From: Jason Ekstrand Date: Fri, 19 Oct 2018 21:58:36 +0000 (-0500) Subject: nir/algebraic: Add some optimizations for D3D-style Booleans X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6bcd2af0863aea9d9d3519300a75820d012e1160;p=mesa.git nir/algebraic: Add some optimizations for D3D-style Booleans D3D Booleans use a 32-bit 0/-1 representation. Because this previously matched NIR exactly, we didn't have to really optimize for it. Now that we have 1-bit Booleans, we need some specific optimizations to chew through the D3D12-style Booleans. Shader-db results on Kaby Lake: total instructions in shared programs: 15136811 -> 14967944 (-1.12%) instructions in affected programs: 2457021 -> 2288154 (-6.87%) helped: 8318 HURT: 10 total cycles in shared programs: 373544524 -> 359701825 (-3.71%) cycles in affected programs: 151029683 -> 137186984 (-9.17%) helped: 7749 HURT: 682 total loops in shared programs: 4431 -> 4399 (-0.72%) loops in affected programs: 32 -> 0 helped: 21 HURT: 0 total spills in shared programs: 10290 -> 10051 (-2.32%) spills in affected programs: 2532 -> 2293 (-9.44%) helped: 18 HURT: 18 total fills in shared programs: 22203 -> 21732 (-2.12%) fills in affected programs: 3319 -> 2848 (-14.19%) helped: 18 HURT: 18 Note that a large chunk of the improvement fixing regressions caused by switching to 1-bit Booleans. Previously, our ability to optimize D3D booleans was improved by using the D3D representation directly in NIR. Now that NIR does 1-bit bools, we need a few more optimizations. Reviewed-by: Bas Nieuwenhuizen Reviewed-by: Eric Anholt Tested-by: Bas Nieuwenhuizen --- diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 3c8af4692b5..506d45e55b5 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -534,6 +534,19 @@ optimizations = [ (('bcsel', a, b, b), b), (('fcsel', a, b, b), b), + # D3D Boolean emulation + (('bcsel', a, -1, 0), ('ineg', ('b2i', 'a@1'))), + (('bcsel', a, 0, -1), ('ineg', ('b2i', ('inot', a)))), + (('iand', ('ineg', ('b2i', 'a@1')), ('ineg', ('b2i', 'b@1'))), + ('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)), + (('iand', ('ineg', ('b2i', a)), '1.0@32'), ('b2f', a)), + # Conversions (('i2b32', ('b2i', 'a@32')), a), (('f2i', ('ftrunc', a)), ('f2i', a)),