[llvm] [DependenceAnalysis] Fix incorrect analysis of wrapping AddRec expressions (PR #154982)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 24 16:22:37 PDT 2025
================
@@ -6439,8 +6439,129 @@ void ScalarEvolution::setNoWrapFlags(SCEVAddRecExpr *AddRec,
}
}
-ConstantRange ScalarEvolution::
-getRangeForUnknownRecurrence(const SCEVUnknown *U) {
+std::optional<bool>
+ScalarEvolution::mayAddRecWrap(const SCEVAddRecExpr *AddRec) {
+ Type *Ty = AddRec->getType();
+
+ // Pointer AddRec expressions do not wrap in the arithmetic sense.
+ if (Ty->isPointerTy())
+ return false;
+
+ // Step 1: Check existing no-wrap flags from SCEV construction.
+ if (AddRec->hasNoSelfWrap() || AddRec->hasNoUnsignedWrap() ||
+ AddRec->hasNoSignedWrap()) {
----------------
kasuga-fj wrote:
NW is insufficient. DA handles affine format expressions and expects their "monotonicity". Things are getting complicated because signed and unsigned interpretations are mixed up in DA.
> Overall I'm left confused which property you actually need for DA. Is it nw, nsw, nuw, nusw or some combination thereof?
I don't think this question is simple enough to be answered easily. The only thing now I'm certain of is that "NW is not sufficient".
https://github.com/llvm/llvm-project/pull/154982
More information about the llvm-commits
mailing list