nir/opt_algebraic: Optimize Doom Eternal's word extract by LSB.

Foz-db GFX10_3:
Totals from 419 (0.31% of 134913) affected shaders:
CodeSize: 4126032 -> 4121756 (-0.10%)
Instrs: 783608 -> 782541 (-0.14%)
Latency: 7889664 -> 7888521 (-0.01%); split: -0.02%, +0.00%
InvThroughput: 1315690 -> 1314863 (-0.06%); split: -0.06%, +0.00%
VClause: 11826 -> 11830 (+0.03%)
SClause: 27736 -> 27734 (-0.01%)
Copies: 50493 -> 50428 (-0.13%); split: -0.13%, +0.01%
PreSGPRs: 23264 -> 23265 (+0.00%)

Signed-off-by: Georg Lehmann <dadschoorse@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16436>
This commit is contained in:
Georg Lehmann 2022-05-10 17:26:42 +02:00 committed by Marge Bot
parent 9a11ad7efd
commit bc5c68fc08

View file

@ -30,6 +30,7 @@ from nir_opcodes import type_sizes
import itertools
import struct
from math import pi
import math
# Convenience variables
a = 'a'
@ -1012,6 +1013,8 @@ for op in ['iand', 'ior', 'ixor']:
# Integer sizes
for s in [8, 16, 32, 64]:
last_shift_bit = int(math.log2(s)) - 1
optimizations.extend([
(('iand', ('ieq', 'a@{}'.format(s), 0), ('ieq', 'b@{}'.format(s), 0)), ('ieq', ('ior', a, b), 0), 'options->lower_umax'),
(('ior', ('ine', 'a@{}'.format(s), 0), ('ine', 'b@{}'.format(s), 0)), ('ine', ('ior', a, b), 0), 'options->lower_umin'),
@ -1027,6 +1030,7 @@ for s in [8, 16, 32, 64]:
(('ishl', 'a@{}'.format(s), ('iand', s - 1, b)), ('ishl', a, b)),
(('ishr', 'a@{}'.format(s), ('iand', s - 1, b)), ('ishr', a, b)),
(('ushr', 'a@{}'.format(s), ('iand', s - 1, b)), ('ushr', a, b)),
(('ushr', 'a@{}'.format(s), ('ishl(is_used_once)', ('iand', b, 1), last_shift_bit)), ('ushr', a, ('ishl', b, last_shift_bit))),
])
optimizations.extend([