[Mesa-dev] [PATCH 3/3] nir: combine fmul and fadd across ffma operations

Jonathan Marek jonathan at marek.ca
Mon Nov 19 20:00:50 UTC 2018


This works by moving the fadd up across the ffma operations, so that it
can eventually can be combined with a fmul. I'm not sure it works in all
cases, but it works in all the common cases.

This will only affect freedreno since it is the only driver using the
fuse_ffma option.

Example:
    matrix * vec4(coord, 1.0)
is compiled as:
    fmul, ffma, ffma, fadd
and with this patch:
    ffma, ffma, ffma

Signed-off-by: Jonathan Marek <jonathan at marek.ca>
---
 src/compiler/nir/nir_opt_algebraic.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 8f4df891b8..8d7c30e04a 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -133,6 +133,7 @@ optimizations = [
    (('~fadd at 64', a, ('fmul',         c , ('fadd', b, ('fneg', a)))), ('flrp', a, b, c), '!options->lower_flrp64'),
    (('ffma', a, b, c), ('fadd', ('fmul', a, b), c), 'options->lower_ffma'),
    (('~fadd', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma'),
+   (('~fadd', ('ffma', a, b, c), d), ('ffma', a, b, ('fadd', c, d)), 'options->fuse_ffma'),
 
    (('fdot4', ('vec4', a, b,   c,   1.0), d), ('fdph',  ('vec3', a, b, c), d)),
    (('fdot4', ('vec4', a, 0.0, 0.0, 0.0), b), ('fmul', a, b)),
-- 
2.17.1



More information about the mesa-dev mailing list