[llvm] [LoopInterchange] Add loop names to debug messages. NFC (PR #172855)
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 18 06:26:36 PST 2025
https://github.com/sjoerdmeijer created https://github.com/llvm/llvm-project/pull/172855
The debug messages are difficult to follow, because it is not printing which loops it is dealing with (or you would need to scroll up a lot and then it's still not very clear). Thus, this just adds loop names to various debug messages so it's easier to see which loops it is accepting, rejecting, etc.
>From 85bc2627075c1fe475f9e48d1eef3b89ab8edc4f Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <smeijer at nvidia.com>
Date: Thu, 18 Dec 2025 06:23:07 -0800
Subject: [PATCH] [LoopInterchange] Add loop names to debug messages. NFC
The debug messages are difficult to follow, because it is not printing
which loops it is dealing with (or you would need to scroll up a lot and
then it's still not very clear). Thus, this just adds loop names to
various debug messages so it's easier to see which loops it is
accepting, rejecting, etc.
---
.../lib/Transforms/Scalar/LoopInterchange.cpp | 32 ++++++++++++++-----
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 330b4abb9942f..bdc01c14d0e0e 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -642,8 +642,14 @@ struct LoopInterchange {
unsigned LoopNestDepth = LoopList.size();
- LLVM_DEBUG(dbgs() << "Processing LoopList of size = " << LoopNestDepth
- << "\n");
+ LLVM_DEBUG(
+ dbgs() << "Processing LoopList of size = " << LoopNestDepth
+ << " containing the following loops:\n";
+ for (auto *L : LoopList) {
+ dbgs() << " - ";
+ L->print(dbgs());
+ }
+ );
CharMatrix DependencyMatrix;
Loop *OuterMostLoop = *(LoopList.begin());
@@ -659,7 +665,8 @@ struct LoopInterchange {
// Get the Outermost loop exit.
BasicBlock *LoopNestExit = OuterMostLoop->getExitBlock();
if (!LoopNestExit) {
- LLVM_DEBUG(dbgs() << "OuterMostLoop needs an unique exit block");
+ LLVM_DEBUG(dbgs() << "OuterMostLoop '" << OuterMostLoop->getName()
+ << "' needs an unique exit block");
return false;
}
@@ -695,14 +702,19 @@ struct LoopInterchange {
<< " and OuterLoopId = " << OuterLoopId << "\n");
LoopInterchangeLegality LIL(OuterLoop, InnerLoop, SE, ORE);
if (!LIL.canInterchangeLoops(InnerLoopId, OuterLoopId, DependencyMatrix)) {
- LLVM_DEBUG(dbgs() << "Not interchanging loops. Cannot prove legality.\n");
+ LLVM_DEBUG(dbgs() << "Cannot prove legality, not interchanging loops '"
+ << OuterLoop->getName() << "' and '"
+ << InnerLoop->getName() << "'\n");
return false;
}
- LLVM_DEBUG(dbgs() << "Loops are legal to interchange\n");
+ LLVM_DEBUG(dbgs() << "Loops '" << OuterLoop->getName() << "' and '"
+ << InnerLoop->getName() << "' are legal to interchange\n");
LoopInterchangeProfitability LIP(OuterLoop, InnerLoop, SE, ORE);
if (!LIP.isProfitable(InnerLoop, OuterLoop, InnerLoopId, OuterLoopId,
DependencyMatrix, CCM)) {
- LLVM_DEBUG(dbgs() << "Interchanging loops not profitable.\n");
+ LLVM_DEBUG(dbgs() << "Interchanging loops '" << OuterLoop->getName()
+ << "' and '" << InnerLoop->getName()
+ << "' not profitable.\n");
return false;
}
@@ -715,7 +727,9 @@ struct LoopInterchange {
LoopInterchangeTransform LIT(OuterLoop, InnerLoop, SE, LI, DT, LIL);
LIT.transform(LIL.getHasNoWrapReductions());
- LLVM_DEBUG(dbgs() << "Loops interchanged.\n");
+ LLVM_DEBUG(dbgs() << "Loops interchanged: outer loop '"
+ << OuterLoop->getName() << "' and inner loop '"
+ << InnerLoop->getName() << "'\n");
LoopsInterchanged++;
llvm::formLCSSARecursively(*OuterLoop, *DT, LI, SE);
@@ -745,7 +759,9 @@ bool LoopInterchangeLegality::tightlyNested(Loop *OuterLoop, Loop *InnerLoop) {
BasicBlock *InnerLoopPreHeader = InnerLoop->getLoopPreheader();
BasicBlock *OuterLoopLatch = OuterLoop->getLoopLatch();
- LLVM_DEBUG(dbgs() << "Checking if loops are tightly nested\n");
+ LLVM_DEBUG(dbgs() << "Checking if loops '" << OuterLoop->getName()
+ << "' and '" << InnerLoop->getName()
+ << "' are tightly nested\n");
// A perfectly nested loop will not have any branch in between the outer and
// inner block i.e. outer header will branch to either inner preheader and
More information about the llvm-commits
mailing list