Mesa (main): nir/algebraic: add optimizations for imul(a, INT_MIN)

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 9 11:39:13 UTC 2021


Module: Mesa
Branch: main
Commit: b009467b810ce42a97f80c15cbb5647781a5f807
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b009467b810ce42a97f80c15cbb5647781a5f807

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Wed Jul 21 17:03:01 2021 +0100

nir/algebraic: add optimizations for imul(a, INT_MIN)

is_pos_power_of_two would catch this, but nir_op_imul has signed sources,
so is_neg_power_of_two catches it instead, which creates a useless
nir_op_ineg.

fossil-db (Sienna Cichlid):
Totals from 1014 (0.68% of 150170) affected shaders:
CodeSize: 3592296 -> 3592288 (-0.00%); split: -0.00%, +0.00%
Instrs: 671211 -> 670426 (-0.12%)
Latency: 5268917 -> 5268479 (-0.01%); split: -0.01%, +0.00%
InvThroughput: 2187349 -> 2187343 (-0.00%); split: -0.00%, +0.00%
VClause: 8634 -> 8636 (+0.02%)
Copies: 97585 -> 97604 (+0.02%)

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12039>

---

 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 bbc89b6ad86..225bb3efbc1 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -95,6 +95,10 @@ def intBitsToFloat(i):
 optimizations = [
 
    (('imul', a, '#b(is_pos_power_of_two)'), ('ishl', a, ('find_lsb', b)), '!options->lower_bitops'),
+   (('imul', 'a at 8', 0x80), ('ishl', a, 7), '!options->lower_bitops'),
+   (('imul', 'a at 16', 0x8000), ('ishl', a, 15), '!options->lower_bitops'),
+   (('imul', 'a at 32', 0x80000000), ('ishl', a, 31), '!options->lower_bitops'),
+   (('imul', 'a at 64', 0x8000000000000000), ('ishl', a, 63), '!options->lower_bitops'),
    (('imul', a, '#b(is_neg_power_of_two)'), ('ineg', ('ishl', a, ('find_lsb', ('iabs', b)))), '!options->lower_bitops'),
    (('ishl', a, '#b'), ('imul', a, ('ishl', 1, b)), 'options->lower_bitops'),
 



More information about the mesa-commit mailing list