[llvm] [VPlan] Implement VPlan-based cost model for VPReduction, VPExtendedReduction and VPMulAccumulateReduction. (NFC) (PR #113903)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue May 27 13:24:34 PDT 2025


================
@@ -2527,24 +2533,47 @@ InstructionCost VPReductionRecipe::computeCost(ElementCount VF,
   auto *VectorTy = cast<VectorType>(toVectorTy(ElementTy, VF));
   unsigned Opcode = RecurrenceDescriptor::getOpcode(RdxKind);
   FastMathFlags FMFs = getFastMathFlags();
+  std::optional<FastMathFlags> OptionalFMF =
+      ElementTy->isFloatingPointTy() ? std::make_optional(FMFs) : std::nullopt;
 
   // TODO: Support any-of reductions.
   assert(
       (!RecurrenceDescriptor::isAnyOfRecurrenceKind(RdxKind) ||
        ForceTargetInstructionCost.getNumOccurrences() > 0) &&
       "Any-of reduction not implemented in VPlan-based cost model currently.");
 
-  // Cost = Reduction cost + BinOp cost
-  InstructionCost Cost =
-      Ctx.TTI.getArithmeticInstrCost(Opcode, ElementTy, Ctx.CostKind);
+  // Note that TTI should model the cost of moving result to the scalar register
+  // and the BinOp cost in the getReductionCost().
----------------
fhahn wrote:

Could you repharse this a bit to make it clearer what this note is about? Below we only call `getMinMaxReductionIntrinsicOp` / `getMinMaxReductionCost`. Should `getReductionCost` -> `getMinMaxReductiton...`?

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


More information about the llvm-commits mailing list