From be0ab37bacbc782576d05309dcfe2323b27d24b7 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 5 Oct 2023 17:44:09 -0400 Subject: [PATCH] nir/opt_algebraic: Optimize LLVM booleans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helps OpenCL kernels. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Marek Olšák Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 22a1859ef48..48aa97223e4 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1508,6 +1508,9 @@ optimizations.extend([ (('umax', ('b2i', 'a@1'), ('b2i', 'b@1')), ('b2i', ('ior', a, b))), (('umin', ('b2i', 'a@1'), ('b2i', 'b@1')), ('b2i', ('iand', a, b))), + # Clean up LLVM booleans. b2i output is 0/1 so iand is a no-op. + (('iand', ('b2i', a), 1), ('b2i', a)), + (('ine', ('umin', ('ineg', ('b2i', 'a@1')), b), 0), ('iand', a, ('ine', b, 0))), (('ine', ('umax', ('ineg', ('b2i', 'a@1')), b), 0), ('ior' , a, ('ine', b, 0))),