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

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 23 21:59:55 PDT 2025


================
@@ -782,19 +784,25 @@ Value *VPInstruction::generate(VPTransformState &State) {
 InstructionCost VPInstruction::computeCost(ElementCount VF,
                                            VPCostContext &Ctx) const {
   if (Instruction::isBinaryOp(getOpcode())) {
+
+    Type *ResTy = Ctx.Types.inferScalarType(this);
+    if (!vputils::onlyFirstLaneUsed(this))
+      ResTy = toVectorTy(ResTy, VF);
+
     if (!getUnderlyingValue()) {
-      // TODO: Compute cost for VPInstructions without underlying values once
-      // the legacy cost model has been retired.
-      return 0;
+      switch (getOpcode()) {
+      case Instruction::FMul:
+        return Ctx.TTI.getArithmeticInstrCost(getOpcode(), ResTy, Ctx.CostKind);
+      default:
+        // TODO: Compute cost for VPInstructions without underlying values once
+        // the legacy cost model has been retired.
+        return 0;
+      }
----------------
ElvisWang123 wrote:

Yes. Otherwise it will hit the assertion of `legacy cost model and vplan-based cost model mismatch` when the reduction is `fmuladd`.

Fmuladd reduction will generate `Instruction::FMul` + fadd reduction. Without the cost of fmul, the cost will slightly lower than the legcy model.

Could be split of in different patch but cannot show the failure without removing `precompute` reduction costs.

The potential failure: 
(C) https://godbolt.org/z/hP4eYooTK 
(llvm IR) https://godbolt.org/z/G9bT4Y1c9

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


More information about the llvm-commits mailing list