]> granicus.if.org Git - llvm/commitdiff
[LFTR] Strengthen assertions in genLoopLimit [NFCI]
authorPhilip Reames <listmail@philipreames.com>
Fri, 17 May 2019 02:18:03 +0000 (02:18 +0000)
committerPhilip Reames <listmail@philipreames.com>
Fri, 17 May 2019 02:18:03 +0000 (02:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360978 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/IndVarSimplify.cpp

index 8465ad7db5e0ada74caecf6582bf7efa64aabca1..0542eca0e78e0a4bd24b2886e61a7be1b0cfb3fd 100644 (file)
@@ -2263,8 +2263,8 @@ static PHINode *FindLoopCounter(Loop *L, const SCEV *BECount,
 /// is taken IVCount times.  
 static Value *genLoopLimit(PHINode *IndVar, const SCEV *IVCount, Loop *L,
                            SCEVExpander &Rewriter, ScalarEvolution *SE) {
-  const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(IndVar));
-  assert(AR && AR->getLoop() == L && AR->isAffine() && "bad loop counter");
+  assert(isLoopCounter(IndVar, L, SE));
+  const SCEVAddRecExpr *AR = cast<SCEVAddRecExpr>(SE->getSCEV(IndVar));
   const SCEV *IVInit = AR->getStart();
 
   // IVInit may be a pointer while IVCount is an integer when FindLoopCounter
@@ -2311,13 +2311,13 @@ static Value *genLoopLimit(PHINode *IndVar, const SCEV *IVCount, Loop *L,
     // IVInit integer and IVCount pointer would only occur if a canonical IV
     // were generated on top of case #2, which is not expected.
 
+    assert(AR->getStepRecurrence(*SE)->isOne() && "only handles unit stride");
     const SCEV *IVLimit = nullptr;
     // For unit stride, IVCount = Start + BECount with 2's complement overflow.
     // For non-zero Start, compute IVCount here.
     if (AR->getStart()->isZero())
       IVLimit = IVCount;
     else {
-      assert(AR->getStepRecurrence(*SE)->isOne() && "only handles unit stride");
       const SCEV *IVInit = AR->getStart();
 
       // For integer IVs, truncate the IV before computing IVInit + BECount.