[llvm] [DA] Require 'nsw' for AddRecs in the WeakCrossing SIV test (PR #185041)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 21:59:18 PDT 2026


================
@@ -1366,15 +1366,28 @@ bool DependenceInfo::strongSIVtest(const SCEVAddRecExpr *Src,
 // Can determine iteration for splitting.
 //
 // Return true if dependence disproved.
-bool DependenceInfo::weakCrossingSIVtest(const SCEV *Coeff,
-                                         const SCEV *SrcConst,
-                                         const SCEV *DstConst,
-                                         const Loop *CurSrcLoop,
-                                         const Loop *CurDstLoop, unsigned Level,
+bool DependenceInfo::weakCrossingSIVtest(const SCEVAddRecExpr *Src,
+                                         const SCEVAddRecExpr *Dst,
+                                         unsigned Level,
                                          FullDependence &Result) const {
   if (!isDependenceTestEnabled(DependenceTestType::WeakCrossingSIV))
     return false;
 
+  if (!Src->hasNoSignedWrap() || !Dst->hasNoSignedWrap())
+    return false;
+
+  const SCEV *Coeff = Src->getStepRecurrence(*SE);
+  const SCEV *DstCoeff = Dst->getStepRecurrence(*SE);
+  assert(Coeff ==  SE->getNegativeSCEV(DstCoeff) && "Not a weak crossing case.");
+  // Coeff is equal to its negative value in two cases:
+  // 1. Coeff is zero. In this case, the subscripts are ZIV.
+  // 2. Coeff is the minimum signed value. In this case, given the previous
----------------
kasuga-fj wrote:

What happens if the coefficients are not constants. For example, when `Src` is like `{c0,+,a}`, `Dst` is like `{c1,+,(-1 * a)}`, and `a` can be zero or the signed minimum value? IMHO we should bail out conservatively if we cannot prove them, like as follows:

```cpp
if (!SE->isKnownPredicate(ICMP_NE, Coeff, SE->getNegativeSCEV(Coeff)))
  return false;

assert(SE->isKnownPredicate(ICMP_NE, Coeff, SE->getNegativeSCEV(Coeff)));
```

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


More information about the llvm-commits mailing list