[llvm] [DA] use NSW arithmetic (PR #116632)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 18 07:21:14 PST 2024


================
@@ -3116,11 +3116,9 @@ const SCEV *DependenceInfo::addToCoefficient(const SCEV *Expr,
                                              const Loop *TargetLoop,
                                              const SCEV *Value) const {
   const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Expr);
-  if (!AddRec) // create a new addRec
-    return SE->getAddRecExpr(Expr,
-                             Value,
-                             TargetLoop,
-                             SCEV::FlagAnyWrap); // Worst case, with no info.
+  if (!AddRec)
+    return SE->getAddRecExpr(Expr, Value, TargetLoop, SCEV::FlagNSW);
----------------
fhahn wrote:

Why is it safe to assume NSW without any additional information here? 

Also, I think as @nikic mentioned, at the moment, we would need to prove that NSW holds in all contexts where the new AddRec is valid

There's https://github.com/llvm/llvm-project/pull/91961 to extend SCEV to allow constructing SCEV's with context-sensitive wrapping flags.

https://github.com/llvm/llvm-project/pull/116632


More information about the llvm-commits mailing list