[llvm] [LAA][NFC] Refactor deref no-wrap check; expose broken reverse-loop bounds (PR #211960)
Aleksandr Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 31 08:51:39 PDT 2026
================
@@ -277,45 +281,51 @@ static bool evaluatePtrAddRecAtMaxBTCWillNotWrap(
LoopGuards.emplace(ScalarEvolution::LoopGuards::collect(AR->getLoop(), SE));
MaxBTC = SE.applyLoopGuards(MaxBTC, *LoopGuards);
- const SCEV *OffsetAtLastIter =
- mulSCEVNoOverflow(MaxBTC, SE.getAbsExpr(Step, /*IsNSW=*/false), SE);
- if (!OffsetAtLastIter) {
+ const SCEV *AbsStep = SE.getAbsExpr(Step, /*IsNSW=*/false);
+ // Total distance (in bytes) walked between the first and the last
+ // accessed pointer; MaxBTC * |Step|.
+ const SCEV *WalkBytes = mulSCEVNoOverflow(MaxBTC, AbsStep, SE);
+ if (!WalkBytes) {
// Re-try with constant max backedge-taken count if using the symbolic one
// failed.
MaxBTC = SE.getConstantMaxBackedgeTakenCount(AR->getLoop());
if (isa<SCEVCouldNotCompute>(MaxBTC))
return false;
- MaxBTC = SE.getNoopOrZeroExtend(
- MaxBTC, WiderTy);
- OffsetAtLastIter =
- mulSCEVNoOverflow(MaxBTC, SE.getAbsExpr(Step, /*IsNSW=*/false), SE);
- if (!OffsetAtLastIter)
+ MaxBTC = SE.getNoopOrZeroExtend(MaxBTC, WiderTy);
+ WalkBytes = mulSCEVNoOverflow(MaxBTC, AbsStep, SE);
+ if (!WalkBytes)
return false;
}
- const SCEV *OffsetEndBytes = addSCEVNoOverflow(
- OffsetAtLastIter, SE.getNoopOrZeroExtend(EltSize, WiderTy), SE);
- if (!OffsetEndBytes)
+ // Total length in bytes of the accessed range (from the first accessed
+ // byte through the end of the last access); WalkBytes + EltSize.
+ const SCEV *SpanBytes = addSCEVNoOverflow(
+ WalkBytes, SE.getNoopOrZeroExtend(EltSize, WiderTy), SE);
+ if (!SpanBytes)
return false;
+ // Compute MaxOffset per direction: exclusive upper offset of the
+ // accessed range.
----------------
aleks-tmb wrote:
I initially introduced some of these changes; please see the original commit: https://github.com/llvm/llvm-project/pull/211960/changes/172ef03d3d19e2d7ceca01079e59b3e6834d57e9
However, during the review, we decided to preserve the existing terminology and move those changes to a follow-up patch containing the actual fix: https://github.com/llvm/llvm-project/pull/211960#discussion_r3674208932
https://github.com/llvm/llvm-project/pull/211960
More information about the llvm-commits
mailing list