[llvm] [LoopVectorizer] Add a -force-vscale-for-tuning override option. (PR #156916)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 4 09:03:23 PDT 2025
https://github.com/davemgreen created https://github.com/llvm/llvm-project/pull/156916
It can be useful for debugging and tuning to be able to alter the VScaleForTuning. This adds a quick option to the vectorizer for it. It overrides the VScaleForTuning in the vectorizer even when the vscale is known, as the options is a "force".
>From 23ced2ef5e00e7bc84edaef834e72210455665fc Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Thu, 4 Sep 2025 16:53:50 +0100
Subject: [PATCH] [LoopVectorizer] Add a -force-vscale-for-tuning override
option.
It can be useful for debugging and tuning to be able to alter the
VScaleForTuning. This adds a quick option to the vectorizer for it
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 9 +++++++++
.../AArch64/scalable-vectorization-cost-tuning.ll | 4 ++++
2 files changed, 13 insertions(+)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 3fbeef1211954..68019b7b58413 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -303,6 +303,10 @@ static cl::opt<bool> ForceTargetSupportsScalableVectors(
"Pretend that scalable vectors are supported, even if the target does "
"not support them. This flag should only be used for testing."));
+static cl::opt<unsigned> VScaleForTuningOpt(
+ "force-vscale-for-tuning", cl::Hidden,
+ cl::desc("Force a vscale for tuning factor in the loop vectorizer"));
+
static cl::opt<unsigned> SmallLoopCost(
"small-loop-cost", cl::init(20), cl::Hidden,
cl::desc(
@@ -1473,6 +1477,11 @@ class LoopVectorizationCostModel {
/// vscale_range.min == vscale_range.max then return vscale_range.max, else
/// return the value returned by the corresponding TTI method.
void initializeVScaleForTuning() {
+ if (VScaleForTuningOpt.getNumOccurrences()) {
+ VScaleForTuning = VScaleForTuningOpt;
+ return;
+ }
+
const Function *Fn = TheLoop->getHeader()->getParent();
if (Fn->hasFnAttribute(Attribute::VScaleRange)) {
auto Attr = Fn->getFnAttribute(Attribute::VScaleRange);
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization-cost-tuning.ll b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization-cost-tuning.ll
index c4aee69db70b3..16d3786681ffa 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization-cost-tuning.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization-cost-tuning.ll
@@ -7,6 +7,10 @@
; RUN: -force-target-instruction-cost=1 -passes=loop-vectorize -S -debug-only=loop-vectorize --disable-output < %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=VSCALEFORTUNING1
+; RUN: opt -mtriple=aarch64 -mattr=+sve -mcpu=generic -force-vscale-for-tuning=2 \
+; RUN: -force-target-instruction-cost=1 -passes=loop-vectorize -S -debug-only=loop-vectorize --disable-output < %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=VSCALEFORTUNING2
+
; RUN: opt -mtriple=aarch64 -mcpu=neoverse-v1 \
; RUN: -force-target-instruction-cost=1 -passes=loop-vectorize -S -debug-only=loop-vectorize --disable-output < %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=VSCALEFORTUNING2
More information about the llvm-commits
mailing list