Module: Mesa Branch: main Commit: bc5c68fc08fb40026fff9775c221860885c2aacc URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=bc5c68fc08fb40026fff9775c221860885c2aacc
Author: Georg Lehmann <[email protected]> Date: Tue May 10 17:26:42 2022 +0200 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 <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16436> --- src/compiler/nir/nir_opt_algebraic.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 9f73c336beb..e7f21ad0b7f 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -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([
