[llvm] [VPlan] Impl VPlan-based pattern match for ExtendedRed and MulAccRed (PR #113903)

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Sun May 18 17:21:42 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().
   if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RdxKind)) {
     Intrinsic::ID Id = getMinMaxReductionIntrinsicOp(RdxKind);
-    return Cost +
-           Ctx.TTI.getMinMaxReductionCost(Id, VectorTy, FMFs, Ctx.CostKind);
----------------
ElvisWang123 wrote:

Remove the BinOp cost here to match the legacy cost model.  [link](https://github.com/llvm/llvm-project/blob/ec7a5091655f75839e8da57a76aec6600a864915/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp#L5888)
And TTI already calculate the cost of BinOp (at least in RISCV). [link](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp#L1884-L1920)


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


More information about the llvm-commits mailing list