Skip to content

Commit ed275fb

Browse files
committed
[LoopInterchange] Bail out early if minimum loop nest is not met
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.
1 parent 895a8e6 commit ed275fb

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static cl::opt<bool> RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden,
199199
cl::desc("Run the NewGVN pass"));
200200

201201
static cl::opt<bool> EnableLoopInterchange(
202-
"enable-loopinterchange", cl::init(false), cl::Hidden,
202+
"enable-loopinterchange", cl::init(true), cl::Hidden,
203203
cl::desc("Enable the experimental LoopInterchange Pass"));
204204

205205
static cl::opt<bool> EnableUnrollAndJam("enable-unroll-and-jam",

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ static void populateWorklist(Loop &L, LoopVector &LoopList) {
234234
LoopList.push_back(CurrentLoop);
235235
}
236236

237+
static bool hasMinimumLoopDepth(SmallVectorImpl<Loop *> &LoopList) {
238+
unsigned LoopNestDepth = LoopList.size();
239+
if (LoopNestDepth < 2) {
240+
LLVM_DEBUG(dbgs() << "Loop doesn't contain minimum nesting level.\n");
241+
return false;
242+
}
243+
return true;
244+
}
237245
namespace {
238246

239247
/// LoopInterchangeLegality checks if it is legal to interchange the loop.
@@ -416,11 +424,11 @@ struct LoopInterchange {
416424

417425
bool processLoopList(SmallVectorImpl<Loop *> &LoopList) {
418426
bool Changed = false;
419-
unsigned LoopNestDepth = LoopList.size();
420-
if (LoopNestDepth < 2) {
421-
LLVM_DEBUG(dbgs() << "Loop doesn't contain minimum nesting level.\n");
427+
428+
if (!hasMinimumLoopDepth(LoopList))
422429
return false;
423-
}
430+
431+
unsigned LoopNestDepth = LoopList.size();
424432
if (LoopNestDepth > MaxLoopNestDepth) {
425433
LLVM_DEBUG(dbgs() << "Cannot handle loops of depth greater than "
426434
<< MaxLoopNestDepth << "\n");
@@ -1713,6 +1721,12 @@ PreservedAnalyses LoopInterchangePass::run(LoopNest &LN,
17131721
LPMUpdater &U) {
17141722
Function &F = *LN.getParent();
17151723

1724+
SmallVector<Loop *, 8> LoopList(LN.getLoops());
1725+
1726+
// Ensure minimum depth of the loop nest to do the interchange.
1727+
if (!hasMinimumLoopDepth(LoopList))
1728+
return PreservedAnalyses::all();
1729+
17161730
DependenceInfo DI(&F, &AR.AA, &AR.SE, &AR.LI);
17171731
std::unique_ptr<CacheCost> CC =
17181732
CacheCost::getCacheCost(LN.getOutermostLoop(), AR, DI);

0 commit comments

Comments
 (0)