[llvm] [DependenceAnalysis] Fix incorrect analysis of wrapping AddRec expressions (PR #154982)
Sebastian Pop via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 23 13:05:58 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()) {
----------------
sebpop wrote:
> SCEVWrapPredicate requires both nusw and nsw
I fixed SCEVWrapPredicate to only require the existing wrap flags, and if the AddRec does not have wrap flags, then NUSW for pointer types and NSSW for integers.
> which property you actually need for DA
we need to ensure AddRec expressions don't create cyclic patterns that violate linearity assumptions. So NW is enough as it is set whenever either NUW or NSW are set. Thus fixed in the above code avoiding 2 flag checks.
https://github.com/llvm/llvm-project/pull/154982
More information about the llvm-commits
mailing list