From: Ian Romanick Date: Mon, 10 Oct 2022 20:42:56 +0000 (-0700) Subject: nir/algebraic: Optimize some ifind_msb to ufind_msb X-Git-Tag: upstream/23.3.3~11837 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=831f9d3f615ca5228e9614191d76f95735bfc2cc;p=platform%2Fupstream%2Fmesa.git nir/algebraic: Optimize some ifind_msb to ufind_msb On Intel platforms, the uclz lowering if ufind_msb is either one instruction better (Gfx7 and newer) or two instructions better (all older platforms) than the ifind_msb implementations. On platforms that use lower_find_msb_to_reverse, there should be no difference. All Haswell and newer Intel platforms had similar results. (Ice Lake shown) total instructions in shared programs: 19938662 -> 19938634 (<.01%) instructions in affected programs: 850 -> 822 (-3.29%) helped: 2 / HURT: 0 total cycles in shared programs: 858467067 -> 858465538 (<.01%) cycles in affected programs: 10080 -> 8551 (-15.17%) helped: 2 / HURT: 0 Reviewed-by: Kenneth Graunke Part-of: --- diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 2a58f91..0162c33 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1814,6 +1814,8 @@ optimizations.extend([ (('find_lsb', ('bitfield_reverse', a)), ('ufind_msb_rev', a), 'options->has_find_msb_rev'), (('ufind_msb_rev', ('bitfield_reverse', a)), ('find_lsb', a), '!options->lower_find_lsb'), + (('ifind_msb', ('f2i32(is_used_once)', a)), ('ufind_msb', ('f2i32', ('fabs', a)))), + (('~fmul', ('bcsel(is_used_once)', c, -1.0, 1.0), b), ('bcsel', c, ('fneg', b), b)), (('~fmul', ('bcsel(is_used_once)', c, 1.0, -1.0), b), ('bcsel', c, b, ('fneg', b))), (('~fmulz', ('bcsel(is_used_once)', c, -1.0, 1.0), b), ('bcsel', c, ('fneg', b), b)),