diff options
author | Florian Hahn <flo@fhahn.com> | 2025-09-04 11:32:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-04 11:32:33 +0100 |
commit | b400fd115145ccea0b62944e37e74eedc9da223f (patch) | |
tree | 29cbe2f2410c3d2a0b4dd1c7eab1878d679caca0 /llvm/lib/Analysis/LoopAccessAnalysis.cpp | |
parent | c14052e20b87bc74a031d09fb312723e0751ed0f (diff) | |
download | llvm-b400fd115145ccea0b62944e37e74eedc9da223f.zip llvm-b400fd115145ccea0b62944e37e74eedc9da223f.tar.gz llvm-b400fd115145ccea0b62944e37e74eedc9da223f.tar.bz2 |
[LAA] Support assumptions with non-constant deref sizes. (#156758)
Update evaluatePtrAddrecAtMaxBTCWillNotWrap to support non-constant
sizes in dereferenceable assumptions.
Apply loop-guards in a few places needed to reason about expressions
involving trip counts of the from (BTC - 1).
PR: https://github.com/llvm/llvm-project/pull/156758
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopAccessAnalysis.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index e18cc6b..cfddd99 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -238,8 +238,8 @@ static bool evaluatePtrAddRecAtMaxBTCWillNotWrap( StartPtrV, {Attribute::Dereferenceable}, *AC, L->getLoopPredecessor()->getTerminator(), DT); if (DerefRK) { - DerefBytesSCEV = SE.getUMaxExpr( - DerefBytesSCEV, SE.getConstant(WiderTy, DerefRK.ArgValue)); + DerefBytesSCEV = + SE.getUMaxExpr(DerefBytesSCEV, SE.getSCEV(DerefRK.IRArgValue)); } } @@ -259,6 +259,10 @@ static bool evaluatePtrAddRecAtMaxBTCWillNotWrap( const SCEV *StartOffset = SE.getNoopOrZeroExtend( SE.getMinusSCEV(AR->getStart(), StartPtr), WiderTy); + if (!LoopGuards) + LoopGuards.emplace(ScalarEvolution::LoopGuards::collect(AR->getLoop(), SE)); + MaxBTC = SE.applyLoopGuards(MaxBTC, *LoopGuards); + const SCEV *OffsetAtLastIter = mulSCEVOverflow(MaxBTC, SE.getAbsExpr(Step, /*IsNSW=*/false), SE); if (!OffsetAtLastIter) { @@ -288,11 +292,7 @@ static bool evaluatePtrAddRecAtMaxBTCWillNotWrap( if (!EndBytes) return false; - if (!LoopGuards) - LoopGuards.emplace( - ScalarEvolution::LoopGuards::collect(AR->getLoop(), SE)); - - EndBytes = SE.applyLoopGuards(EndBytes, *LoopGuards); + DerefBytesSCEV = SE.applyLoopGuards(DerefBytesSCEV, *LoopGuards); return SE.isKnownPredicate(CmpInst::ICMP_ULE, EndBytes, DerefBytesSCEV); } |