Skip to content

[ValueTracking] Track or disjoint conditions as add in Assumption/DomCondition Cache #86302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ static void computeKnownBitsFromCmp(const Value *V, CmpInst::Predicate Pred,
}
default:
const APInt *Offset = nullptr;
if (match(LHS, m_CombineOr(m_V, m_Add(m_V, m_APInt(Offset)))) &&
if (match(LHS, m_CombineOr(m_V, m_AddLike(m_V, m_APInt(Offset)))) &&
match(RHS, m_APInt(C))) {
ConstantRange LHSRange = ConstantRange::makeAllowedICmpRegion(Pred, *C);
if (Offset)
Expand Down Expand Up @@ -9285,7 +9285,7 @@ void llvm::findValuesAffectedByCondition(
} else {
// Handle (A + C1) u< C2, which is the canonical form of
// A > C3 && A < C4.
if (match(A, m_Add(m_Value(X), m_ConstantInt())) &&
if (match(A, m_AddLike(m_Value(X), m_ConstantInt())) &&
match(B, m_ConstantInt()))
AddAffected(X);

Expand Down
51 changes: 51 additions & 0 deletions llvm/test/Transforms/InstCombine/known-bits.ll
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,56 @@ if.else:
ret i64 13
}

define i1 @test_icmp_or_distjoint(i8 %n, i1 %other) {
; CHECK-LABEL: @test_icmp_or_distjoint(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[N_OR:%.*]] = or disjoint i8 [[N:%.*]], 16
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_OR]], -111
; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
; CHECK-NEXT: ret i1 true
; CHECK: if.else:
; CHECK-NEXT: ret i1 [[OTHER:%.*]]
;
entry:
%n_or = or disjoint i8 %n, 16
%cmp = icmp ugt i8 %n_or, 145
br i1 %cmp, label %if.then, label %if.else

if.then:
%r = icmp slt i8 %n, 0
ret i1 %r

if.else:
ret i1 %other
}

define i1 @test_icmp_or_fail_missing_disjoint(i8 %n, i1 %other) {
; CHECK-LABEL: @test_icmp_or_fail_missing_disjoint(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[N_OR:%.*]] = or i8 [[N:%.*]], 16
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[N_OR]], -111
; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[N]], 0
; CHECK-NEXT: ret i1 [[R]]
; CHECK: if.else:
; CHECK-NEXT: ret i1 [[OTHER:%.*]]
;
entry:
%n_or = or i8 %n, 16
%cmp = icmp ugt i8 %n_or, 145
br i1 %cmp, label %if.then, label %if.else

if.then:
%r = icmp slt i8 %n, 0
ret i1 %r

if.else:
ret i1 %other
}



declare void @use(i1)
declare void @sink(i8)