[llvm-branch-commits] [llvm] [DA] Hoist division check for early exit in weakCrossingSIVtest (NFC) (PR #188442)
Ruoyu Qiu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Mar 25 02:19:47 PDT 2026
https://github.com/cabbaken created https://github.com/llvm/llvm-project/pull/188442
This patch moves the check that `Coeff` divides `Delta` earlier in the
function to enable an early exit. Potentially improve performance.
>From 3059a1e8f665e329c1cd2867a8ceaa5309a1c693 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 25 Mar 2026 09:07:55 +0000
Subject: [PATCH] [DA] Hoist division check for early exit in
weakCrossingSIVtest (NFC)
This patch moves the check that `Coeff` divides `Delta` earlier in the
function to enable an early exit. Potentially improve performance.
Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
llvm/lib/Analysis/DependenceAnalysis.cpp | 42 ++++++++++++------------
1 file changed, 21 insertions(+), 21 deletions(-)
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;
}
More information about the llvm-branch-commits
mailing list