<div dir="ltr">In general, you're not supposed to mess around with the precision of fma... What we do in the Intel drivers is to leave fma split, apply operations, and then we have a special mul+add fusion pass we run at the end.  Leaving them split allows for exactly this kind of optimization without mixing up those FMAs that are supposed to be kept fused and those generated by mul+add fusion which can be split back apart and re-optimized.<br></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 12, 2018 at 12:17 PM Jonathan Marek <<a href="mailto:jonathan@marek.ca">jonathan@marek.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This works by moving the fadd up across the ffma operations, so that it<br>
can eventually can be combined with a fmul. I'm not sure it works in all<br>
cases, but it works in all the common cases.<br>
<br>
Example:<br>
    matrix * vec4(coord, 1.0)<br>
is compiled as:<br>
    fmul, ffma, ffma, fadd<br>
and with this patch:<br>
    ffma, ffma, ffma<br>
<br>
Signed-off-by: Jonathan Marek <<a href="mailto:jonathan@marek.ca" target="_blank">jonathan@marek.ca</a>><br>
---<br>
 src/compiler/nir/nir_opt_algebraic.py | 1 +<br>
 1 file changed, 1 insertion(+)<br>
<br>
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py<br>
index 8f4df891b8..82e10731a6 100644<br>
--- a/src/compiler/nir/nir_opt_algebraic.py<br>
+++ b/src/compiler/nir/nir_opt_algebraic.py<br>
@@ -133,6 +133,7 @@ optimizations = [<br>
    (('~fadd@64', a, ('fmul',         c , ('fadd', b, ('fneg', a)))), ('flrp', a, b, c), '!options->lower_flrp64'),<br>
    (('ffma', a, b, c), ('fadd', ('fmul', a, b), c), 'options->lower_ffma'),<br>
    (('~fadd', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma'),<br>
+   (('~fadd', ('ffma', a, b, c), d), ('ffma', a, b, ('fadd', c, d))),<br>
<br>
    (('fdot4', ('vec4', a, b,   c,   1.0), d), ('fdph',  ('vec3', a, b, c), d)),<br>
    (('fdot4', ('vec4', a, 0.0, 0.0, 0.0), b), ('fmul', a, b)),<br>
-- <br>
2.17.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>