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

Ruoyu Qiu via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 21:46:54 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");
+
----------------
cabbaken wrote:

Yes, I removed them.

Additionally, the ConstantRange-based intersection test has now been consolidated into a single, early pre-test (#187435).

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


More information about the llvm-commits mailing list