[llvm] 9ccf825 - [VPlan] Implement VPWidenCallRecipe::computeCost (NFCI). (#106047)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 1 08:26:12 PDT 2024
Author: Florian Hahn
Date: 2024-09-01T16:26:08+01:00
New Revision: 9ccf82543d509bb5a0f5d0551fc4d6c1913b9a9b
URL: https://github.com/llvm/llvm-project/commit/9ccf82543d509bb5a0f5d0551fc4d6c1913b9a9b
DIFF: https://github.com/llvm/llvm-project/commit/9ccf82543d509bb5a0f5d0551fc4d6c1913b9a9b.diff
LOG: [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
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index e7ea5cb23b90d3..bd71dbffa929e7 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 c9cee652d2d326..3d08e3cefbf633 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -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 {
More information about the llvm-commits
mailing list