From b301c33f65aefa289437eac9d06a71ee57b127a3 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 28 Jan 2022 15:48:39 +0000 Subject: [PATCH] nir/algebraic: optimize fabs(bcsel(b, fneg(a), a)) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit fossil-db (Sienna Cichlid): Totals from 207 (0.15% of 134913) affected shaders: VGPRs: 7152 -> 6928 (-3.13%) CodeSize: 762404 -> 752888 (-1.25%) MaxWaves: 6138 -> 6146 (+0.13%) Instrs: 144031 -> 142184 (-1.28%) Latency: 817783 -> 807286 (-1.28%) InvThroughput: 151031 -> 147497 (-2.34%) VClause: 1490 -> 1453 (-2.48%) SClause: 3357 -> 3331 (-0.77%); split: -0.92%, +0.15% Copies: 9632 -> 9555 (-0.80%); split: -0.81%, +0.01% Branches: 4306 -> 4270 (-0.84%) PreSGPRs: 11232 -> 11218 (-0.12%); split: -0.15%, +0.03% PreVGPRs: 6307 -> 6121 (-2.95%) Signed-off-by: Rhys Perry Reviewed-by: Timur Kristóf Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 34eec39..9817f47 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1676,6 +1676,8 @@ optimizations.extend([ (('~fmul', ('bcsel(is_used_once)', c, 1.0, -1.0), b), ('bcsel', c, b, ('fneg', b))), (('~fmulz', ('bcsel(is_used_once)', c, -1.0, 1.0), b), ('bcsel', c, ('fneg', b), b)), (('~fmulz', ('bcsel(is_used_once)', c, 1.0, -1.0), b), ('bcsel', c, b, ('fneg', b))), + (('fabs', ('bcsel(is_used_once)', b, ('fneg', a), a)), ('fabs', a)), + (('fabs', ('bcsel(is_used_once)', b, a, ('fneg', a))), ('fabs', a)), (('~bcsel', ('flt', a, 0.0), ('fneg', a), a), ('fabs', a)), (('bcsel', a, ('bcsel', b, c, d), d), ('bcsel', ('iand', a, b), c, d)), -- 2.7.4