Skip to content

Commit 0e78655

Browse files
committed
[LVI] Use m_AddLike instead of m_Add when matching simple condition
We have more complete logic for handling `Add`, so try to use that logic for `or disjoint` (which can definitionally be treated as `add`). Closes #86058
1 parent efa1544 commit 0e78655

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,14 +1069,14 @@ static bool matchICmpOperand(APInt &Offset, Value *LHS, Value *Val,
10691069
// Handle range checking idiom produced by InstCombine. We will subtract the
10701070
// offset from the allowed range for RHS in this case.
10711071
const APInt *C;
1072-
if (match(LHS, m_Add(m_Specific(Val), m_APInt(C)))) {
1072+
if (match(LHS, m_AddLike(m_Specific(Val), m_APInt(C)))) {
10731073
Offset = *C;
10741074
return true;
10751075
}
10761076

10771077
// Handle the symmetric case. This appears in saturation patterns like
10781078
// (x == 16) ? 16 : (x + 1).
1079-
if (match(Val, m_Add(m_Specific(LHS), m_APInt(C)))) {
1079+
if (match(Val, m_AddLike(m_Specific(LHS), m_APInt(C)))) {
10801080
Offset = -*C;
10811081
return true;
10821082
}

llvm/test/Transforms/CorrelatedValuePropagation/basic.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,7 @@ define i1 @clamp_high1_or(i32 noundef %a) {
879879
; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp eq i32 [[A]], 5
880880
; CHECK-NEXT: [[ADD:%.*]] = or disjoint i32 [[A]], 1
881881
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[SEL_CMP]], i32 5, i32 [[ADD]]
882-
; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[SEL]], 6
883-
; CHECK-NEXT: ret i1 [[RES]]
882+
; CHECK-NEXT: ret i1 false
884883
; CHECK: out:
885884
; CHECK-NEXT: ret i1 false
886885
;
@@ -935,8 +934,7 @@ define i1 @clamp_high2_or_disjoint(i32 noundef %a) {
935934
; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp ne i32 [[A]], 5
936935
; CHECK-NEXT: [[ADD:%.*]] = or disjoint i32 [[A]], 1
937936
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[SEL_CMP]], i32 [[ADD]], i32 5
938-
; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[SEL]], 6
939-
; CHECK-NEXT: ret i1 [[RES]]
937+
; CHECK-NEXT: ret i1 false
940938
; CHECK: out:
941939
; CHECK-NEXT: ret i1 false
942940
;

llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ define i1 @test_assume_cmp_with_offset_or(i64 %idx, i1 %other) {
593593
; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i64 [[IDX_OFF1]], 10
594594
; CHECK-NEXT: br i1 [[CMP1]], label [[T:%.*]], label [[F:%.*]]
595595
; CHECK: T:
596-
; CHECK-NEXT: [[CMP3:%.*]] = icmp ugt i64 [[IDX]], 2
597-
; CHECK-NEXT: ret i1 [[CMP3]]
596+
; CHECK-NEXT: ret i1 true
598597
; CHECK: F:
599598
; CHECK-NEXT: ret i1 [[CMP2:%.*]]
600599
;

0 commit comments

Comments
 (0)