From 7b36d4adb6d240982fc9b31cc424dc3166ca0ee8 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 14 Jun 2019 17:22:56 +0000 Subject: [PATCH] Revert [LFTR] Stylistic cleanup as suggested in last review comment of D62939 [NFC] Reverting because it depends on r363289, which breaks a green dragon build: http://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/18208 This reverts r363292 (git commit 42a3fc133d3544b5c0c032fe99c6e8a469a836c2) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363426 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/IndVarSimplify.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 962a2afee87..e7167e00e26 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -2385,15 +2385,12 @@ bool IndVarSimplify:: linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, const SCEV *BackedgeTakenCount, PHINode *IndVar, SCEVExpander &Rewriter) { - assert(isLoopCounter(IndVar, L, SE)); - assert(L->getLoopLatch() && "Loop no longer in simplified form?"); - Instruction * const IncVar = - cast(IndVar->getIncomingValueForBlock(L->getLoopLatch())); - // Initialize CmpIndVar and IVCount to their preincremented values. Value *CmpIndVar = IndVar; const SCEV *IVCount = BackedgeTakenCount; + assert(L->getLoopLatch() && "Loop no longer in simplified form?"); + // If the exiting block is the same as the backedge block, we prefer to // compare against the post-incremented value, otherwise we must compare // against the preincremented value. @@ -2404,10 +2401,12 @@ linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, // to add a potentially UB introducing use. We need to either a) show // the loop test we're modifying is already in post-inc form, or b) show // that adding a use must not introduce UB. + Instruction *Inc = + cast(IndVar->getIncomingValueForBlock(L->getLoopLatch())); ICmpInst *LoopTest = getLoopTest(L, ExitingBB); - SafeToPostInc = LoopTest->getOperand(0) == IncVar || - LoopTest->getOperand(1) == IncVar || - mustExecuteUBIfPoisonOnPathTo(IncVar, ExitingBB->getTerminator(), DT); + SafeToPostInc = LoopTest->getOperand(0) == Inc || + LoopTest->getOperand(1) == Inc || + mustExecuteUBIfPoisonOnPathTo(Inc, ExitingBB->getTerminator(), DT); } if (SafeToPostInc) { // Add one to the "backedge-taken" count to get the trip count. @@ -2418,7 +2417,7 @@ linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, // The BackedgeTaken expression contains the number of times that the // backedge branches to the loop header. This is one less than the // number of times the loop executes, so use the incremented indvar. - CmpIndVar = IncVar; + CmpIndVar = IndVar->getIncomingValueForBlock(ExitingBB); } } @@ -2434,6 +2433,7 @@ linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, // dynamically dead IV that wraps on the first loop iteration only, which is // not covered by the post-inc addrec. (If the new IV was not dynamically // dead, it could not be poison on the first iteration in the first place.) + Value *IncVar = IndVar->getIncomingValueForBlock(L->getLoopLatch()); if (auto *BO = dyn_cast(IncVar)) { const SCEVAddRecExpr *AR = cast(SE->getSCEV(IncVar)); if (BO->hasNoUnsignedWrap()) -- 2.40.0