[PATCH] D146468: [LFTR] Use evaluateAtIteration in genLoopLimit [nfc]
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 20 16:15:32 PDT 2023
reames created this revision.
reames added reviewers: nikic, fhahn.
Herald added subscribers: StephenFan, bollu, hiraditya, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added a project: LLVM.
Note that the comments being remove appear to be very out of sync with the actual code in question.
I am not entirely sure of this change, and am not strongly motivated to pursue it. It mostly came out of discussion on https://reviews.llvm.org/D146457, and me going "why doesn't LFTR use this?". I never found a good answer.
https://reviews.llvm.org/D146468
Files:
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -917,27 +917,13 @@
assert(AR->getStepRecurrence(*SE)->isOne() && "only handles unit stride");
// IVInit may be a pointer while ExitCount is an integer when FindLoopCounter
- // 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.
+ // finds a valid pointer IV.
if (IndVar->getType()->isPointerTy() &&
!ExitCount->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
- // variables that have a positive unit stride of one. This means we don't
- // have to handle the case of negative offsets (yet) and just need to zero
- // extend ExitCount.
- Type *OfsTy = SE->getEffectiveSCEVType(IVInit->getType());
- const SCEV *IVOffset = SE->getTruncateOrZeroExtend(ExitCount, OfsTy);
- if (UsePostInc)
- IVOffset = SE->getAddExpr(IVOffset, SE->getOne(OfsTy));
- // Expand the code for the iteration count.
- assert(SE->isLoopInvariant(IVOffset, L) &&
- "Computed iteration count is not loop invariant!");
+ const SCEVAddRecExpr *ARBase = UsePostInc ? AR->getPostIncExpr(*SE) : AR;
+ const SCEV *IVLimit = ARBase->evaluateAtIteration(ExitCount, *SE);
- const SCEV *IVLimit = SE->getAddExpr(IVInit, IVOffset);
BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
return Rewriter.expandCodeFor(IVLimit, IndVar->getType(), BI);
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146468.506764.patch
Type: text/x-patch
Size: 1892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230320/cd2197fd/attachment-0001.bin>
More information about the llvm-commits
mailing list