[llvm] [SLP] Fix canConvertToFMA fmul costing (PR #216425)

Dmitry Sidorov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 15:50:30 PDT 2026


================
@@ -126,12 +126,42 @@ define void @contract_mul(ptr noalias %d, ptr noalias %a, ptr noalias %b, ptr no
 ; THR15-NEXT:    [[BP0:%.*]] = getelementptr inbounds float, ptr [[B]], i64 0
 ; THR15-NEXT:    [[CP0:%.*]] = getelementptr inbounds float, ptr [[C]], i64 0
 ; THR15-NEXT:    [[DP0:%.*]] = getelementptr inbounds float, ptr [[D]], i64 0
-; THR15-NEXT:    [[TMP0:%.*]] = load <4 x float>, ptr [[AP0]], align 4
-; THR15-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[BP0]], align 4
-; THR15-NEXT:    [[TMP2:%.*]] = load <4 x float>, ptr [[CP0]], align 4
-; THR15-NEXT:    [[TMP3:%.*]] = fmul contract <4 x float> [[TMP0]], [[TMP1]]
-; THR15-NEXT:    [[TMP4:%.*]] = fadd contract <4 x float> [[TMP3]], [[TMP2]]
-; THR15-NEXT:    store <4 x float> [[TMP4]], ptr [[DP0]], align 4
+; THR15-NEXT:    [[A0:%.*]] = load float, ptr [[AP0]], align 4
----------------
MrSidims wrote:

No, vector is better here. Patch doesn't change that at the default threshold. The THR15 line is a cost probe, not a profitability claim.

Before the patch the contract case could never take the FMA credit, so `getInstructionCost(I, CostKind)` passes the fmul as its own context instruction, so the AMDGPU fusion discount priced it free and FMACost < FMulPlusFAddCost could not hold.

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


More information about the llvm-commits mailing list