[llvm] 9224d32 - [IndVars] Fix branches exiting by true with invariant conditions
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 13 00:52:45 PST 2020
Author: Max Kazantsev
Date: 2020-11-13T15:52:00+07:00
New Revision: 9224d322a27fa383d9c33d4eee4d8aa7842a939b
URL: https://github.com/llvm/llvm-project/commit/9224d322a27fa383d9c33d4eee4d8aa7842a939b
DIFF: https://github.com/llvm/llvm-project/commit/9224d322a27fa383d9c33d4eee4d8aa7842a939b.diff
LOG: [IndVars] Fix branches exiting by true with invariant conditions
Forgot to invert the condition for them.
Added:
Modified:
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index cc3bf87be46e..4c31064a77da 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1432,6 +1432,9 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
Rewriter.setInsertPoint(BI);
auto *LHSV = Rewriter.expandCodeFor(InvariantLHS);
auto *RHSV = Rewriter.expandCodeFor(InvariantRHS);
+ bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB));
+ if (ExitIfTrue)
+ InvariantPred = ICmpInst::getInversePredicate(InvariantPred);
IRBuilder<> Builder(BI);
auto *NewCond = Builder.CreateICmp(InvariantPred, LHSV, RHSV,
BI->getCondition()->getName());
diff --git a/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll b/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
index 664af7adcb44..b0629ed79483 100644
--- a/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
+++ b/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
@@ -529,7 +529,7 @@ define void @test_can_predicate_simple_unsigned_inverted(i32* %p, i32* %arr) {
; CHECK-NEXT: br i1 [[ZERO_COND]], label [[EXIT:%.*]], label [[RANGE_CHECK_BLOCK:%.*]]
; CHECK: range_check_block:
; CHECK-NEXT: [[IV_NEXT]] = sub i32 [[IV]], 1
-; CHECK-NEXT: [[RANGE_CHECK1:%.*]] = icmp ult i32 [[TMP0]], [[LEN]]
+; CHECK-NEXT: [[RANGE_CHECK1:%.*]] = icmp uge i32 [[TMP0]], [[LEN]]
; CHECK-NEXT: br i1 [[RANGE_CHECK1]], label [[FAIL:%.*]], label [[BACKEDGE]]
; CHECK: backedge:
; CHECK-NEXT: [[EL_PTR:%.*]] = getelementptr i32, i32* [[P]], i32 [[IV]]
More information about the llvm-commits
mailing list