[llvm] [LV] Don't calculate scalar costs for scalable VFs in setVectorizedCallDecision (PR #152713)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 8 06:30:30 PDT 2025
https://github.com/david-arm created https://github.com/llvm/llvm-project/pull/152713
In setVectorizedCallDecision we attempt to calculate the scalar costs for vectorisation calls, even for scalable VFs where we already know the answer is Invalid. We can avoid doing unnecessary work by skipping this completely for scalable vectors.
>From a03ffd008a18475aba11f48781472841067722b5 Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Fri, 8 Aug 2025 13:28:47 +0000
Subject: [PATCH] [LV] Don't calculate scalar costs for scalable VFs in
setVectorizedCallDecision
In setVectorizedCallDecision we attempt to calculate the scalar
costs for vectorisation calls, even for scalable VFs where we
already know the answer is Invalid. We can avoid doing unnecessary
work by skipping this completely for scalable vectors.
---
.../Transforms/Vectorize/LoopVectorize.cpp | 20 ++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index be00fd6a416e5..cfb0c78400331 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5888,14 +5888,20 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) {
// assumed to be vectors, so we need to extract individual elements from
// there, execute VF scalar calls, and then gather the result into the
// vector return value.
- InstructionCost ScalarCallCost =
- TTI.getCallInstrCost(ScalarFunc, ScalarRetTy, ScalarTys, CostKind);
-
- // Compute costs of unpacking argument values for the scalar calls and
- // packing the return values to a vector.
- InstructionCost ScalarizationCost = getScalarizationOverhead(CI, VF);
+ if (VF.isFixed()) {
+ InstructionCost ScalarCallCost =
+ TTI.getCallInstrCost(ScalarFunc, ScalarRetTy, ScalarTys, CostKind);
+
+ // Compute costs of unpacking argument values for the scalar calls and
+ // packing the return values to a vector.
+ InstructionCost ScalarizationCost = getScalarizationOverhead(CI, VF);
+ ScalarCost = ScalarCallCost * VF.getKnownMinValue() + ScalarizationCost;
+ } else {
+ // There is no point attempting to calculate the scalar cost for a
+ // scalable VF as we know it will be Invalid.
+ ScalarCost = InstructionCost::getInvalid();
+ }
- ScalarCost = ScalarCallCost * VF.getKnownMinValue() + ScalarizationCost;
// Honor ForcedScalars and UniformAfterVectorization decisions.
// TODO: For calls, it might still be more profitable to widen. Use
// VPlan-based cost model to compare different options.
More information about the llvm-commits
mailing list