nir: Add a few more algebraic optimizations to help address calculation.

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9201>
This commit is contained in:
Timur Kristóf 2021-02-26 19:05:25 +01:00 committed by Marge Bot
parent 9f9b0f583b
commit 132171dc4e

View file

@ -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)),