[llvm] [DA] Hoist division check for early exit in weakCrossingSIVtest (NFC) (PR #188442)

Ruoyu Qiu via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 23:09:16 PDT 2026


================
@@ -1428,6 +1428,27 @@ bool DependenceInfo::weakCrossingSIVtest(const SCEV *Coeff,
     return true;
   }
 
+  // check that Coeff divides Delta
+  APInt APDelta = ConstDelta->getAPInt();
+  APInt APCoeff = ConstCoeff->getAPInt();
+  APInt Distance = APDelta; // these need to be initialzed
+  APInt Remainder = APDelta;
+  APInt::sdivrem(APDelta, APCoeff, Distance, Remainder);
+  LLVM_DEBUG(dbgs() << "\t    Remainder = " << Remainder << "\n");
+  if (Remainder != 0) {
+    // Coeff doesn't divide Delta, no dependence
+    ++WeakCrossingSIVindependence;
+    ++WeakCrossingSIVsuccesses;
+    return true;
+  }
+  LLVM_DEBUG(dbgs() << "\t    Distance = " << Distance << "\n");
+  // if 2*Coeff doesn't divide Delta, then the equal direction isn't possible
+  if (Distance[0]) {
+    // Equal direction isn't possible
+    Result.DV[Level].Direction &= ~Dependence::DVEntry::EQ;
+    ++WeakCrossingSIVsuccesses;
----------------
cabbaken wrote:

I think we should figure out what `*successes` metrics represents.

- If it represents 'the number by which a test can prove independence', it should not be incremented here.
- If it represents 'the number by which a test can refine direction vector', it should be incremented here.

Accroding to the code in `banerjeeMIVtest`:

```cpp
    if (NewDeps > 0) {
      bool Improved = false;
      for (unsigned K = 1; K <= CommonLevels; ++K) {
        if (Loops[K]) {
          unsigned Old = Result.DV[K - 1].Direction;
          Result.DV[K - 1].Direction = Old & Bound[K].DirSet;
          Improved |= Old != Result.DV[K - 1].Direction;
          if (!Result.DV[K - 1].Direction) {
            Improved = false;
            Disproved = true;
            break;
          }
        }
      }
      if (Improved)
        ++BanerjeeSuccesses;
```

The `Improved` implies 'if this test refines the direction vector', and it can only be incremented once in one invocation.

I would fix this here and the fix for `exactSIV` should be in a different PR.

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


More information about the llvm-commits mailing list