[llvm] [VPlan] Implement VPWidenCallRecipe::computeCost (NFCI). (PR #106047)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 02:04:36 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Florian Hahn (fhahn)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/106047.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+4)
- (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+40)
``````````diff
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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/106047
More information about the llvm-commits
mailing list