[llvm] [LV] Don't calculate scalar costs for scalable VFs in setVectorizedCallDecision (PR #152713)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 19 01:50:43 PDT 2025


================
@@ -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.
----------------
fhahn wrote:

Perhaps we should assert here that the cost is actually invalid, to make sure the expectation isn't broken by future TTI changes?

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


More information about the llvm-commits mailing list