[llvm] 3ba18a6 - [LoopUnroll] Fix misleading runtime unroll debug message (#190709)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 09:28:08 PDT 2026


Author: Justin Fargnoli
Date: 2026-04-14T16:28:02Z
New Revision: 3ba18a675bf8bbfc4d52427e895a518a5685f19b

URL: https://github.com/llvm/llvm-project/commit/3ba18a675bf8bbfc4d52427e895a518a5685f19b
DIFF: https://github.com/llvm/llvm-project/commit/3ba18a675bf8bbfc4d52427e895a518a5685f19b.diff

LOG: [LoopUnroll] Fix misleading runtime unroll debug message (#190709)

Avoid the confusing `Runtime unrolling with count: 0` `LLVM_DEBUG`
statement.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
    llvm/test/Transforms/LoopUnroll/debug.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 955c7aa99f301..885ae1f6dc02a 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -1231,10 +1231,11 @@ void llvm::computeUnrollCount(Loop *L, const TargetTransformInfo &TTI,
   if (MaxTripCount && UP.Count > MaxTripCount)
     UP.Count = MaxTripCount;
 
-  LLVM_DEBUG(dbgs().indent(2)
-             << "Runtime unrolling with count: " << UP.Count << "\n");
   if (UP.Count < 2)
     UP.Count = 0;
+  else
+    LLVM_DEBUG(dbgs().indent(2)
+               << "Runtime unrolling with count: " << UP.Count << "\n");
   return;
 }
 

diff  --git a/llvm/test/Transforms/LoopUnroll/debug.ll b/llvm/test/Transforms/LoopUnroll/debug.ll
index fd84eeeb3d457..f3bcdc52db073 100644
--- a/llvm/test/Transforms/LoopUnroll/debug.ll
+++ b/llvm/test/Transforms/LoopUnroll/debug.ll
@@ -7,6 +7,7 @@
 ; RUN: opt -disable-output -passes=loop-unroll -debug-only=loop-unroll -unroll-full-max-count=2 < %s 2>&1 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=MAX-COUNT
 ; RUN: opt -disable-output -passes=loop-unroll -debug-only=loop-unroll -unroll-allow-partial -unroll-partial-threshold=4 < %s 2>&1 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=PARTIAL-NOPROFIT
 ; RUN: opt -disable-output -passes=loop-unroll -debug-only=loop-unroll -unroll-allow-remainder=false < %s 2>&1 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=PRAGMA-NOREMAINDER
+; RUN: opt -disable-output -passes=loop-unroll -debug-only=loop-unroll -unroll-partial-threshold=9 < %s 2>&1 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=RUNTIME-NOPROFIT
 
 ; REQUIRES: asserts
 
@@ -567,6 +568,23 @@ exit:
 ; CHECK-NEXT:  Runtime unrolling with count: 8
 ; CHECK-NEXT:  Exiting block %for.body: TripCount=0, TripMultiple=1, BreakoutTrip=1
 ; CHECK:UNROLLING loop %for.body by 8 with run-time trip count!
+;
+; With a low partial threshold, the runtime unroll count is reduced below 2
+; and no unrolling occurs. Verify we don't print a misleading
+; "Runtime unrolling with count" message.
+;
+; RUNTIME-NOPROFIT-LABEL:Loop Unroll: F[runtime_unroll_simple] Loop %for.body (depth=1)
+; RUNTIME-NOPROFIT-NEXT:Loop Size = 6
+; RUNTIME-NOPROFIT-NEXT: Computing unroll count: TripCount=0, MaxTripCount=2147483647, TripMultiple=1
+; RUNTIME-NOPROFIT-NEXT: Explicit unroll requested: pragma-enable
+; RUNTIME-NOPROFIT-NEXT: Trying pragma unroll...
+; RUNTIME-NOPROFIT-NEXT: Trying full unroll...
+; RUNTIME-NOPROFIT-NEXT: Trying upper-bound unroll...
+; RUNTIME-NOPROFIT-NEXT: Trying loop peeling...
+; RUNTIME-NOPROFIT-NEXT: Trying partial unroll...
+; RUNTIME-NOPROFIT-NEXT: Trying runtime unroll...
+; RUNTIME-NOPROFIT-NOT:  Runtime unrolling with count:
+; RUNTIME-NOPROFIT: Not unrolling: no viable strategy found.
 
 define i32 @runtime_unroll_simple(ptr %A, i32 %n) {
 entry:


        


More information about the llvm-commits mailing list