[llvm] [LAA] Be more careful when evaluating AddRecs at symbolic max BTC. (PR #128061)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 25 06:02:48 PST 2025
================
@@ -206,11 +206,31 @@ std::pair<const SCEV *, const SCEV *> llvm::getStartAndEndForAccess(
const SCEV *ScStart;
const SCEV *ScEnd;
+ auto &DL = Lp->getHeader()->getDataLayout();
+ Type *IdxTy = DL.getIndexType(PtrExpr->getType());
+ const SCEV *EltSizeSCEV = SE->getStoreSizeOfExpr(IdxTy, AccessTy);
if (SE->isLoopInvariant(PtrExpr, Lp)) {
ScStart = ScEnd = PtrExpr;
} else if (auto *AR = dyn_cast<SCEVAddRecExpr>(PtrExpr)) {
ScStart = AR->getStart();
- ScEnd = AR->evaluateAtIteration(MaxBECount, *SE);
+ if (!isa<SCEVCouldNotCompute>(BTC))
----------------
fhahn wrote:
Thanks for digging into this! One clarification is that we evaluate at BTC = UNSIGNED_MAX. So `{0, +, 1}` won't wrap, but adding `1` will (`getStartAndEndForAccess` will compute the first address after the last access).
When we have strides larger than 1, the last accessed address will be something like `%start + stride * UNSIGNED_MAX`, which should wrap to something like `%start - %stride`. I am not entirely sure if there may be other wrapping issues with how `evaluateAtIteration` internally computes the result, but the original end point computed for `runtime_checks_with_symbolic_max_btc_neg_1` should illustrates that: start == end due to adding %stride to the result of evaluateAtIteration.
https://github.com/llvm/llvm-project/pull/128061
More information about the llvm-commits
mailing list