nir/algebraic: Optimize some masking of extract_u8 operations

I observed this pattern in several Red Dead Redemption 2 shaders.

No shader-db changes on any Intel platform.

v2: Remove duplicated patterns. Noticed by Georg.

fossil-db:

All Intel platforms had similar results. (Meteor Lake shown)
Totals:
Instrs: 151519393 -> 151507192 (-0.01%); split: -0.01%, +0.00%
Cycle count: 17208246858 -> 17177437340 (-0.18%); split: -0.25%, +0.07%
Spill count: 80830 -> 80759 (-0.09%); split: -0.09%, +0.00%
Fill count: 152754 -> 152179 (-0.38%); split: -0.40%, +0.02%

Totals from 7531 (1.20% of 630198) affected shaders:
Instrs: 12606141 -> 12593940 (-0.10%); split: -0.10%, +0.00%
Cycle count: 5466605514 -> 5435795996 (-0.56%); split: -0.79%, +0.22%
Spill count: 25251 -> 25180 (-0.28%); split: -0.29%, +0.01%
Fill count: 45143 -> 44568 (-1.27%); split: -1.36%, +0.08%

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30158>
This commit is contained in:
Ian Romanick 2024-02-20 10:03:46 -08:00 committed by Marge Bot
parent 1c7e35d4e0
commit faee9426ab

View file

@ -1793,6 +1793,14 @@ optimizations.extend([
(('extract_u8', ('iand', a, 0x00ff0000), 2), ('extract_u8', a, 2)),
(('extract_u8', ('iand', a, 0xff000000), 3), ('extract_u8', a, 3)),
(('iand', ('extract_u8', a, 0), '#b'), ('iand', a, ('iand', b, 0x00ff))),
(('iand', ('extract_u16', a, 0), '#b'), ('iand', a, ('iand', b, 0xffff))),
(('ieq', ('iand', ('extract_u8', a, '#b'), '#c'), 0), ('ieq', ('iand', a, ('ishl', ('iand', c, 0x00ff), ('imul', ('i2i32', b), 8))), 0)),
(('ine', ('iand', ('extract_u8', a, '#b'), '#c'), 0), ('ine', ('iand', a, ('ishl', ('iand', c, 0x00ff), ('imul', ('i2i32', b), 8))), 0)),
(('ieq', ('iand', ('extract_u16(is_used_once)', a, '#b'), '#c'), 0), ('ieq', ('iand', a, ('ishl', ('iand', c, 0xffff), ('imul', ('i2i32', b), 16))), 0)),
(('ine', ('iand', ('extract_u16(is_used_once)', a, '#b'), '#c'), 0), ('ine', ('iand', a, ('ishl', ('iand', c, 0xffff), ('imul', ('i2i32', b), 16))), 0)),
# Word extraction
(('ushr', ('ishl', 'a@32', 16), 16), ('extract_u16', a, 0), '!options->lower_extract_word'),
(('ushr', 'a@32', 16), ('extract_u16', a, 1), '!options->lower_extract_word'),