From 132171dc4e7f0d5f630acc34b7153e48143edddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Fri, 26 Feb 2021 19:05:25 +0100 Subject: [PATCH] nir: Add a few more algebraic optimizations to help address calculation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Timur Kristóf Reviewed-by: Rhys Perry Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 1444be1a2dd..5938561735e 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -340,9 +340,15 @@ optimizations.extend([ # instruction or a constant offset field for in load / store instructions. (('ishl', ('iadd', a, '#b'), '#c'), ('iadd', ('ishl', a, c), ('ishl', b, c))), - # (a + #b) * #c + # (a + #b) * #c => (a * #c) + (#b * #c) (('imul', ('iadd(is_used_once)', a, '#b'), '#c'), ('iadd', ('imul', a, c), ('imul', b, c))), + # ((a + #b) + c) * #d => ((a + c) * #d) + (#b * #d) + (('imul', ('iadd(is_used_once)', ('iadd(is_used_once)', a, '#b'), c), '#d'), + ('iadd', ('imul', ('iadd', a, c), d), ('imul', b, d))), + (('ishl', ('iadd(is_used_once)', ('iadd(is_used_once)', a, '#b'), c), '#d'), + ('iadd', ('ishl', ('iadd', a, c), d), ('ishl', b, d))), + # Comparison simplifications (('~inot', ('flt', a, b)), ('fge', a, b)), (('~inot', ('fge', a, b)), ('flt', a, b)),