Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,10 @@ class VPWidenCallRecipe : public VPSingleDefRecipe {
/// 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());
}
Expand Down
39 changes: 39 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading