[llvm] [LV][NFC] Fix "vectorization is possible but not beneficial" message (PR #228024)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 04:52:49 PDT 2026
https://github.com/david-arm updated https://github.com/llvm/llvm-project/pull/228024
>From 674eac3d8bdc640a17d7ca26385a955540e41f29 Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Thu, 1 Oct 2026 10:26:08 +0000
Subject: [PATCH 1/2] [LV][NFC] Fix "vectorization is possible but not
beneficial" message
---
llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h | 5 +++++
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 7 ++++++-
.../Transforms/LoopVectorize/AArch64/early_exit_costs.ll | 2 +-
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index 733b8647a06e3..2a38d125e68d9 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -946,6 +946,11 @@ class LoopVectorizationPlanner {
/// Destroy the cost model.
void clearCostModel();
+ bool hasVectorPlan() const {
+ return any_of(
+ VPlans, [&](const VPlanPtr &Plan) { return !Plan->hasScalarVFOnly(); });
+ }
+
/// Build VPlans for the specified \p UserVF and \p UserIC if they are
/// non-zero or all applicable candidate VFs otherwise. If vectorization and
/// interleaving should be avoided up-front, no plans are generated.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 45edf702d7092..ffe94ecd075ef 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7985,7 +7985,12 @@ bool LoopVectorizePass::processLoop(Loop *L) {
std::pair<StringRef, std::string> VecDiagMsg, IntDiagMsg;
bool VectorizeLoop = true, InterleaveLoop = true;
if (VF.Width.isScalar()) {
- LLVM_DEBUG(dbgs() << "LV: Vectorization is possible but not beneficial.\n");
+ if (LVP.hasVectorPlan())
+ LLVM_DEBUG(dbgs() << "LV: Vectorization is not possible. Failed to "
+ "create any vector vplans.\n");
+ else
+ LLVM_DEBUG(
+ dbgs() << "LV: Vectorization is possible but not beneficial.\n");
VecDiagMsg = {
"VectorizationNotBeneficial",
"the cost-model indicates that vectorization is not beneficial"};
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll b/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll
index 8dd7ca8971724..1a33b66c3e577 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll
@@ -91,7 +91,7 @@ loop.end:
define i64 @vectorization_not_profitable_due_to_trunc(ptr dereferenceable(800) %src) {
; CHECK-LABEL: LV: Checking a loop in 'vectorization_not_profitable_due_to_trunc'
; CHECK: LV: Selecting VF: 1.
-; CHECK: LV: Vectorization is possible but not beneficial.
+; CHECK: LV: Vectorization is not possible. Failed to create any vector vplans.
entry:
br label %loop.header
>From 20f0e044ba06999c392dc486d716a27b52da964e Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Thu, 1 Oct 2026 11:51:58 +0000
Subject: [PATCH 2/2] Fix silly mistake with ordering
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 7 +++----
.../Transforms/LoopVectorize/AArch64/early_exit_costs.ll | 2 +-
.../Transforms/LoopVectorize/early_exit_store_legality.ll | 2 +-
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index ffe94ecd075ef..999185e631097 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5346,7 +5346,6 @@ void LoopVectorizationCostModel::collectValuesToIgnore() {
void LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) {
CM->collectValuesToIgnore();
Config.collectElementTypesForWidening(&CM->ValuesToIgnore);
-
FixedScalableVFPair MaxFactors = CM->computeMaxVF(UserVF, UserIC);
if (!MaxFactors) // Cases that should not to be vectorized nor interleaved.
return;
@@ -7986,11 +7985,11 @@ bool LoopVectorizePass::processLoop(Loop *L) {
bool VectorizeLoop = true, InterleaveLoop = true;
if (VF.Width.isScalar()) {
if (LVP.hasVectorPlan())
- LLVM_DEBUG(dbgs() << "LV: Vectorization is not possible. Failed to "
- "create any vector vplans.\n");
- else
LLVM_DEBUG(
dbgs() << "LV: Vectorization is possible but not beneficial.\n");
+ else
+ LLVM_DEBUG(dbgs() << "LV: Vectorization is not possible. Failed to "
+ "create any vector vplans.\n");
VecDiagMsg = {
"VectorizationNotBeneficial",
"the cost-model indicates that vectorization is not beneficial"};
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll b/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll
index 1a33b66c3e577..8dd7ca8971724 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/early_exit_costs.ll
@@ -91,7 +91,7 @@ loop.end:
define i64 @vectorization_not_profitable_due_to_trunc(ptr dereferenceable(800) %src) {
; CHECK-LABEL: LV: Checking a loop in 'vectorization_not_profitable_due_to_trunc'
; CHECK: LV: Selecting VF: 1.
-; CHECK: LV: Vectorization is not possible. Failed to create any vector vplans.
+; CHECK: LV: Vectorization is possible but not beneficial.
entry:
br label %loop.header
diff --git a/llvm/test/Transforms/LoopVectorize/early_exit_store_legality.ll b/llvm/test/Transforms/LoopVectorize/early_exit_store_legality.ll
index 644074a8ab965..dd3ee8fdb7700 100644
--- a/llvm/test/Transforms/LoopVectorize/early_exit_store_legality.ll
+++ b/llvm/test/Transforms/LoopVectorize/early_exit_store_legality.ll
@@ -895,7 +895,7 @@ define i32 @uncountable_exit_with_masked_ldst_separate_condition(ptr dereference
; CHECK-DEBUG-LABEL: LV: Checking a loop in 'uncountable_exit_with_masked_ldst_separate_condition'
; CHECK-DEBUG: LV: Loop passed LoopVectorizationLegality checks!
; CHECK-DEBUG: LV: Not vectorizing: Early exit loop with side effects contains unsupported conditional memory operations
-; CHECK-DEBUG: LV: Vectorization is possible but not beneficial.
+; CHECK-DEBUG: LV: Vectorization is not possible. Failed to create any vector vplans.
; CHECK-REMARK: foo.c:290:3: loop not vectorized: Early exit loop with side effects contains unsupported conditional memory operations
entry:
br label %for.body, !dbg !67
More information about the llvm-commits
mailing list