[VPlan] Implement VPWidenCallRecipe::computeCost (NFCI). (#106047)

Implement cost computation for VPWidenCallRecipe. In some cases, targets
use argument info to compute intrinsic costs. If all operands of the
call are VPValues with an underlying IR value, use the IR values as
arguments.

PR: https://github.com/llvm/llvm-project/pull/106731
This commit is contained in:
Florian Hahn
2024-09-01 16:26:08 +01:00
committed by GitHub
parent affc0c64b6
commit 9ccf82543d
2 changed files with 43 additions and 0 deletions

View File

@@ -1565,6 +1565,10 @@ public:
/// Produce a widened version of the call instruction.
void execute(VPTransformState &State) override;
/// Return the cost of this VPWidenCallRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override;
Function *getCalledScalarFunction() const {
return cast<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue());
}

View File

@@ -925,6 +925,45 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
}
}
InstructionCost VPWidenCallRecipe::computeCost(ElementCount VF,
VPCostContext &Ctx) const {
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
if (Variant) {
return Ctx.TTI.getCallInstrCost(nullptr, Variant->getReturnType(),
Variant->getFunctionType()->params(),
CostKind);
}
FastMathFlags FMF;
// TODO: Manage flags via VPRecipeWithIRFlags.
if (auto *FPMO = dyn_cast_or_null<FPMathOperator>(getUnderlyingValue()))
FMF = FPMO->getFastMathFlags();
// Some backends analyze intrinsic arguments to determine cost. If all
// operands are VPValues with an underlying IR value, use the original IR
// values for cost computations.
SmallVector<const Value *> Arguments;
for (VPValue *Op : operands()) {
auto *V = Op->getUnderlyingValue();
if (!V) {
Arguments.clear();
break;
}
Arguments.push_back(V);
}
Type *RetTy =
ToVectorTy(Ctx.Types.inferScalarType(this->getVPSingleValue()), VF);
SmallVector<Type *> ParamTys;
for (unsigned I = 0; I != getNumOperands(); ++I)
ParamTys.push_back(
ToVectorTy(Ctx.Types.inferScalarType(getOperand(I)), VF));
IntrinsicCostAttributes CostAttrs(VectorIntrinsicID, RetTy, Arguments,
ParamTys, FMF);
return Ctx.TTI.getIntrinsicInstrCost(CostAttrs, CostKind);
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void VPWidenCallRecipe::print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const {