From ba0b248ac2c7e64ac81fe8a64bdc80f4e1acee7d Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 8 May 2018 09:53:17 -0700 Subject: [PATCH] nir/algebraic: Eliminate unary op on src of integer comparison w/ zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps because it enables cmod propagation to do more. The removed patterns involving b2i will be handled by other existing patterns after the unary operations are removed. All Intel platforms had similar results. (Ice Lake shown) total instructions in shared programs: 19914458 -> 19914441 (<.01%) instructions in affected programs: 5456 -> 5439 (-0.31%) helped: 17 / HURT: 0 total cycles in shared programs: 855302118 -> 853869766 (-0.17%) cycles in affected programs: 327354347 -> 325921995 (-0.44%) helped: 291 / HURT: 81 All Intel platforms had similar results. (Ice Lake shown) Instructions in all programs: 141205979 -> 141205961 (-0.0%) Instructions helped: 4 Instructions hurt: 3 SENDs in all programs: 7466919 -> 7466913 (-0.0%) SENDs helped: 1 Cycles in all programs: 9133387327 -> 9133384475 (-0.0%) Cycles helped: 3 Cycles hurt: 12 In the shader that was helped for sends, it appears that a NIR pass that moves code out of loops was able to move 3 send operations outside a loop after this change. I did not investigate further. Reviewed-by: Jason Ekstrand Acked-by: Jesse Natalie Acked-by: Alyssa Rosenzweig Tested-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index f3612a259ac..0abf3099a2b 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -552,6 +552,11 @@ optimizations.extend([ (('fneu', ('fneg', a), -1.0), ('fneu', 1.0, a)), (('feq', -1.0, ('fneg', a)), ('feq', a, 1.0)), + (('ieq', ('ineg', a), 0), ('ieq', a, 0)), + (('ine', ('ineg', a), 0), ('ine', a, 0)), + (('ieq', ('iabs', a), 0), ('ieq', a, 0)), + (('ine', ('iabs', a), 0), ('ine', a, 0)), + # b < fsat(NaN) -> b < 0 -> false, and b < Nan -> false. (('flt', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('flt', b, a)), @@ -1410,9 +1415,7 @@ optimizations.extend([ ('ineg', ('b2i', ('iand', a, b)))), (('ior', ('ineg', ('b2i','a@1')), ('ineg', ('b2i', 'b@1'))), ('ineg', ('b2i', ('ior', a, b)))), - (('ieq', ('ineg', ('b2i', 'a@1')), 0), ('inot', a)), (('ieq', ('ineg', ('b2i', 'a@1')), -1), a), - (('ine', ('ineg', ('b2i', 'a@1')), 0), a), (('ine', ('ineg', ('b2i', 'a@1')), -1), ('inot', a)), (('ige', ('ineg', ('b2i', 'a@1')), 0), ('inot', a)), (('ilt', ('ineg', ('b2i', 'a@1')), 0), a),