[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
+  //    assertion, we conclude that both coefficients are equal and this should
+  //    be processed by strongSIVtest, not WeakCrossingSIVtest.
----------------
kasuga-fj wrote:

```suggestion
  //    be processed by strongSIVtest, not weakCrossingSIVtest.
```

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


More information about the llvm-commits mailing list