[llvm] relaxed simd fma (PR #147487)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 10 18:24:52 PDT 2025
================
@@ -1542,6 +1542,29 @@ defm "" : SIMDMADD<F32x4, 0x105, 0x106, [HasRelaxedSIMD]>;
defm "" : SIMDMADD<F64x2, 0x107, 0x108, [HasRelaxedSIMD]>;
defm "" : SIMDMADD<F16x8, 0x14e, 0x14f, [HasFP16]>;
+def fmul_fast : PatFrag<(ops node:$a, node:$b), (fmul node:$a, node:$b),[{
+ return N->getFlags().hasAllowContract();
+}]>;
+
+
+def fadd_fast : PatFrag<(ops node:$a, node:$b), (fadd node:$a, node:$b),[{
+ return N->getFlags().hasAllowContract();
+}]>;
+
+def : Pat<(fadd (v4f32 V128:$a), (fmul_fast (v4f32 V128:$b), (v4f32 V128:$c))),
----------------
lukel97 wrote:
Based on this small test, dag combiner only seems to fuse this to an fma when both nodes have the contract flag set:
```llvm
define float @f(float %x, float %y, float %z) {
%1 = fmul contract float %x, %y
%2 = fadd contract float %1, %z
ret float %2
}
```
So we should probably also restrict our pattern to when both nodes have contract too
https://github.com/llvm/llvm-project/pull/147487
More information about the llvm-commits
mailing list