[llvm] [DA] Fix zero coeff bug in Strong SIV test with runtime assumptions (#149991) (PR #155037)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 06:18:04 PST 2025


================
@@ -1282,7 +1282,40 @@ bool DependenceInfo::strongSIVtest(const SCEV *Coeff, const SCEV *SrcConst,
       Result.DV[Level].Direction &= Dependence::DVEntry::EQ;
     ++StrongSIVsuccesses;
   } else if (Delta->isZero()) {
-    // since 0/X == 0
+    // Check if coefficient could be zero. If so, 0/0 is undefined and we
+    // cannot conclude that only same-iteration dependencies exist.
+    // When coeff=0, all iterations access the same location.
+    if (isa<SCEVUnknown>(Coeff) && !SE->isKnownNonZero(Coeff)) {
+      // Use SCEV range analysis to prove coefficient != 0 in loop context.
+      const SCEV *Zero = SE->getZero(Coeff->getType());
+
+      // Ask SCEV's range analysis if it can prove Coeff != Zero.
+      if (SE->isKnownPredicate(ICmpInst::ICMP_NE, Coeff, Zero)) {
----------------
Meinersbur wrote:

This is the same test as on line 1288. If they are not equally powerful (that would be some TODO to fix):
```
boo lsKnownNonZero = SE->isKnownNonZero(Coeff) || SE->isKnownPredicate(ICmpInst::ICMP_NE, Coeff, Zero);
```
There is also `DependenceInfo::isKnownPredicate`

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


More information about the llvm-commits mailing list