[llvm] [LoopVectorize] Add LoopDepth argument to Vectorized remark[LoopVectorize] Add LoopDepth argument to Vectorized remark (PR #200973)

Kushal Gowda C via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 16:59:18 PDT 2026


https://github.com/kushalgowdac created https://github.com/llvm/llvm-project/pull/200973

Add a structured `LoopDepth` named argument to the optimization remark
emitted by `reportVectorization()` when a loop is successfully vectorized.

This gives downstream remark consumers (opt-viewer, build systems, IDE
integrations) access to loop nesting depth alongside the existing
`VectorizationFactor` and `InterleaveCount` fields. New named arguments
are additive and do not break existing remark consumers.

Also fix a pre-existing typo: `Treshold` → `Threshold` in the SLP
vectorizer's `NotBeneficial` remark argument name (visible in YAML
remark output).

Files changed:
- `llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp` — adds `LoopDepth` NV argument
- `llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp` — fixes `Treshold` typo
- `llvm/test/Transforms/LoopVectorize/loop-depth-remark.ll` — FileCheck test for new field

>From 2153fd01285e64fa66a16797cdd3be453d79ed52 Mon Sep 17 00:00:00 2001
From: Kushal Gowda C <kushalgowdac.official at gmail.com>
Date: Mon, 1 Jun 2026 21:59:00 +0530
Subject: [PATCH] [LoopVectorize] Add LoopDepth argument to Vectorized remark

Add a structured LoopDepth named argument to the optimization remark
emitted by reportVectorization() when a loop is successfully vectorized.
This gives downstream remark consumers (e.g. opt-viewer, build systems)
access to loop nesting depth alongside the existing VectorizationFactor
and InterleaveCount fields.

Also fix a pre-existing typo: Treshold -> Threshold in the SLP
vectorizer's NotBeneficial remark argument name.
---
 .../Vectorize/LoopVectorizationPlanner.cpp    |  3 ++-
 .../Transforms/Vectorize/SLPVectorizer.cpp    |  2 +-
 .../LoopVectorize/loop-depth-remark.ll        | 27 +++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/Transforms/LoopVectorize/loop-depth-remark.ll

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp
index c922ca7d32dbf..347fb9c0ba62c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp
@@ -130,7 +130,8 @@ void LoopVectorizationUtils::reportVectorization(OptimizationRemarkEmitter *ORE,
                               TheLoop->getHeader())
            << "vectorized " << LoopType << "loop (vectorization width: "
            << ore::NV("VectorizationFactor", VFWidth)
-           << ", interleaved count: " << ore::NV("InterleaveCount", IC) << ")";
+           << ", interleaved count: " << ore::NV("InterleaveCount", IC)
+           << ore::NV("LoopDepth", TheLoop->getLoopDepth()) << ")";
   });
 }
 
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 362087c950b7b..9cf7882fa031d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -28411,7 +28411,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
       return OptimizationRemarkMissed(SV_NAME, "NotBeneficial", I0)
              << "List vectorization was possible but not beneficial with cost "
              << ore::NV("Cost", MinCost) << " >= "
-             << ore::NV("Treshold", -SLPCostThreshold);
+             << ore::NV("Threshold", -SLPCostThreshold);
     });
   } else if (!Changed) {
     R.getORE()->emit([&]() {
diff --git a/llvm/test/Transforms/LoopVectorize/loop-depth-remark.ll b/llvm/test/Transforms/LoopVectorize/loop-depth-remark.ll
new file mode 100644
index 0000000000000..fbd00c01bc125
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/loop-depth-remark.ll
@@ -0,0 +1,27 @@
+; RUN: opt -disable-output -passes=loop-vectorize -pass-remarks=loop-vectorize 2>&1 %s | FileCheck %s
+
+; CHECK: remark: {{.*}} vectorized loop
+; CHECK-SAME: VectorizationFactor
+; CHECK-SAME: InterleaveCount
+; CHECK-SAME: LoopDepth
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @add_arrays(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %n) {
+entry:
+  br label %loop
+loop:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+  %gep_a = getelementptr inbounds float, ptr %a, i64 %iv
+  %gep_b = getelementptr inbounds float, ptr %b, i64 %iv
+  %gep_c = getelementptr inbounds float, ptr %c, i64 %iv
+  %load_b = load float, ptr %gep_b, align 4
+  %load_c = load float, ptr %gep_c, align 4
+  %add = fadd float %load_b, %load_c
+  store float %add, ptr %gep_a, align 4
+  %iv.next = add nuw nsw i64 %iv, 1
+  %exitcond = icmp eq i64 %iv.next, %n
+  br i1 %exitcond, label %exit, label %loop
+exit:
+  ret void
+}



More information about the llvm-commits mailing list