[llvm-branch-commits] [llvm] [DA] Fix overflow of calculation in weakCrossingSIVtest (PR #188450)

Ryotaro Kasuga via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Mar 25 06:06:52 PDT 2026


================
@@ -1454,17 +1454,23 @@ bool DependenceInfo::weakCrossingSIVtest(const SCEV *Coeff,
   if (const SCEV *UpperBound =
           collectUpperBound(CurSrcLoop, Delta->getType())) {
     LLVM_DEBUG(dbgs() << "\t    UpperBound = " << *UpperBound << "\n");
-    const SCEV *ConstantTwo = SE->getConstant(UpperBound->getType(), 2);
-    const SCEV *ML =
-        SE->getMulExpr(SE->getMulExpr(ConstCoeff, UpperBound), ConstantTwo);
-    LLVM_DEBUG(dbgs() << "\t    ML = " << *ML << "\n");
-    if (SE->isKnownPredicate(CmpInst::ICMP_SGT, Delta, ML)) {
+    ConstantRange UBRange = SE->getSignedRange(UpperBound);
+    ConstantRange MLRange =
+        UBRange.smul_fast(ConstCoeff->getAPInt())
+            .smul_fast(APInt(Distance.getBitWidth(), 2, true));
+    ConstantRange DeltaRange(ConstDelta->getAPInt());
+    LLVM_DEBUG(dbgs() << "\t    UBRange = " << UBRange << "\n");
+    LLVM_DEBUG(dbgs() << "\t    MLRange = " << MLRange << "\n");
+    LLVM_DEBUG(dbgs() << "\t    DeltaRange = " << DeltaRange << "\n");
+
+    if (DeltaRange.intersectWith(MLRange).isEmptySet() &&
+        DeltaRange.getSignedMin().sgt(MLRange.getSignedMax())) {
       // Delta too big, no dependence
       ++WeakCrossingSIVindependence;
       ++WeakCrossingSIVsuccesses;
       return true;
     }
-    if (SE->isKnownPredicate(CmpInst::ICMP_EQ, Delta, ML)) {
+    if (DeltaRange.getSignedMin().eq(MLRange.getSignedMax())) {
----------------
kasuga-fj wrote:

```suggestion
    if (APDelta.eq(MLRange.getSignedMax())) {
```

But I'm not sure whether this is correct. For example, what happens in the following case?

```c
for (i = 0; i < N; i++) {
  A[i - (2^62-1)] = 0;
  A[-i + 2^62] = 1;
}
```

IIUC, there is a dependency `[<>]` if `N` is large enough, but maybe fail to detect it?

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


More information about the llvm-branch-commits mailing list