[llvm] 042783f - [LFTR] Assert and simplify under assumption exit counts are integers [nfc]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 07:35:19 PDT 2023
Author: Philip Reames
Date: 2023-03-21T07:35:05-07:00
New Revision: 042783f556639cd5c3b2f4db67c6eeacea53459e
URL: https://github.com/llvm/llvm-project/commit/042783f556639cd5c3b2f4db67c6eeacea53459e
DIFF: https://github.com/llvm/llvm-project/commit/042783f556639cd5c3b2f4db67c6eeacea53459e.diff
LOG: [LFTR] Assert and simplify under assumption exit counts are integers [nfc]
This invariant was introduced in 8f3d16905d75b07a933d01dc29677fe5867c1b3e.
Differential Revision: https://reviews.llvm.org/D146470
Added:
Modified:
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 0f784a8715edb..2b19842050a5f 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<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);
}
More information about the llvm-commits
mailing list