[llvm] [LV] Add a statistic for early exit vectorization (PR #145730)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 09:01:17 PDT 2025


https://github.com/annamthomas updated https://github.com/llvm/llvm-project/pull/145730

>From c56cdcd6f6d30b01ac85187e57d16c987219809f Mon Sep 17 00:00:00 2001
From: Anna Thomas <anna at azul.com>
Date: Wed, 25 Jun 2025 11:44:56 -0400
Subject: [PATCH] [LV] Add a statistic for early exit vectorization

We currently do not vectorize the epilog loops with early-exits, but the
stats are updated there as well for completeness.
---
 llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 5eda2003920e6..4f365b9f990bf 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -175,6 +175,8 @@ const char LLVMLoopVectorizeFollowupEpilogue[] =
 STATISTIC(LoopsVectorized, "Number of loops vectorized");
 STATISTIC(LoopsAnalyzed, "Number of loops analyzed for vectorization");
 STATISTIC(LoopsEpilogueVectorized, "Number of epilogues vectorized");
+STATISTIC(LoopsEarlyExitVectorized, "Number of early exit loops vectorized"); 
+
 
 static cl::opt<bool> EnableEpilogueVectorization(
     "enable-epilogue-vectorization", cl::init(true), cl::Hidden,
@@ -10291,6 +10293,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
         auto ExpandedSCEVs = LVP.executePlan(EPI.MainLoopVF, EPI.MainLoopUF,
                                              *BestMainPlan, MainILV, DT, false);
         ++LoopsVectorized;
+        // TODO: Currently unsupported for early exits.
+        if (BestPlan.hasEarlyExit())
+          ++LoopsEarlyExitVectorized;
 
         // Second pass vectorizes the epilogue and adjusts the control flow
         // edges from the first pass.
@@ -10319,6 +10324,10 @@ bool LoopVectorizePass::processLoop(Loop *L) {
           Inc->setIncomingValueForBlock(BypassBlock, V);
         }
         ++LoopsEpilogueVectorized;
+        // TODO: Currently unsupported for early exits.
+        if (BestEpiPlan.hasEarlyExit())
+          ++LoopsEarlyExitVectorized;
+
 
         if (!Checks.hasChecks())
           DisableRuntimeUnroll = true;
@@ -10328,6 +10337,8 @@ bool LoopVectorizePass::processLoop(Loop *L) {
                                Checks, BestPlan);
         LVP.executePlan(VF.Width, IC, BestPlan, LB, DT, false);
         ++LoopsVectorized;
+        if (BestPlan.hasEarlyExit())
+          ++LoopsEarlyExitVectorized;
 
         // Add metadata to disable runtime unrolling a scalar loop when there
         // are no runtime checks about strides and memory. A scalar loop that is



More information about the llvm-commits mailing list