[llvm] r364713 - [LFTR] Remove unnecessary latch check; NFCI

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 29 05:41:02 PDT 2019


Author: nikic
Date: Sat Jun 29 05:41:02 2019
New Revision: 364713

URL: http://llvm.org/viewvc/llvm-project?rev=364713&view=rev
Log:
[LFTR] Remove unnecessary latch check; NFCI

The whole indvars pass works on loops in simplified form, so there
is always a unique latch. Convert the condition into an assertion
in needsLFTR (though we also assert this in later LFTR functions).

Additionally update the comment on getLoopTest() now that we are
dealing with multiple exits.

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=364713&r1=364712&r2=364713&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Sat Jun 29 05:41:02 2019
@@ -2027,16 +2027,9 @@ static PHINode *getLoopPhiForCounter(Val
   return nullptr;
 }
 
-/// Given a loop with one backedge and one exit, return the ICmpInst
-/// controlling the sole loop exit.  There is no guarantee that the exiting
-/// block is also the latch.
-static ICmpInst *getLoopTest(Loop *L, BasicBlock *ExitingBB) {
-
-  BasicBlock *LatchBlock = L->getLoopLatch();
-  // Don't bother with LFTR if the loop is not properly simplified.
-  if (!LatchBlock)
-    return nullptr;
-
+/// Return the ICmpInst controlling the given loop exit.  There is no guarantee
+/// that the exiting block is also the latch.
+static ICmpInst *getLoopTest(BasicBlock *ExitingBB) {
   BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
   return dyn_cast<ICmpInst>(BI->getCondition());
 }
@@ -2044,6 +2037,8 @@ static ICmpInst *getLoopTest(Loop *L, Ba
 /// linearFunctionTestReplace policy. Return true unless we can show that the
 /// current exit test is already sufficiently canonical.
 static bool needsLFTR(Loop *L, BasicBlock *ExitingBB) {
+  assert(L->getLoopLatch() && "Must be in simplified form");
+
   // Avoid converting a constant or loop invariant test back to a runtime
   // test.  This is critical for when SCEV's cached ExitCount is less precise
   // than the current IR (such as after we've proven a particular exit is
@@ -2053,7 +2048,7 @@ static bool needsLFTR(Loop *L, BasicBloc
     return false;
   
   // Do LFTR to simplify the exit condition to an ICMP.
-  ICmpInst *Cond = getLoopTest(L, ExitingBB);
+  ICmpInst *Cond = getLoopTest(ExitingBB);
   if (!Cond)
     return true;
 
@@ -2228,7 +2223,7 @@ static PHINode *FindLoopCounter(Loop *L,
   PHINode *BestPhi = nullptr;
   const SCEV *BestInit = nullptr;
   BasicBlock *LatchBlock = L->getLoopLatch();
-  assert(LatchBlock && "needsLFTR should guarantee a loop latch");
+  assert(LatchBlock && "Must be in simplified form");
   const DataLayout &DL = L->getHeader()->getModule()->getDataLayout();
 
   for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I) {
@@ -2255,7 +2250,7 @@ static PHINode *FindLoopCounter(Loop *L,
       // We explicitly allow unknown phis as long as they are already used by
       // the loop exit test.  This is legal since performing LFTR could not
       // increase the number of undef users. 
-      if (ICmpInst *Cond = getLoopTest(L, ExitingBB))
+      if (ICmpInst *Cond = getLoopTest(ExitingBB))
         if (Phi != getLoopPhiForCounter(Cond->getOperand(0), L) &&
             Phi != getLoopPhiForCounter(Cond->getOperand(1), L))
           continue;
@@ -2412,7 +2407,7 @@ linearFunctionTestReplace(Loop *L, Basic
       // 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.
-      if (ICmpInst *LoopTest = getLoopTest(L, ExitingBB))
+      if (ICmpInst *LoopTest = getLoopTest(ExitingBB))
         SafeToPostInc = LoopTest->getOperand(0) == IncVar ||
           LoopTest->getOperand(1) == IncVar;
       if (!SafeToPostInc)




More information about the llvm-commits mailing list