Skip to content

Commit d1360f6

Browse files
committed
[VPlan] Implment VPReductionRecipe::computeCost(). NFC
Implementation of `computeCost()` function for `VPReductionRecipe`.
1 parent 57b12e8 commit d1360f6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,10 @@ class VPReductionRecipe : public VPSingleDefRecipe {
23472347
/// Generate the reduction in the loop
23482348
void execute(VPTransformState &State) override;
23492349

2350+
/// Return the cost of VPReductionRecipe.
2351+
InstructionCost computeCost(ElementCount VF,
2352+
VPCostContext &Ctx) const override;
2353+
23502354
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
23512355
/// Print the recipe.
23522356
void print(raw_ostream &O, const Twine &Indent,

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,30 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) {
19991999
State.set(this, NewRed, 0, /*IsScalar*/ true);
20002000
}
20012001

2002+
InstructionCost VPReductionRecipe::computeCost(ElementCount VF,
2003+
VPCostContext &Ctx) const {
2004+
RecurKind RdxKind = RdxDesc.getRecurrenceKind();
2005+
Type *ElementTy = RdxDesc.getRecurrenceType();
2006+
auto *VectorTy = dyn_cast<VectorType>(ToVectorTy(ElementTy, VF));
2007+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
2008+
unsigned Opcode = RdxDesc.getOpcode();
2009+
2010+
if (VectorTy == nullptr)
2011+
return InstructionCost::getInvalid();
2012+
2013+
// Cost = Reduction cost + BinOp cost
2014+
InstructionCost Cost =
2015+
Ctx.TTI.getArithmeticInstrCost(Opcode, ElementTy, CostKind);
2016+
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RdxKind)) {
2017+
Intrinsic::ID Id = getMinMaxReductionIntrinsicOp(RdxKind);
2018+
return Cost + Ctx.TTI.getMinMaxReductionCost(
2019+
Id, VectorTy, RdxDesc.getFastMathFlags(), CostKind);
2020+
}
2021+
2022+
return Cost + Ctx.TTI.getArithmeticReductionCost(
2023+
Opcode, VectorTy, RdxDesc.getFastMathFlags(), CostKind);
2024+
}
2025+
20022026
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
20032027
void VPReductionRecipe::print(raw_ostream &O, const Twine &Indent,
20042028
VPSlotTracker &SlotTracker) const {

0 commit comments

Comments
 (0)