[LFTR] Assert and simplify under assumption exit counts are integers [nfc]
authorPhilip Reames <preames@rivosinc.com>
Tue, 21 Mar 2023 14:18:27 +0000 (07:18 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 21 Mar 2023 14:35:05 +0000 (07:35 -0700)
This invariant was introduced in 8f3d16905d75b07a933d01dc29677fe5867c1b3e.

Differential Revision: https://reviews.llvm.org/D146470

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

index 0f784a8..2b19842 100644 (file)
@@ -912,6 +912,7 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB,
                            const SCEV *ExitCount, bool UsePostInc, Loop *L,
                            SCEVExpander &Rewriter, ScalarEvolution *SE) {
   assert(isLoopCounter(IndVar, L, SE));
+  assert(ExitCount->getType()->isIntegerTy() && "exit count must be integer");
   const SCEVAddRecExpr *AR = cast<SCEVAddRecExpr>(SE->getSCEV(IndVar));
   const SCEV *IVInit = AR->getStart();
   assert(AR->getStepRecurrence(*SE)->isOne() && "only handles unit stride");
@@ -920,8 +921,7 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB,
   // finds a valid pointer IV. Sign extend ExitCount in order to materialize a
   // GEP. Avoid running SCEVExpander on a new pointer value, instead reusing
   // the existing GEPs whenever possible.
-  if (IndVar->getType()->isPointerTy() &&
-      !ExitCount->getType()->isPointerTy()) {
+  if (IndVar->getType()->isPointerTy()) {
     // IVOffset will be the new GEP offset that is interpreted by GEP as a
     // signed value. ExitCount on the other hand represents the loop trip count,
     // which is an unsigned value. FindLoopCounter only allows induction
@@ -979,8 +979,7 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB,
     // Ensure that we generate the same type as IndVar, or a smaller integer
     // type. In the presence of null pointer values, we have an integer type
     // SCEV expression (IVInit) for a pointer type IV value (IndVar).
-    Type *LimitTy = ExitCount->getType()->isPointerTy() ?
-      IndVar->getType() : ExitCount->getType();
+    Type *LimitTy = ExitCount->getType();
     BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
     return Rewriter.expandCodeFor(IVLimit, LimitTy, BI);
   }