[llvm] [VPlan] Implement VPWidenCallRecipe::computeCost (NFCI). (PR #106047)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 02:04:04 PDT 2024
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/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.
>From 3fc1eeebf964c218be2576e11c1b5b96cbe65998 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Sun, 25 Aug 2024 22:13:54 +0100
Subject: [PATCH] [VPlan] Implement VPWidenCallRecipe::computeCost (NFCI).
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.
---
llvm/lib/Transforms/Vectorize/VPlan.h | 4 ++
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 40 +++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 36a1aa08654d5b..ea88fe6720d96f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -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());
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index fe1325f4163004..8bc0c6621fbde2 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -924,6 +924,46 @@ 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, TargetTransformInfo::TCK_RecipThroughput);
+}
+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void VPWidenCallRecipe::print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const {
More information about the llvm-commits
mailing list