From 7bc3062a3bd4c1f29eb52db93e29329b3aee7034 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Thu, 20 Feb 2025 13:14:45 +0100 Subject: [PATCH] nir/opt_algebraic: push comparisons with constants into bcsel with constant Foz-DB Navi21: Totals from 1657 (2.08% of 79789) affected shaders: MaxWaves: 30275 -> 30261 (-0.05%); split: +0.01%, -0.05% Instrs: 3316251 -> 3315701 (-0.02%); split: -0.04%, +0.02% CodeSize: 17831924 -> 17832020 (+0.00%); split: -0.06%, +0.06% SpillSGPRs: 815 -> 859 (+5.40%) SpillVGPRs: 3335 -> 3293 (-1.26%) Scratch: 231424 -> 230400 (-0.44%) Latency: 33413310 -> 33402751 (-0.03%); split: -0.04%, +0.01% InvThroughput: 9116062 -> 9112904 (-0.03%); split: -0.04%, +0.00% VClause: 65587 -> 65560 (-0.04%); split: -0.05%, +0.01% SClause: 86208 -> 86261 (+0.06%); split: -0.02%, +0.08% Copies: 356158 -> 356439 (+0.08%); split: -0.07%, +0.15% PreSGPRs: 101710 -> 101806 (+0.09%); split: -0.01%, +0.11% PreVGPRs: 89293 -> 89286 (-0.01%); split: -0.04%, +0.04% VALU: 2220900 -> 2218839 (-0.09%); split: -0.11%, +0.01% SALU: 472988 -> 474567 (+0.33%); split: -0.08%, +0.42% VMEM: 118401 -> 118347 (-0.05%) SMEM: 123597 -> 123592 (-0.00%) Reviewed-by: Ian Romanick Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 728581db862..27a70209f16 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -909,6 +909,15 @@ optimizations.extend([ (('imax', ('imin', a, b), a), a), ]) +for op in ['ine', 'ieq', 'ilt', 'ige', 'ult', 'uge', 'bitz', 'bitnz', + 'fneu', 'feq', 'flt', 'fge', 'fneo', 'fequ']: + optimizations.extend([ + ((op, ('bcsel(is_used_once)', a, b, '#c'), '#d'), ('bcsel', a, (op, b, d), (op, c, d))), + ((op, ('bcsel(is_used_once)', a, '#b', c), '#d'), ('bcsel', a, (op, b, d), (op, c, d))), + ((op, '#d', ('bcsel(is_used_once)', a, b, '#c')), ('bcsel', a, (op, d, b), (op, d, c))), + ((op, '#d', ('bcsel(is_used_once)', a, '#b', c)), ('bcsel', a, (op, d, b), (op, d, c))), + ]) + for N in [8, 16, 32, 64]: b2iN = 'b2i{0}'.format(N) optimizations.extend([