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

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Mar 25 02:22:05 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Ruoyu Qiu (cabbaken)

<details>
<summary>Changes</summary>

This patch moves the check that `Coeff` divides `Delta` earlier in the
function to enable an early exit. Potentially improve performance.



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


1 Files Affected:

- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+21-21) 


``````````diff
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index b26c53e50d9e4..5885306302de1 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -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;
+  }
+
   // We're certain that Delta > 0 and ConstCoeff > 0.
   // Check Delta/(2*ConstCoeff) against upper loop bound
   if (const SCEV *UpperBound =
@@ -1457,27 +1478,6 @@ bool DependenceInfo::weakCrossingSIVtest(const SCEV *Coeff,
     }
   }
 
-  // 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;
-  }
   return false;
 }
 

``````````

</details>


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


More information about the llvm-branch-commits mailing list