[llvm] [LV] -scalable-vectorization=preferred should not override UserVF=1 (PR #226948)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 02:58:45 PDT 2026


================
@@ -132,8 +132,11 @@ LoopVectorizeHints::LoopVectorizeHints(const Loop *L,
 
   // If the flag is set to force any use of scalable vectors, override the loop
   // hints.
-  if (ForceScalableVectorization.getValue() !=
-      LoopVectorizeHints::SK_Unspecified)
+  // However: A preference must not turn a UserVF of 1, used by e.g.
+  // vectorize(disable) pragmas, into a vscale x 1 VF.
+  if (ForceScalableVectorization.getValue() != SK_Unspecified &&
+      (Width.Value != 1 ||
----------------
paulwalker-arm wrote:

There's no clear path one way or the other but personally I think`-scalable-vectorization` is intended to maximise scalable vector coverage rather than being a user facing tuning option.  For that reason I see no reason why it shouldn't override the pragma.

Another data point is the pragma is rarely target agnostic (except perhaps to disable vectorisation) so I would be cautious about trusting it.  I've seen cases where it has been used to deliberately improve performance for whatever target the user was on when writing the code, which is where "we can ignore `vectorize_width(4)`" likely comes from.  However, that used to be the only way to use the pragma and so I don't really see how that is any more or less ignorable than `vectorize_width(4,fixed)`.

Perhaps it's worth assuming the compiler knows best but when a pragma is available we introduce a threshold the compiler cost have to better before its choice is preferred.  Even with this I think `-scalable-vectorization=always` should win.

https://github.com/llvm/llvm-project/pull/226948


More information about the llvm-commits mailing list