From 8752401e03f3c3946f328c510aa04429b0f67fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 16 Nov 2024 23:34:09 -0500 Subject: [PATCH] nir/algebraic: optimize (a & b) | (a | c) => a | c, (a & b) & (a | c) => a & b No change in shader-db with ACO, but it doesn't seem to be optimized by any other patterns. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index b7c0190ea61..db3c9b681b6 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -227,6 +227,10 @@ optimizations = [ (('ior', ('ior', a, b), ('ior(is_used_once)', a, c)), ('ior', ('ior', a, b), c)), (('iand', ('ior(is_used_once)', a, b), ('ior(is_used_once)', a, c)), ('ior', a, ('iand', b, c))), (('ior', ('iand(is_used_once)', a, b), ('iand(is_used_once)', a, c)), ('iand', a, ('ior', b, c))), + # (a & b) | (a | c) => ((a & b) | a) | c => a | c + (('ior', ('iand', a, b), ('ior', a, c)), ('ior', a, c)), + # (a & b) & (a | c) => b & (a & (a | c)) => b & a + (('iand', ('iand', a, b), ('ior', a, c)), ('iand', a, b)), (('ieq', ('iand', a, '#b(is_pos_power_of_two)'), b), ('ine', ('iand', a, b), 0)), (('ine', ('iand', a, '#b(is_pos_power_of_two)'), b), ('ieq', ('iand', a, b), 0)), (('ieq', ('ushr(is_used_once)', a, '#b'), 0), ('ult', a, ('ishl', 1, b))),