[llvm-branch-commits] [llvm] [LV] -scalable-vectorization=preferred should not override UserVF=1 (PR #226948)
Gaƫtan Bossu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 12 05:13:48 PDT 2026
https://github.com/gbossu updated https://github.com/llvm/llvm-project/pull/226948
>From fbfacd9f96eaf8f58fad3c06125f875d1c35ba01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Bossu?= <gaetan.bossu at arm.com>
Date: Wed, 7 Oct 2026 14:33:07 +0000
Subject: [PATCH 1/2] -scalable-vectorization=on should not override !loop MD
---
.../Transforms/Vectorize/LoopVectorizationLegality.cpp | 9 +++++++--
.../LoopVectorize/pragma-disable-with-scalable-prefer.ll | 8 +++-----
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 69ce0cb8a145f..9edd25e48fb08 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -118,8 +118,9 @@ LoopVectorizeHints::LoopVectorizeHints(const Loop *L,
[TTI](ScalableForceKind ForceScalableHint,
ScalableForceKind ForceScalableOpt, unsigned ForceWidth,
ElementCount ForceWidthOpt) -> ScalableForceKind {
- // -scalable-vectorization=(always|off|on) has the highest precedence.
- if (ForceScalableOpt != SK_Unspecified)
+ // -scalable-vectorization=(always|off) has the highest precedence.
+ if (ForceScalableOpt == SK_AlwaysScalable ||
+ ForceScalableOpt == SK_FixedWidthOnly)
return ForceScalableOpt;
// Then, consider loop hints.
@@ -128,6 +129,10 @@ LoopVectorizeHints::LoopVectorizeHints(const Loop *L,
ForceScalableHint == SK_FixedWidthOnly)
return ForceScalableHint;
+ // Then, -scalable-vectorization=on.
+ if (ForceScalableOpt == SK_PreferScalable)
+ return SK_PreferScalable;
+
// Then, infer scalability from a preferred VF.
assert(ForceScalableOpt == SK_Unspecified);
if (ForceWidthOpt.isScalable())
diff --git a/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-prefer.ll b/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-prefer.ll
index 70b579f999c61..b03c205b42c89 100644
--- a/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-prefer.ll
+++ b/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-prefer.ll
@@ -3,12 +3,10 @@
; Clang lowers "#pragma clang loop vectorize(disable) interleave_count(1)" to
; width 1, scalable.disable and interleave count 1.
-; Currently, -scalable-vectorization=preferred overrides the user VF=1 and
-; re-enables vectorisation, with VF = vscale x 1.
+; -scalable-vectorization=preferred must not override the user VF=1 and
+; re-enable vectorisation.
; CHECK-LABEL: define void @repro(
-; CHECK: vector.body:
-; CHECK: load <vscale x 1 x i8>
-; CHECK: store <vscale x 1 x i8>
+; CHECK-NOT: vector.body:
define void @repro(ptr %out, ptr %in, i32 %tc) {
entry:
>From c55162c1e8f3027cda9889d6f8e8a7ddd059b9cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Bossu?= <gaetan.bossu at arm.com>
Date: Mon, 12 Oct 2026 12:12:35 +0000
Subject: [PATCH 2/2] Have pragmas take precedence over -scalable-vectorization
---
.../Vectorize/LoopVectorizationLegality.cpp | 15 +++++----------
.../pragma-disable-with-scalable-always.ll | 8 +++-----
.../pragma-fixed-width-with-scalable-always.ll | 6 +++---
.../pragma-scalable-width-with-scalable-off.ll | 6 ++++--
4 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 9edd25e48fb08..3e24c07868909 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -59,7 +59,7 @@ static cl::opt<LoopVectorizeHints::ScalableForceKind>
"scalable-vectorization", cl::init(LoopVectorizeHints::SK_Unspecified),
cl::Hidden,
cl::desc("Control whether the compiler can use scalable vectors to "
- "vectorize a loop"),
+ "vectorize a loop. This does not override loop pragmas."),
cl::values(
clEnumValN(LoopVectorizeHints::SK_FixedWidthOnly, "off",
"Scalable vectorization is disabled."),
@@ -118,20 +118,15 @@ LoopVectorizeHints::LoopVectorizeHints(const Loop *L,
[TTI](ScalableForceKind ForceScalableHint,
ScalableForceKind ForceScalableOpt, unsigned ForceWidth,
ElementCount ForceWidthOpt) -> ScalableForceKind {
- // -scalable-vectorization=(always|off) has the highest precedence.
- if (ForceScalableOpt == SK_AlwaysScalable ||
- ForceScalableOpt == SK_FixedWidthOnly)
- return ForceScalableOpt;
-
- // Then, consider loop hints.
+ // Loop hints have the highest precedence.
assert(ForceScalableHint != SK_AlwaysScalable && "Unexpected loop hint.");
if (ForceScalableHint == SK_PreferScalable ||
ForceScalableHint == SK_FixedWidthOnly)
return ForceScalableHint;
- // Then, -scalable-vectorization=on.
- if (ForceScalableOpt == SK_PreferScalable)
- return SK_PreferScalable;
+ // Then, consider -scalable-vectorization=(always|off|on).
+ if (ForceScalableOpt != SK_Unspecified)
+ return ForceScalableOpt;
// Then, infer scalability from a preferred VF.
assert(ForceScalableOpt == SK_Unspecified);
diff --git a/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-always.ll b/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-always.ll
index 33e95f32d48a6..4cc2e32666ca6 100644
--- a/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-always.ll
+++ b/llvm/test/Transforms/LoopVectorize/pragma-disable-with-scalable-always.ll
@@ -3,12 +3,10 @@
; Clang lowers "#pragma clang loop vectorize(disable) interleave_count(1)" to
; width 1, scalable.disable and interleave count 1.
-; Currently, -scalable-vectorization=always overrides the user VF=1 and
-; re-enables vectorisation, with VF = vscale x 1.
+; -scalable-vectorization=always must not override the user VF=1 and
+; re-enable vectorisation.
; CHECK-LABEL: define void @repro(
-; CHECK: vector.body:
-; CHECK: load <vscale x 1 x i8>
-; CHECK: store <vscale x 1 x i8>
+; CHECK-NOT: vector.body:
define void @repro(ptr %out, ptr %in, i32 %tc) {
entry:
diff --git a/llvm/test/Transforms/LoopVectorize/pragma-fixed-width-with-scalable-always.ll b/llvm/test/Transforms/LoopVectorize/pragma-fixed-width-with-scalable-always.ll
index 8e49abc6380ea..9a7ed5db0e394 100644
--- a/llvm/test/Transforms/LoopVectorize/pragma-fixed-width-with-scalable-always.ll
+++ b/llvm/test/Transforms/LoopVectorize/pragma-fixed-width-with-scalable-always.ll
@@ -2,12 +2,12 @@
;
; Clang lowers "#pragma clang loop vectorize_width(4)" and
; "interleave_count(1)" to width 4, scalable.disable, and interleave count 1.
-; -scalable-vectorization=always overrides scalable.disable and forces vectorization with VF=vscale x 4.
+; -scalable-vectorization=always must not override scalable.disable and force a scalable VF.
;
; CHECK-LABEL: define void @repro(
; CHECK: vector.body:
-; CHECK: load <vscale x 4 x i8>
-; CHECK: store <vscale x 4 x i8>
+; CHECK: load <4 x i8>
+; CHECK: store <4 x i8>
define void @repro(ptr %out, ptr %in, i32 %tc) {
entry:
diff --git a/llvm/test/Transforms/LoopVectorize/pragma-scalable-width-with-scalable-off.ll b/llvm/test/Transforms/LoopVectorize/pragma-scalable-width-with-scalable-off.ll
index 18c94449c8240..7be598bd03584 100644
--- a/llvm/test/Transforms/LoopVectorize/pragma-scalable-width-with-scalable-off.ll
+++ b/llvm/test/Transforms/LoopVectorize/pragma-scalable-width-with-scalable-off.ll
@@ -2,10 +2,12 @@
;
; Clang lowers "#pragma clang loop vectorize_width(1, scalable)" and
; "interleave_count(1)" to width 1, scalable.enable, and interleave count 1.
-; -scalable-vectorization=off overrides scalable.enable and disables vectorisation
+; -scalable-vectorization=off must not override scalable.enable and disable vectorization.
;
; CHECK-LABEL: define void @repro(
-; CHECK-NOT: vector.body:
+; CHECK: vector.body:
+; CHECK: load <vscale x 1 x i8>
+; CHECK: store <vscale x 1 x i8>
define void @repro(ptr %out, ptr %in, i32 %tc) {
entry:
More information about the llvm-branch-commits
mailing list