From 042783f556639cd5c3b2f4db67c6eeacea53459e Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 21 Mar 2023 07:18:27 -0700 Subject: [PATCH] [LFTR] Assert and simplify under assumption exit counts are integers [nfc] This invariant was introduced in 8f3d16905d75b07a933d01dc29677fe5867c1b3e. Differential Revision: https://reviews.llvm.org/D146470 --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 0f784a8..2b19842 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -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(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(ExitingBB->getTerminator()); return Rewriter.expandCodeFor(IVLimit, LimitTy, BI); } -- 2.7.4