From 5746c76f3fc93cc1a21caf24e35b638218a6eed7 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Mon, 13 Sep 2021 10:10:49 -0700 Subject: [PATCH] Revert "[IndVars] Break backedge and replace PHIs if loop exits on 1st iteration" This reverts commit d9ca444835e67960df927d5b8cade57776fdd8cb. See review for why. --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 8 -------- llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll | 7 +++++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index f6a6ea16d3c2..320e20ca341c 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -1465,15 +1465,8 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) { bool Changed = false; bool SkipLastIter = false; - bool ExitsOnFirstIter = false; SmallSet 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(ExitCount)) { // Okay, we do not know the exit count here. Can we at least prove that it @@ -1523,7 +1516,6 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) { foldExit(L, ExitingBB, true, DeadInsts); replaceLoopPHINodesWithPreheaderValues(L, DeadInsts); Changed = true; - ExitsOnFirstIter = true; continue; } diff --git a/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll b/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll index 607017877231..e2ba6e084dce 100644 --- a/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll +++ b/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll @@ -15,6 +15,7 @@ define i1 @kill_backedge_and_phis(i8* align 1 %lhs, i8* align 1 %rhs, i32 %len) ; 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) @@ -24,10 +25,12 @@ define i1 @kill_backedge_and_phis(i8* align 1 %lhs, i8* align 1 %rhs, i32 %len) ; 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 true, label %exit.loopexit, label %exiting_3 +; CHECK-NEXT: br i1 %bar_ret, label %exit.loopexit, label %exiting_3 ; CHECK: exiting_3: ; CHECK-NEXT: %baz_ret = call i1 @baz() -; CHECK-NEXT: br i1 false, label %loop, label %exit.loopexit +; 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: 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