From 541e7eb3898bef4878e6eb356a5942acfb8431ee Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 26 Jul 2022 12:30:04 -0700 Subject: [PATCH] nir/algebraic: Optimize some u2f of bfi v2: Fix a copy-and-paste bug s/('find_lsb', a)/a/ in the patterns. See piglit!819. DG2, Tiger Lake, Ice Lake, Skylake, and Broadwell had similar results (Ice Lake shown) total instructions in shared programs: 20570063 -> 20570033 (<.01%) instructions in affected programs: 452 -> 422 (-6.64%) helped: 30 / HURT: 0 total cycles in shared programs: 902118723 -> 902118781 (<.01%) cycles in affected programs: 1762 -> 1820 (3.29%) helped: 0 / HURT: 29 DG2, Tiger Lake, Ice Lake, and Skylake had similar results (Ice Lake shown) Totals: Instrs: 152819969 -> 152819500 (-0.00%) Cycles: 15014628652 -> 15014627187 (-0.00%); split: -0.00%, +0.00% Totals from 469 (0.07% of 662497) affected shaders: Instrs: 7644 -> 7175 (-6.14%) Cycles: 31787 -> 30322 (-4.61%); split: -4.90%, +0.29% Reviewed-by: Matt Turner 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 9b44cbcda1b..611fc10ab65 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1385,6 +1385,15 @@ optimizations.extend([ (('uror@16', a, b), ('ior', ('ushr', a, b), ('ishl', a, ('isub', 16, b))), 'options->lower_rotate'), (('uror@32', a, b), ('ior', ('ushr', a, b), ('ishl', a, ('isub', 32, b))), 'options->lower_rotate'), (('uror@64', a, b), ('ior', ('ushr', a, b), ('ishl', a, ('isub', 64, b))), 'options->lower_rotate'), + + # Because 'a' is a positive power of two, the result of the bfi is either 0 + # or 'a' depending on whether or not 'b' is odd. Use 'b&1' for the zero + # value to help platforms that can't have two constants in a bcsel. + (('u2f32', ('bfi', '#a(is_pos_power_of_two)', b, 0)), + ('bcsel', ('ieq', ('iand', b, 1), 0), ('iand', b, 1), ('u2f', a))), + (('u2f', ('bfi', '#a(is_pos_power_of_two)', b, 0)), + ('bcsel', ('ieq', ('iand', b, 1), 0), 0, ('u2f', a))), + # Exponential/logarithmic identities (('~fexp2', ('flog2', a)), a), # 2^lg2(a) = a (('~flog2', ('fexp2', a)), a), # lg2(2^a) = a