[llvm] [VPlan] Implement VPReductionRecipe::computeCost(). NFC (PR #107790)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 13:02:31 PDT 2024


================
@@ -2012,6 +2012,40 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) {
   State.set(this, NewRed, /*IsScalar*/ true);
 }
 
+InstructionCost VPReductionRecipe::computeCost(ElementCount VF,
+                                               VPCostContext &Ctx) const {
+  RecurKind RdxKind = RdxDesc.getRecurrenceKind();
+  Type *ElementTy = Ctx.Types.inferScalarType(this);
+  auto *VectorTy = cast<VectorType>(ToVectorTy(ElementTy, VF));
+  TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+  unsigned Opcode = RdxDesc.getOpcode();
+
+  // TODO: Support any-of reduction and in-loop reductions.
+  assert(
+      (!RecurrenceDescriptor::isAnyOfRecurrenceKind(RdxKind) ||
+       ForceTargetInstructionCost.getNumOccurrences() > 0) &&
+      "Any-of reduction not implemented in VPlan-based cost model currently.");
+  assert(
+      (!Ctx.isInLoopReduction(getUnderlyingInstr(), VF, VectorTy) ||
----------------
fhahn wrote:

Do we need to introduce a lookup via the legacy cost model here? IIRC the first op of the reduction recipe is the reduction PHI recipe, which has an in-loop flag. Can we check that instead?

https://github.com/llvm/llvm-project/pull/107790


More information about the llvm-commits mailing list