nir/opt_algebraic: some bitfield_select optimizations

Foz-DB Navi21:
Totals from 47 (0.06% of 79789) affected shaders:
Instrs: 69536 -> 69363 (-0.25%)
CodeSize: 370624 -> 369388 (-0.33%)
Latency: 383505 -> 383298 (-0.05%)
InvThroughput: 72924 -> 72727 (-0.27%)
PreSGPRs: 2618 -> 2610 (-0.31%)
VALU: 43261 -> 43091 (-0.39%)
SALU: 13065 -> 13063 (-0.02%)

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34739>
This commit is contained in:
Georg Lehmann 2025-04-29 09:55:57 +02:00 committed by Marge Bot
parent 201f6c1a00
commit 0a30611c10

View file

@ -2437,9 +2437,25 @@ optimizations.extend([
('ubfe', 'value', 'offset', 'bits')),
'options->lower_bitfield_extract && options->has_bfe'),
# (src0 & src1) | (~src0 & src2). Constant fold if src2 is 0.
# (src0 & src1) | (~src0 & src2). Constant fold if a src is 0/-1.
(('bitfield_select', a, b, 0), ('iand', a, b)),
(('bitfield_select', a, 0, b), ('iand', ('inot', a), b)),
(('bitfield_select', 0, a, b), b),
(('bitfield_select', a, b, -1), ('ior', ('inot', a), b)),
(('bitfield_select', a, -1, b), ('ior', a, b)),
(('bitfield_select', -1, a, b), a),
(('bitfield_select', a, b, b), b),
(('bitfield_select', a, ('inot', b), b), ('ixor', a, b)),
(('bitfield_select', a, b, ('inot', b)), ('inot', ('ixor', a, b))),
(('bitfield_select', a, ('iand', a, b), c), ('bitfield_select', a, b, c)),
(('bitfield_select', a, b, ('iand', ('inot', a), c)), ('bitfield_select', a, b, c)),
(('bitfield_select', ('inot', a), b, c), ('bitfield_select', a, c, b)),
(('bitfield_select', ('ineg', ('b2i', 'a@1')), b, c), ('bcsel', a, b, c)),
(('ior@32', ('iand', a, b), ('iand', ('inot', a), c)), ('bitfield_select', a, b, c), 'options->has_bitfield_select'),
(('iadd@32', ('iand', a, b), ('iand', ('inot', a), c)), ('bitfield_select', a, b, c), 'options->has_bitfield_select'),
(('ixor@32', ('iand', a, b), ('iand', ('inot', a), c)), ('bitfield_select', a, b, c), 'options->has_bitfield_select'),
(('ixor@32', ('iand', a, ('ixor', b, c)), c), ('bitfield_select', a, b, c), 'options->has_bitfield_select'),
# Note that these opcodes are defined to only use the five least significant bits of 'offset' and 'bits'
(('ubfe', 'value', 'offset', ('iand', 31, 'bits')), ('ubfe', 'value', 'offset', 'bits')),