[llvm] [LoopUnrollPass] Remove redundant debug message in `tryToUnrollLoop()` (PR #181954)

Justin Fargnoli via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 11:28:57 PST 2026


https://github.com/justinfargnoli updated https://github.com/llvm/llvm-project/pull/181954

>From 48bda25ea1ce2e71f4ff891fabe0303d54b9171b Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Wed, 18 Feb 2026 01:40:47 +0000
Subject: [PATCH 1/2] [LoopUnroll] Remove redundant debug message and update
 canUnroll() messages

Remove the redundant "Loop not considered unrollable." LLVM_DEBUG
message from tryToUnrollLoop(), since canUnroll() already prints
a specific reason for each failure case.

Update the debug messages in canUnroll() to use a consistent
"Not unrolling: <reason>" format that better describes the cause:
- "Not unrolling: contains convergent operations."
- "Not unrolling: loop size could not be computed."
- "Not unrolling: contains non-duplicatable instructions."

Also simplify the switch on Convergence to a plain if, since only
one case is handled.

This supersedes PR #178950 which had gone stale with merge conflicts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply at anthropic.com>
---
 llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 17 +++++++----------
 llvm/test/Transforms/LoopUnroll/debug.ll      |  6 ++----
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 40d8043d01e02..296e6f5b7e57f 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -717,20 +717,19 @@ UnrollCostEstimator::UnrollCostEstimator(
 }
 
 bool UnrollCostEstimator::canUnroll() const {
-  switch (Convergence) {
-  case ConvergenceKind::ExtendedLoop:
-    LLVM_DEBUG(dbgs().indent(1) << "Convergence prevents unrolling.\n");
+  if (Convergence == ConvergenceKind::ExtendedLoop) {
+    LLVM_DEBUG(
+        dbgs().indent(1) << "Not unrolling: contains convergent operations.\n");
     return false;
-  default:
-    break;
   }
   if (!LoopSize.isValid()) {
-    LLVM_DEBUG(dbgs().indent(1) << "Invalid loop size prevents unrolling.\n");
+    LLVM_DEBUG(dbgs().indent(1)
+               << "Not unrolling: loop size could not be computed.\n");
     return false;
   }
   if (NotDuplicatable) {
     LLVM_DEBUG(dbgs().indent(1)
-               << "Non-duplicatable blocks prevent unrolling.\n");
+               << "Not unrolling: contains non-duplicatable instructions.\n");
     return false;
   }
   return true;
@@ -1242,10 +1241,8 @@ tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
   CodeMetrics::collectEphemeralValues(L, &AC, EphValues);
 
   UnrollCostEstimator UCE(L, TTI, EphValues, UP.BEInsns);
-  if (!UCE.canUnroll()) {
-    LLVM_DEBUG(dbgs().indent(1) << "Loop not considered unrollable.\n");
+  if (!UCE.canUnroll())
     return LoopUnrollResult::Unmodified;
-  }
 
   unsigned LoopSize = UCE.getRolledLoopSize();
   LLVM_DEBUG(dbgs() << "Loop Size = " << LoopSize << "\n");
diff --git a/llvm/test/Transforms/LoopUnroll/debug.ll b/llvm/test/Transforms/LoopUnroll/debug.ll
index b68b7c2d10e94..dfbaee9a241e1 100644
--- a/llvm/test/Transforms/LoopUnroll/debug.ll
+++ b/llvm/test/Transforms/LoopUnroll/debug.ll
@@ -49,8 +49,7 @@ exit:
 }
 
 ; CHECK-LABEL:Loop Unroll: F[extended_convergence] Loop %for.body
-; CHECK-NEXT: Convergence prevents unrolling.
-; CHECK-NEXT: Loop not considered unrollable.
+; CHECK-NEXT: Not unrolling: contains convergent operations.
 
 declare void @convergent_func() convergent
 declare token @llvm.experimental.convergence.anchor()
@@ -76,8 +75,7 @@ exit:
 }
 
 ; CHECK-LABEL:Loop Unroll: F[noduplicate_prevents_unroll] Loop %for.body
-; CHECK-NEXT: Non-duplicatable blocks prevent unrolling.
-; CHECK-NEXT: Loop not considered unrollable.
+; CHECK-NEXT: Not unrolling: contains non-duplicatable instructions.
 
 declare void @noduplicate_func() noduplicate
 

>From c02bc5bf3750121748f31ee13b01cf665b096625 Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Wed, 18 Feb 2026 02:08:41 +0000
Subject: [PATCH 2/2] clang-format

---
 llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 296e6f5b7e57f..526ec193e0779 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -718,8 +718,8 @@ UnrollCostEstimator::UnrollCostEstimator(
 
 bool UnrollCostEstimator::canUnroll() const {
   if (Convergence == ConvergenceKind::ExtendedLoop) {
-    LLVM_DEBUG(
-        dbgs().indent(1) << "Not unrolling: contains convergent operations.\n");
+    LLVM_DEBUG(dbgs().indent(1)
+               << "Not unrolling: contains convergent operations.\n");
     return false;
   }
   if (!LoopSize.isValid()) {



More information about the llvm-commits mailing list