Skip to content

Commit 9224d32

Browse files
committed
[IndVars] Fix branches exiting by true with invariant conditions
Forgot to invert the condition for them.
1 parent e36d101 commit 9224d32

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,9 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
14321432
Rewriter.setInsertPoint(BI);
14331433
auto *LHSV = Rewriter.expandCodeFor(InvariantLHS);
14341434
auto *RHSV = Rewriter.expandCodeFor(InvariantRHS);
1435+
bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB));
1436+
if (ExitIfTrue)
1437+
InvariantPred = ICmpInst::getInversePredicate(InvariantPred);
14351438
IRBuilder<> Builder(BI);
14361439
auto *NewCond = Builder.CreateICmp(InvariantPred, LHSV, RHSV,
14371440
BI->getCondition()->getName());

llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ define void @test_can_predicate_simple_unsigned_inverted(i32* %p, i32* %arr) {
529529
; CHECK-NEXT: br i1 [[ZERO_COND]], label [[EXIT:%.*]], label [[RANGE_CHECK_BLOCK:%.*]]
530530
; CHECK: range_check_block:
531531
; CHECK-NEXT: [[IV_NEXT]] = sub i32 [[IV]], 1
532-
; CHECK-NEXT: [[RANGE_CHECK1:%.*]] = icmp ult i32 [[TMP0]], [[LEN]]
532+
; CHECK-NEXT: [[RANGE_CHECK1:%.*]] = icmp uge i32 [[TMP0]], [[LEN]]
533533
; CHECK-NEXT: br i1 [[RANGE_CHECK1]], label [[FAIL:%.*]], label [[BACKEDGE]]
534534
; CHECK: backedge:
535535
; CHECK-NEXT: [[EL_PTR:%.*]] = getelementptr i32, i32* [[P]], i32 [[IV]]

0 commit comments

Comments
 (0)