[llvm] [LAA,Loads] Use loop guards and max BTC if needed when checking deref. (PR #155672)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 28 08:07:36 PDT 2025
================
@@ -263,23 +260,36 @@ evaluatePtrAddRecAtMaxBTCWillNotWrap(const SCEVAddRecExpr *AR,
SE.getMinusSCEV(AR->getStart(), StartPtr), WiderTy);
const SCEV *OffsetAtLastIter =
- mulSCEVOverflow(MaxBTC, SE.getAbsExpr(Step, /*IsNSW=*/false), SE, CtxI);
- if (!OffsetAtLastIter)
- return false;
+ mulSCEVOverflow(MaxBTC, SE.getAbsExpr(Step, /*IsNSW=*/false), SE);
+ if (!OffsetAtLastIter) {
+ // Re-try with constant max backedge-taken count if using the symbolic one
+ // failed.
+ MaxBTC = SE.getNoopOrZeroExtend(
+ SE.getConstantMaxBackedgeTakenCount(AR->getLoop()), WiderTy);
+ OffsetAtLastIter =
+ mulSCEVOverflow(MaxBTC, SE.getAbsExpr(Step, /*IsNSW=*/false), SE);
----------------
fhahn wrote:
Unfortunately that's not enough in some cases, for example https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/LoopVectorize/single_early_exit.ll#L333 where the trip count of the inner loop depends on an induction from the outer loop
https://github.com/llvm/llvm-project/pull/155672
More information about the llvm-commits
mailing list