[llvm] [LoopInterchange] Bail out early if minimum loop nest is not met (PR #115127)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 23:20:13 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Madhur Amilkanthwar (madhur13490)
<details>
<summary>Changes</summary>
This patch bails out early if minimum depth
is not met. As it stands today, the pass computes
CacheCost before it attempts to do the transform.
This is not needed if minimum depth is not met.
This handles basic cases where depth is typically 1.
As the patch avoids unnecessary computation, it is aimed to improve compile-time.
---
Full diff: https://github.com/llvm/llvm-project/pull/115127.diff
2 Files Affected:
- (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+1-1)
- (modified) llvm/lib/Transforms/Scalar/LoopInterchange.cpp (+18-4)
``````````diff
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 16fe9a74bb9c0d..c1650db0e7059d 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -199,7 +199,7 @@ static cl::opt<bool> RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden,
cl::desc("Run the NewGVN pass"));
static cl::opt<bool> EnableLoopInterchange(
- "enable-loopinterchange", cl::init(false), cl::Hidden,
+ "enable-loopinterchange", cl::init(true), cl::Hidden,
cl::desc("Enable the experimental LoopInterchange Pass"));
static cl::opt<bool> EnableUnrollAndJam("enable-unroll-and-jam",
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index db63bda1e6b926..09bd7d8eda8547 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -234,6 +234,14 @@ static void populateWorklist(Loop &L, LoopVector &LoopList) {
LoopList.push_back(CurrentLoop);
}
+static bool hasMinimumLoopDepth(SmallVectorImpl<Loop *> &LoopList) {
+ unsigned LoopNestDepth = LoopList.size();
+ if (LoopNestDepth < 2) {
+ LLVM_DEBUG(dbgs() << "Loop doesn't contain minimum nesting level.\n");
+ return false;
+ }
+ return true;
+}
namespace {
/// LoopInterchangeLegality checks if it is legal to interchange the loop.
@@ -416,11 +424,11 @@ struct LoopInterchange {
bool processLoopList(SmallVectorImpl<Loop *> &LoopList) {
bool Changed = false;
- unsigned LoopNestDepth = LoopList.size();
- if (LoopNestDepth < 2) {
- LLVM_DEBUG(dbgs() << "Loop doesn't contain minimum nesting level.\n");
+
+ if (!hasMinimumLoopDepth(LoopList))
return false;
- }
+
+ unsigned LoopNestDepth = LoopList.size();
if (LoopNestDepth > MaxLoopNestDepth) {
LLVM_DEBUG(dbgs() << "Cannot handle loops of depth greater than "
<< MaxLoopNestDepth << "\n");
@@ -1713,6 +1721,12 @@ PreservedAnalyses LoopInterchangePass::run(LoopNest &LN,
LPMUpdater &U) {
Function &F = *LN.getParent();
+ SmallVector<Loop *, 8> LoopList(LN.getLoops());
+
+ // Ensure minimum depth of the loop nest to do the interchange.
+ if (!hasMinimumLoopDepth(LoopList))
+ return PreservedAnalyses::all();
+
DependenceInfo DI(&F, &AR.AA, &AR.SE, &AR.LI);
std::unique_ptr<CacheCost> CC =
CacheCost::getCacheCost(LN.getOutermostLoop(), AR, DI);
``````````
</details>
https://github.com/llvm/llvm-project/pull/115127
More information about the llvm-commits
mailing list