[LV] Don't calculate scalar costs for scalable VFs in setVectorizedCallDecision (#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.
This commit is contained in:
David Sherwood 2025-08-20 15:00:31 +01:00 committed by GitHub
parent 694a488708
commit e172110d12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5832,14 +5832,22 @@ 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);
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);
// 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.
assert(!getScalarizationOverhead(CI, VF).isValid() &&
"Unexpected valid cost for scalarizing scalable vectors");
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.