[llvm] [LAA] Honor no-wrap predicates already in PSE in isNoWrap (PR #226430)
Tim Besard via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 00:21:22 PDT 2026
================
@@ -1153,7 +1153,12 @@ isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR, Value *Ptr,
return true;
}
- return false;
+ // Without adding a new predicate, AR may still be known not to wrap if the
+ // predicates of PSE already imply it, e.g. because a wrap predicate for AR
+ // was added while analyzing the dependences of the loop.
+ ScalarEvolution &SE = *PSE.getSE();
+ return PSE.getPredicate().implies(
+ SE.getWrapPredicate(AR, SCEVWrapPredicate::IncrementNUSW), SE);
----------------
maleadt wrote:
Thanks, but I don't think this works. Applying your suggestion breaks the case I'm interested in: `isDependenceDistanceOfOne` calls `getPtrStride` without a `Predicates` vector, so `isNoWrap` never enters `if (Ptr && Predicates)` and still returns false for pointers whose NUSW predicate was already added. With the suggestion applied, both new tests fail and LLE doesn't eliminate any loads.
AFAIU skipping the `push_back` also doesn't change anything: every caller passes the collected predicates to `PSE.addPredicates`, which already drops implied ones, so the check would just run the `implies()` scan twice for each new predicate.
I've instead pushed a version that takes what I understand to be the idea of your suggestion, building a single NUSW wrap predicate for the pointer, and uses it for both outcomes. Can you take another look?
https://github.com/llvm/llvm-project/pull/226430
More information about the llvm-commits
mailing list