@@ -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)
20032027void VPReductionRecipe::print (raw_ostream &O, const Twine &Indent,
20042028 VPSlotTracker &SlotTracker) const {
0 commit comments