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

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 6 07:06:53 PST 2025


================
@@ -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);
----------------
sebpop wrote:

> The NSW flag doesn't make it linear in the mathematical sense

Yes NSW does determine the check for affine functions in checkSubscript:

https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/DependenceAnalysis.cpp#L988

```
// Examine the scev and return true iff it's affine.
// Collect any loops mentioned in the set of "Loops".
bool DependenceInfo::checkSubscript(const SCEV *Expr, const Loop *LoopNest,
[...]
      if (!AddRec->getNoWrapFlags())
        return false;
```

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


More information about the llvm-commits mailing list