-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[ConstraintElim] Simplify and/or instead of replacing its operand #139874
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
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Yingwei Zheng (dtcxzyw) ChangesIn Closes #137937. Patch is 24.76 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/139874.diff 9 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index f2d6e268743eb..da5be383df15c 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1563,8 +1563,12 @@ removeEntryFromStack(const StackEntry &E, ConstraintInfo &Info,
static bool checkOrAndOpImpliedByOther(
FactOrCheck &CB, ConstraintInfo &Info, Module *ReproducerModule,
SmallVectorImpl<ReproducerEntry> &ReproducerCondStack,
- SmallVectorImpl<StackEntry> &DFSInStack) {
+ SmallVectorImpl<StackEntry> &DFSInStack,
+ SmallVectorImpl<Instruction *> &ToRemove) {
Instruction *JoinOp = CB.getContextInst();
+ if (JoinOp->use_empty())
+ return false;
+
CmpInst *CmpToCheck = cast<CmpInst>(CB.getInstructionToSimplify());
unsigned OtherOpIdx = JoinOp->getOperand(0) == CmpToCheck ? 1 : 0;
@@ -1611,15 +1615,12 @@ static bool checkOrAndOpImpliedByOther(
if (auto ImpliedCondition =
checkCondition(CmpToCheck->getPredicate(), CmpToCheck->getOperand(0),
CmpToCheck->getOperand(1), CmpToCheck, Info)) {
- if (IsOr && isa<SelectInst>(JoinOp)) {
- JoinOp->setOperand(
- OtherOpIdx == 0 ? 2 : 0,
+ if (IsOr == *ImpliedCondition)
+ JoinOp->replaceAllUsesWith(
ConstantInt::getBool(JoinOp->getType(), *ImpliedCondition));
- } else
- JoinOp->setOperand(
- 1 - OtherOpIdx,
- ConstantInt::getBool(JoinOp->getType(), *ImpliedCondition));
-
+ else
+ JoinOp->replaceAllUsesWith(JoinOp->getOperand(OtherOpIdx));
+ ToRemove.push_back(JoinOp);
return true;
}
@@ -1852,9 +1853,9 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
ReproducerModule.get(), ReproducerCondStack, S.DT, ToRemove);
if (!Simplified &&
match(CB.getContextInst(), m_LogicalOp(m_Value(), m_Value()))) {
- Simplified =
- checkOrAndOpImpliedByOther(CB, Info, ReproducerModule.get(),
- ReproducerCondStack, DFSInStack);
+ Simplified = checkOrAndOpImpliedByOther(
+ CB, Info, ReproducerModule.get(), ReproducerCondStack, DFSInStack,
+ ToRemove);
}
Changed |= Simplified;
} else if (auto *MinMax = dyn_cast<MinMaxIntrinsic>(Inst)) {
diff --git a/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll b/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll
index 8bd0b4100cff9..deefe05ddb317 100644
--- a/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll
+++ b/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll
@@ -6,8 +6,7 @@ define i1 @test_second_and_condition_implied_by_first(i8 %x) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
-; CHECK-NEXT: [[AND:%.*]] = and i1 [[C_1]], true
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 false
; CHECK: else:
@@ -31,8 +30,7 @@ define i1 @test_first_and_condition_implied_by_second_ops(i8 %x) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
-; CHECK-NEXT: [[AND:%.*]] = and i1 true, [[C_1]]
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 false
; CHECK: else:
@@ -56,8 +54,7 @@ define i1 @test_second_and_condition_implied_by_first_select_form(i8 %x) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
-; CHECK-NEXT: [[AND:%.*]] = select i1 [[C_1]], i1 true, i1 false
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 false
; CHECK: else:
@@ -105,8 +102,7 @@ define i1 @test_same_cond_for_and(i8 %x) {
; CHECK-LABEL: @test_same_cond_for_and(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
-; CHECK-NEXT: [[AND:%.*]] = and i1 true, [[C_1]]
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 false
; CHECK: else:
@@ -152,8 +148,7 @@ define i1 @test_second_and_condition_not_implied_by_first(i8 %x) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i8 [[X]], 5
-; CHECK-NEXT: [[AND:%.*]] = and i1 true, [[C_1]]
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 false
; CHECK: else:
@@ -371,8 +366,7 @@ define i1 @test_and_used_in_false_branch(i8 %x) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
-; CHECK-NEXT: [[AND:%.*]] = and i1 [[C_1]], true
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 true
; CHECK: else:
@@ -397,8 +391,7 @@ define i1 @test_or_used_in_false_branch(i8 %x) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ule i8 [[X:%.*]], 10
; CHECK-NEXT: [[T_1:%.*]] = icmp ule i8 [[X]], 5
-; CHECK-NEXT: [[AND:%.*]] = or i1 [[C_1]], false
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 [[T_1]]
; CHECK: else:
@@ -423,8 +416,7 @@ define i1 @test_or_used_in_false_branch2(i8 %x) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
-; CHECK-NEXT: [[AND:%.*]] = or i1 false, [[T_1]]
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[T_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: ret i1 [[T_1]]
; CHECK: else:
@@ -450,8 +442,7 @@ define i1 @and_select_first_implies_second_may_be_poison(ptr noundef %A, ptr nou
; CHECK-NEXT: [[C_1:%.*]] = icmp ne ptr [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds ptr, ptr [[B]], i64 -1
; CHECK-NEXT: [[C_2:%.*]] = icmp ugt ptr [[GEP]], [[A]]
-; CHECK-NEXT: [[AND:%.*]] = select i1 [[C_2]], i1 true, i1 false
-; CHECK-NEXT: ret i1 [[AND]]
+; CHECK-NEXT: ret i1 [[C_2]]
;
entry:
%c.1 = icmp ne ptr %A, %B
@@ -504,8 +495,7 @@ define void @and_tree_second_implies_first(i32 noundef %v0, i32 noundef %v1, i32
; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i32 [[V1]], [[V2:%.*]]
; CHECK-NEXT: [[AND1:%.*]] = and i1 [[CMP0]], [[CMP1]]
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[V0]], [[V2]]
-; CHECK-NEXT: [[AND2:%.*]] = and i1 false, [[AND1]]
-; CHECK-NEXT: br i1 [[AND2]], label [[IF_THEN:%.*]], label [[RETURN:%.*]]
+; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[RETURN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @side_effect()
; CHECK-NEXT: br label [[RETURN]]
@@ -535,8 +525,7 @@ define void @and_tree_second_implies_first_perm1(i32 noundef %v0, i32 noundef %v
; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i32 [[V1]], [[V2:%.*]]
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[V0]], [[V2]]
; CHECK-NEXT: [[AND1:%.*]] = and i1 [[CMP2]], [[CMP1]]
-; CHECK-NEXT: [[AND2:%.*]] = and i1 false, [[AND1]]
-; CHECK-NEXT: br i1 [[AND2]], label [[IF_THEN:%.*]], label [[RETURN:%.*]]
+; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[RETURN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @side_effect()
; CHECK-NEXT: br label [[RETURN]]
@@ -567,8 +556,7 @@ define void @and_tree_second_implies_first_perm2(i32 noundef %v0, i32 noundef %v
; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i32 [[V1]], [[V2:%.*]]
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[V0]], [[V2]]
; CHECK-NEXT: [[AND1:%.*]] = and i1 [[CMP0]], [[CMP2]]
-; CHECK-NEXT: [[AND2:%.*]] = and i1 false, [[AND1]]
-; CHECK-NEXT: br i1 [[AND2]], label [[IF_THEN:%.*]], label [[RETURN:%.*]]
+; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[RETURN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @side_effect()
; CHECK-NEXT: br label [[RETURN]]
@@ -629,8 +617,7 @@ define void @or_tree_second_implies_first(i32 noundef %v0, i32 noundef %v1, i32
; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i32 [[V1]], [[V2:%.*]]
; CHECK-NEXT: [[AND1:%.*]] = or i1 [[CMP0]], [[CMP1]]
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[V0]], [[V2]]
-; CHECK-NEXT: [[AND2:%.*]] = or i1 true, [[AND1]]
-; CHECK-NEXT: br i1 [[AND2]], label [[IF_THEN:%.*]], label [[RETURN:%.*]]
+; CHECK-NEXT: br i1 true, label [[IF_THEN:%.*]], label [[RETURN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @side_effect()
; CHECK-NEXT: br label [[RETURN]]
@@ -659,8 +646,7 @@ define void @or_tree_second_implies_first_with_unknown_cond(i64 %x, i1 %cond) {
; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i64 [[X:%.*]], 1
; CHECK-NEXT: [[OR1:%.*]] = select i1 [[CMP1]], i1 [[COND:%.*]], i1 false
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[X]], 2
-; CHECK-NEXT: [[OR2:%.*]] = select i1 [[OR1]], i1 false, i1 false
-; CHECK-NEXT: br i1 [[OR2]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @side_effect()
; CHECK-NEXT: br label [[IF_END]]
diff --git a/llvm/test/Transforms/ConstraintElimination/eq.ll b/llvm/test/Transforms/ConstraintElimination/eq.ll
index 04cd39490cdef..511a08f7796a3 100644
--- a/llvm/test/Transforms/ConstraintElimination/eq.ll
+++ b/llvm/test/Transforms/ConstraintElimination/eq.ll
@@ -432,8 +432,7 @@ define i1 @test_eq_for_signed_cmp(i32 noundef %v0, i32 noundef %v1, i32 noundef
; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i32 [[V0]], [[V1:%.*]]
; CHECK-NEXT: [[AND0:%.*]] = and i1 [[CMP1]], [[CMP]]
; CHECK-NEXT: [[CMP4:%.*]] = icmp sgt i32 [[V1]], [[V2]]
-; CHECK-NEXT: [[AND1:%.*]] = and i1 false, [[AND0]]
-; CHECK-NEXT: ret i1 [[AND1]]
+; CHECK-NEXT: ret i1 false
;
entry:
%cmp = icmp eq i32 %v2, %v0
@@ -457,8 +456,7 @@ define i1 @test_eq_for_signed_cmp_with_decompsition(i32 noundef %v0, i32 noundef
; CHECK-NEXT: [[AND1:%.*]] = and i1 [[AND0]], [[CMP2]]
; CHECK-NEXT: [[AND2:%.*]] = and i1 [[AND1]], [[CMP3]]
; CHECK-NEXT: [[CMP4:%.*]] = icmp sgt i32 [[V1]], [[V2]]
-; CHECK-NEXT: [[AND3:%.*]] = and i1 false, [[AND2]]
-; CHECK-NEXT: ret i1 [[AND3]]
+; CHECK-NEXT: ret i1 false
;
entry:
%v0add = add nsw i32 %v0, %addend0
diff --git a/llvm/test/Transforms/ConstraintElimination/gep-arithmetic-signed-predicates.ll b/llvm/test/Transforms/ConstraintElimination/gep-arithmetic-signed-predicates.ll
index 52094914f6962..c9f4984bcba60 100644
--- a/llvm/test/Transforms/ConstraintElimination/gep-arithmetic-signed-predicates.ll
+++ b/llvm/test/Transforms/ConstraintElimination/gep-arithmetic-signed-predicates.ll
@@ -611,14 +611,12 @@ define i4 @ptr_N_signed_positive_assume(ptr %src, ptr %lower, ptr %upper, i16 %N
; CHECK: step.check:
; CHECK-NEXT: [[STEP_POS:%.*]] = icmp sge i16 [[STEP:%.*]], 0
; CHECK-NEXT: [[STEP_SLT_N:%.*]] = icmp slt i16 [[STEP]], [[N]]
-; CHECK-NEXT: [[AND_STEP:%.*]] = and i1 false, [[STEP_SLT_N]]
-; CHECK-NEXT: br i1 [[AND_STEP]], label [[PTR_CHECK:%.*]], label [[EXIT:%.*]]
+; CHECK-NEXT: br i1 false, label [[PTR_CHECK:%.*]], label [[EXIT:%.*]]
; CHECK: ptr.check:
; CHECK-NEXT: [[SRC_STEP:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i16 [[STEP]]
; CHECK-NEXT: [[CMP_STEP_START:%.*]] = icmp slt ptr [[SRC_STEP]], [[LOWER]]
; CHECK-NEXT: [[CMP_STEP_END:%.*]] = icmp sge ptr [[SRC_STEP]], [[UPPER]]
-; CHECK-NEXT: [[OR_CHECK:%.*]] = or i1 true, [[CMP_STEP_END]]
-; CHECK-NEXT: br i1 [[OR_CHECK]], label [[TRAP_BB]], label [[EXIT]]
+; CHECK-NEXT: br i1 true, label [[TRAP_BB]], label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: ret i4 3
;
diff --git a/llvm/test/Transforms/ConstraintElimination/geps-precondition-overflow-check.ll b/llvm/test/Transforms/ConstraintElimination/geps-precondition-overflow-check.ll
index 08b25c6065aac..d90b986c8e539 100644
--- a/llvm/test/Transforms/ConstraintElimination/geps-precondition-overflow-check.ll
+++ b/llvm/test/Transforms/ConstraintElimination/geps-precondition-overflow-check.ll
@@ -36,8 +36,7 @@ define i1 @overflow_check_2_and(ptr %dst) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[DST_5:%.*]] = getelementptr i32, ptr [[DST:%.*]], i64 5
; CHECK-NEXT: [[DST_5_UGE:%.*]] = icmp uge ptr [[DST_5]], [[DST]]
-; CHECK-NEXT: [[AND:%.*]] = and i1 true, [[DST_5_UGE]]
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[DST_5_UGE]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: [[DST_4:%.*]] = getelementptr i32, ptr [[DST]], i64 4
; CHECK-NEXT: [[TRUE_DST_4_UGE:%.*]] = icmp uge ptr [[DST_4]], [[DST]]
@@ -65,8 +64,7 @@ define i1 @overflow_check_3_and(ptr %dst) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[DST_5:%.*]] = getelementptr i32, ptr [[DST:%.*]], i64 5
; CHECK-NEXT: [[DST_5_UGE:%.*]] = icmp uge ptr [[DST_5]], [[DST]]
-; CHECK-NEXT: [[AND:%.*]] = and i1 true, [[DST_5_UGE]]
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[DST_5_UGE]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: [[DST_4:%.*]] = getelementptr i32, ptr [[DST]], i64 4
; CHECK-NEXT: [[DST_4_UGE:%.*]] = icmp uge ptr [[DST_4]], [[DST]]
@@ -98,8 +96,7 @@ define i1 @overflow_check_4_and(ptr %dst) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[DST_5:%.*]] = getelementptr i32, ptr [[DST:%.*]], i64 5
; CHECK-NEXT: [[DST_5_UGE:%.*]] = icmp uge ptr [[DST_5]], [[DST]]
-; CHECK-NEXT: [[AND:%.*]] = and i1 true, [[DST_5_UGE]]
-; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[DST_5_UGE]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: [[DST_4:%.*]] = getelementptr i32, ptr [[DST]], i64 4
; CHECK-NEXT: [[TRUE_DST_4_UGE:%.*]] = icmp uge ptr [[DST_4]], [[DST]]
@@ -152,8 +149,7 @@ define i1 @overflow_check_3_or(ptr %dst) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[DST_5:%.*]] = getelementptr i32, ptr [[DST:%.*]], i64 5
; CHECK-NEXT: [[DST_5_UGE:%.*]] = icmp uge ptr [[DST_5]], [[DST]]
-; CHECK-NEXT: [[OR:%.*]] = or i1 false, [[DST_5_UGE]]
-; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK-NEXT: br i1 [[DST_5_UGE]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: [[DST_4:%.*]] = getelementptr i32, ptr [[DST]], i64 4
; CHECK-NEXT: [[TRUE_DST_4_UGE:%.*]] = icmp uge ptr [[DST_4]], [[DST]]
diff --git a/llvm/test/Transforms/ConstraintElimination/loops-bottom-tested-pointer-cmps.ll b/llvm/test/Transforms/ConstraintElimination/loops-bottom-tested-pointer-cmps.ll
index 279238bea1842..91546d4abf438 100644
--- a/llvm/test/Transforms/ConstraintElimination/loops-bottom-tested-pointer-cmps.ll
+++ b/llvm/test/Transforms/ConstraintElimination/loops-bottom-tested-pointer-cmps.ll
@@ -23,8 +23,7 @@ define void @checks_in_loops_removable(ptr %ptr, ptr %lower, ptr %upper, i8 %n)
; CHECK-NEXT: [[PTR_IV:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i16 [[IV]]
; CHECK-NEXT: [[CMP_PTR_IV_LOWER:%.*]] = icmp ugt ptr [[LOWER]], [[PTR_IV]]
; CHECK-NEXT: [[CMP_PTR_IV_UPPER:%.*]] = icmp ule ptr [[UPPER]], [[PTR_IV]]
-; CHECK-NEXT: [[OR:%.*]] = or i1 false, [[CMP_PTR_IV_UPPER]]
-; CHECK-NEXT: br i1 [[OR]], label [[TRAP]], label [[LOOP_LATCH]]
+; CHECK-NEXT: br i1 [[CMP_PTR_IV_UPPER]], label [[TRAP]], label [[LOOP_LATCH]]
; CHECK: loop.latch:
; CHECK-NEXT: store i8 0, ptr [[PTR_IV]], align 4
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
@@ -88,14 +87,13 @@ define void @some_checks_in_loops_removable(ptr %ptr, ptr %lower, ptr %upper, i8
; CHECK-NEXT: [[PTR_IV:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i16 [[IV]]
; CHECK-NEXT: [[CMP_PTR_IV_LOWER:%.*]] = icmp ugt ptr [[LOWER]], [[PTR_IV]]
; CHECK-NEXT: [[CMP_PTR_IV_UPPER:%.*]] = icmp ule ptr [[UPPER]], [[PTR_IV]]
-; CHECK-NEXT: [[OR:%.*]] = or i1 false, [[CMP_PTR_IV_UPPER]]
-; CHECK-NEXT: br i1 [[OR]], label [[TRAP]], label [[LOOP_BODY:%.*]]
+; CHECK-NEXT: br i1 [[CMP_PTR_IV_UPPER]], label [[TRAP]], label [[LOOP_BODY:%.*]]
; CHECK: loop.body:
; CHECK-NEXT: [[IV_1:%.*]] = add nuw nsw i16 [[IV]], 1
; CHECK-NEXT: [[PTR_IV_1:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i16 [[IV_1]]
; CHECK-NEXT: [[CMP_PTR_IV_1_UPPER:%.*]] = icmp ule ptr [[UPPER]], [[PTR_IV_1]]
; CHECK-NEXT: [[OR_1:%.*]] = or i1 false, [[CMP_PTR_IV_1_UPPER]]
-; CHECK-NEXT: br i1 [[OR]], label [[TRAP]], label [[LOOP_LATCH]]
+; CHECK-NEXT: br i1 [[CMP_PTR_IV_UPPER]], label [[TRAP]], label [[LOOP_LATCH]]
; CHECK: loop.latch:
; CHECK-NEXT: store i8 0, ptr [[PTR_IV]], align 4
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
@@ -165,14 +163,13 @@ define void @no_checks_in_loops_removable(ptr %ptr, ptr %lower, ptr %upper, i8 %
; CHECK-NEXT: [[PTR_IV:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i16 [[IV]]
; CHECK-NEXT: [[CMP_PTR_IV_LOWER:%.*]] = icmp ugt ptr [[LOWER]], [[PTR_IV]]
; CHECK-NEXT: [[CMP_PTR_IV_UPPER:%.*]] = icmp ule ptr [[UPPER]], [[PTR_IV]]
-; CHECK-NEXT: [[OR:%.*]] = or i1 false, [[CMP_PTR_IV_UPPER]]
-; CHECK-NEXT: br i1 [[OR]], label [[TRAP]], label [[LOOP_BODY:%.*]]
+; CHECK-NEXT: br i1 [[CMP_PTR_IV_UPPER]], label [[TRAP]], label [[LOOP_BODY:%.*]]
; CHECK: loop.body:
; CHECK-NEXT: [[IV_1:%.*]] = add nuw nsw i16 [[IV]], 1
; CHECK-NEXT: [[PTR_IV_1:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i16 [[IV_1]]
; CHECK-NEXT: [[CMP_PTR_IV_1_UPPER:%.*]] = icmp ule ptr [[UPPER]], [[PTR_IV_1]]
; CHECK-NEXT: [[OR_1:%.*]] = or i1 false, [[CMP_PTR_IV_1_UPPER]]
-; CHECK-NEXT: br i1 [[OR]], label [[TRAP]], label [[LOOP_LATCH]]
+; CHECK-NEXT: br i1 [[CMP_PTR_IV_UPPER]], label [[TRAP]], label [[LOOP_LATCH]]
; CHECK: loop.latch:
; CHECK-NEXT: store i8 0, ptr [[PTR_IV]], align 4
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
diff --git a/llvm/test/Transforms/ConstraintElimination/loops-header-tested-pointer-cmps.ll b/llvm/test/Transforms/ConstraintElimination/loops-header-tested-pointer-cmps.ll
index 1842ca2d82545..df0cb40965430 100644
--- a/llvm/test/Transforms/ConstraintElimination/loops-header-tested-pointer-cmps.ll
+++ b/llvm/test/Transforms/ConstraintElimination/loops-header-tested-pointer-cmps.ll
@@ -212,8 +212,7 @@ define void @test2_with_ne(ptr %src, ptr %lower, ptr %upper, i8 %N) {
; CHECK-NEXT: [[SRC_IV:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i8 [[IV]]
; CHECK-NEXT: [[CMP_IV_START:%.*]] = icmp ult ptr [[SRC_IV]], [[LOWER]]
; CHECK-NEXT: [[CMP_IV_END:%.*]] = icmp uge ptr [[SRC_IV]], [[UPPER]]
-; CHECK-NEXT: [[OR_1:%.*]] = or i1 false, [[CMP_IV_END]]
-; CHECK-NEXT: br i1 [[OR_1]], label [[TRAP_BB]], label [[LOOP_BODY_1:%.*]]
+; CHECK-NEXT: br i1 [[CMP_IV_END]], label [[TRAP_BB]], label [[LOOP_BODY_1:%.*]]
; CHECK: loop.body.1:
; CHECK-NEXT: [[ADD_1:%.*]] = add nuw nsw i8 [[IV]], 1
; CHECK-NEXT: [[SRC_IV_1:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i8 [[ADD_1]]
@@ -306,8 +305,7 @@ define void @test3(ptr %src, ptr %lower, ptr %upper, i8 %N) {
; CHECK-NEXT: [[SRC_IV:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i8 [[IV]]
; CHECK-NEXT: [[CMP_IV_START:%.*]] = icmp ult ptr [[SRC_IV]], [[LOWER]]
; CHECK-NEXT: [[CMP_IV_END:%.*]] = icmp uge ptr [[SRC_IV]], [[UPPER]]
-; CHECK-NEXT: [[OR_1:%.*]] = or i1 false, [[CMP_IV_END]...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
In
checkOrAndOpImpliedByOther
, replacing an operand of a disjoint or is unsafe: https://alive2.llvm.org/ce/z/4R4hxNThis patch performs the simplification directly, to avoid miscompilation and unnecessary canonicalization.
Closes #137937.