From b60b2f2add5f52955695d1bd84015287d4fbafe5 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 15 Feb 2022 11:02:07 -0800 Subject: [PATCH] nir/algebraic: Optimize some b2i involved in masking operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v2: Remove the ineg from the b2i in the ior pattern. Suggested by Jason. All Ivy Bridge and newer Intel platforms had similar results. (Ice Lake shown) total instructions in shared programs: 19914441 -> 19914369 (<.01%) instructions in affected programs: 63507 -> 63435 (-0.11%) helped: 24 / HURT: 0 total cycles in shared programs: 853869766 -> 853851470 (<.01%) cycles in affected programs: 10551542 -> 10533246 (-0.17%) helped: 24 / HURT: 0 All Intel platforms had similar results. (Ice Lake shown) Instructions in all programs: 141163061 -> 141092683 (-0.0%) Instructions helped: 14103 Instructions hurt: 55 Cycles in all programs: 9132376195 -> 9133183045 (+0.0%) Cycles helped: 13775 Cycles hurt: 380 Spills in all programs: 18286 -> 18284 (-0.0%) Spills helped: 1 Fills in all programs: 30647 -> 30643 (-0.0%) Fills helped: 1 Gained: 133 Lost: 130 Acked-by: Jesse Natalie Acked-by: Alyssa Rosenzweig Tested-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 0abf3099a2b..c47176a6485 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1083,6 +1083,19 @@ optimizations.extend([ (('ine', ('ineg', ('b2i', 'a@1')), ('ineg', ('b2i', 'b@1'))), ('ine', a, b)), (('b2i', ('ine', 'a@1', 'b@1')), ('b2i', ('ixor', a, b))), + (('ishl', ('b2i32', ('ine', ('iand', 'a@32', '#b(is_pos_power_of_two)'), 0)), '#c'), + ('bcsel', ('ige', ('iand', c, 31), ('find_lsb', b)), + ('ishl', ('iand', a, b), ('iadd', ('iand', c, 31), ('ineg', ('find_lsb', b)))), + ('ushr', ('iand', a, b), ('iadd', ('ineg', ('iand', c, 31)), ('find_lsb', b))) + ) + ), + + (('b2i32', ('ine', ('iand', 'a@32', '#b(is_pos_power_of_two)'), 0)), + ('ushr', ('iand', a, b), ('find_lsb', b)), '!options->lower_bitops'), + + (('ior', ('b2i', a), ('iand', b, 1)), ('iand', ('ior', ('b2i', a), b), 1)), + (('iand', ('b2i', a), ('iand', b, 1)), ('iand', ('b2i', a), b)), + # This pattern occurs coutresy of __flt64_nonnan in the soft-fp64 code. # The first part of the iand comes from the !__feq64_nonnan. #