[llvm] [LoopUnrollPass] Don't use clang specific syntax in optimization remarks (PR #182430)

Justin Fargnoli via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 18:58:42 PST 2026


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

>From 5d3e306a5efd5c5112a98448ed3c68de3b0b5109 Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Fri, 20 Feb 2026 03:34:16 +0000
Subject: [PATCH 1/3] [LoopUnroll] Use generic unroll terminology in
 diagnostics

Replace clang-specific pragma syntax (unroll(full), unroll(enable),
unroll_count) with generic LLVM terminology in ORE remarks and the
command-line option description. This makes the diagnostics accurate
for all frontends, not just clang.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply at anthropic.com>
---
 llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 3e2ed34b3c67d..89f871ca19529 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -142,8 +142,8 @@ static cl::opt<unsigned> UnrollMaxUpperBound(
 
 static cl::opt<unsigned> PragmaUnrollThreshold(
     "pragma-unroll-threshold", cl::init(16 * 1024), cl::Hidden,
-    cl::desc("Unrolled size limit for loops with an unroll(full) or "
-             "unroll_count pragma."));
+    cl::desc("Unrolled size limit for loops with unroll metadata "
+             "(full, enable, or count)."));
 
 static cl::opt<unsigned> FlatLoopTripCountThreshold(
     "flat-loop-tripcount-threshold", cl::init(5), cl::Hidden,
@@ -1060,9 +1060,8 @@ bool llvm::computeUnrollCount(
             return OptimizationRemarkMissed(DEBUG_TYPE,
                                             "UnrollAsDirectedTooLarge",
                                             L->getStartLoc(), L->getHeader())
-                   << "Unable to unroll loop as directed by unroll(enable) "
-                      "pragma "
-                      "because unrolled size is too large.";
+                   << "unable to unroll loop as directed by enable unroll "
+                      "pragma because unrolled size is too large";
           });
       }
     }
@@ -1075,9 +1074,8 @@ bool llvm::computeUnrollCount(
       return OptimizationRemarkMissed(
                  DEBUG_TYPE, "CantFullUnrollAsDirectedRuntimeTripCount",
                  L->getStartLoc(), L->getHeader())
-             << "Unable to fully unroll loop as directed by unroll(full) "
-                "pragma "
-                "because loop has a runtime trip count.";
+             << "unable to fully unroll loop as directed by full unroll "
+                "pragma because loop has a runtime trip count";
     });
 
   // 7th priority is runtime unrolling.

>From 56e183ac509359ac72acb14d30e5f0205dcee57a Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Wed, 4 Mar 2026 00:30:30 +0000
Subject: [PATCH 2/3] Use metadata names in optimization remarks

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

diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 89f871ca19529..6833f1517b23f 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -1048,9 +1048,8 @@ bool llvm::computeUnrollCount(
         return OptimizationRemarkMissed(DEBUG_TYPE,
                                         "FullUnrollAsDirectedTooLarge",
                                         L->getStartLoc(), L->getHeader())
-               << "Unable to fully unroll loop as directed by unroll pragma "
-                  "because "
-                  "unrolled size is too large.";
+               << "unable to fully unroll loop as directed by unroll metadata "
+                  "because unrolled size is too large";
       });
 
     if (UP.PartialThreshold != NoThreshold) {
@@ -1060,8 +1059,9 @@ bool llvm::computeUnrollCount(
             return OptimizationRemarkMissed(DEBUG_TYPE,
                                             "UnrollAsDirectedTooLarge",
                                             L->getStartLoc(), L->getHeader())
-                   << "unable to unroll loop as directed by enable unroll "
-                      "pragma because unrolled size is too large";
+                   << "unable to unroll loop as directed by "
+                      "llvm.loop.unroll.enable metadata because unrolled size "
+                      "is too large";
           });
       }
     }
@@ -1074,8 +1074,9 @@ bool llvm::computeUnrollCount(
       return OptimizationRemarkMissed(
                  DEBUG_TYPE, "CantFullUnrollAsDirectedRuntimeTripCount",
                  L->getStartLoc(), L->getHeader())
-             << "unable to fully unroll loop as directed by full unroll "
-                "pragma because loop has a runtime trip count";
+             << "unable to fully unroll loop as directed by "
+                "llvm.loop.unroll.full metadata because loop has a runtime "
+                "trip count";
     });
 
   // 7th priority is runtime unrolling.
@@ -1140,11 +1141,10 @@ bool llvm::computeUnrollCount(
                                         "DifferentUnrollCountFromDirected",
                                         L->getStartLoc(), L->getHeader())
                << "Unable to unroll loop the number of times directed by "
-                  "unroll_count pragma because remainder loop is restricted "
-                  "(that could architecture specific or because the loop "
-                  "contains a convergent instruction) and so must have an "
-                  "unroll "
-                  "count that divides the loop trip multiple of "
+                  "llvm.loop.unroll.count metadata because remainder loop is "
+                  "restricted (that could architecture specific or because the "
+                  "loop contains a convergent instruction) and so must have an "
+                  "unroll count that divides the loop trip multiple of "
                << NV("TripMultiple", TripMultiple) << ".  Unrolling instead "
                << NV("UnrollCount", UP.Count) << " time(s).";
       });

>From 7166d672da925154c523165b24b52311189049e2 Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Wed, 4 Mar 2026 01:35:06 +0000
Subject: [PATCH 3/3] Address review comments

---
 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 6833f1517b23f..8dd3c10c5d596 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -1126,7 +1126,7 @@ bool llvm::computeUnrollCount(
     while (UP.Count != 0 && TripMultiple % UP.Count != 0)
       UP.Count >>= 1;
     LLVM_DEBUG(dbgs().indent(2)
-               << "Remainder loop is restricted (that could architecture "
+               << "Remainder loop is restricted (that could be architecture "
                   "specific or because the loop contains a convergent "
                   "instruction), so unroll count must divide the trip "
                   "multiple, "
@@ -1142,7 +1142,7 @@ bool llvm::computeUnrollCount(
                                         L->getStartLoc(), L->getHeader())
                << "Unable to unroll loop the number of times directed by "
                   "llvm.loop.unroll.count metadata because remainder loop is "
-                  "restricted (that could architecture specific or because the "
+                  "restricted (that could be architecture specific or because the "
                   "loop contains a convergent instruction) and so must have an "
                   "unroll count that divides the loop trip multiple of "
                << NV("TripMultiple", TripMultiple) << ".  Unrolling instead "



More information about the llvm-commits mailing list