[PATCH] D108910: [IndVars] Break backedge and replace PHIs if loop exits on 1st iteration
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 12 21:32:45 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd9ca444835e6: [IndVars] Break backedge and replace PHIs if loop exits on 1st iteration (authored by mkazantsev).
Changed prior to commit:
https://reviews.llvm.org/D108910?vs=370847&id=372156#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108910/new/
https://reviews.llvm.org/D108910
Files:
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll
Index: llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll
===================================================================
--- llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll
+++ llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll
@@ -15,7 +15,6 @@
; CHECK: loop_preheader:
; CHECK-NEXT: br label %loop
; CHECK: loop:
-; CHECK-NEXT: %iv.next = add nuw nsw i32 0, 1
; CHECK-NEXT: %left_ptr = getelementptr inbounds i8, i8* %lhs, i32 0
; CHECK-NEXT: %right_ptr = getelementptr inbounds i8, i8* %rhs, i32 0
; CHECK-NEXT: %result = call i1 @foo(i8* %left_ptr, i8* %right_ptr)
@@ -25,12 +24,10 @@
; CHECK-NEXT: br i1 false, label %exiting_2, label %exit.loopexit
; CHECK: exiting_2:
; CHECK-NEXT: %bar_ret = call i1 @bar()
-; CHECK-NEXT: br i1 %bar_ret, label %exit.loopexit, label %exiting_3
+; CHECK-NEXT: br i1 true, label %exit.loopexit, label %exiting_3
; CHECK: exiting_3:
; CHECK-NEXT: %baz_ret = call i1 @baz()
-; CHECK-NEXT: %continue = icmp ne i32 %iv.next, %len
-; CHECK-NEXT: %or.cond = select i1 %baz_ret, i1 %continue, i1 false
-; CHECK-NEXT: br i1 %or.cond, label %loop, label %exit.loopexit
+; CHECK-NEXT: br i1 false, label %loop, label %exit.loopexit
; CHECK: exit.loopexit:
; CHECK-NEXT: %val.ph = phi i1 [ %baz_ret, %exiting_3 ], [ %bar_ret, %exiting_2 ], [ %iv.wide.is_not_zero, %exiting_1 ], [ %result, %loop ]
; CHECK-NEXT: br label %exit
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1465,8 +1465,15 @@
bool Changed = false;
bool SkipLastIter = false;
+ bool ExitsOnFirstIter = false;
SmallSet<const SCEV*, 8> DominatingExitCounts;
for (BasicBlock *ExitingBB : ExitingBlocks) {
+ if (ExitsOnFirstIter) {
+ // If proved that some earlier exit is taken
+ // on 1st iteration, then fold this one.
+ foldExit(L, ExitingBB, true, DeadInsts);
+ continue;
+ }
const SCEV *ExitCount = SE->getExitCount(L, ExitingBB);
if (isa<SCEVCouldNotCompute>(ExitCount)) {
// Okay, we do not know the exit count here. Can we at least prove that it
@@ -1516,6 +1523,7 @@
foldExit(L, ExitingBB, true, DeadInsts);
replaceLoopPHINodesWithPreheaderValues(L, DeadInsts);
Changed = true;
+ ExitsOnFirstIter = true;
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108910.372156.patch
Type: text/x-patch
Size: 2513 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210913/3e39ee73/attachment.bin>
More information about the llvm-commits
mailing list