nir/opt_algebraic: Simple xor/ishr optimizations.
authorGeorg Lehmann <dadschoorse@gmail.com>
Mon, 9 May 2022 09:52:26 +0000 (11:52 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 10 May 2022 19:29:31 +0000 (19:29 +0000)
The first pattern here removes the xor-swap pattern.

Foz-DB GFX10_3:
Totals from 305 (0.23% of 134913) affected shaders:
CodeSize: 1589040 -> 1585164 (-0.24%)
Instrs: 284344 -> 283375 (-0.34%)
Latency: 4205148 -> 4198472 (-0.16%); split: -0.16%, +0.00%
InvThroughput: 708745 -> 708739 (-0.00%)

Signed-off-by: Georg Lehmann <dadschoorse@gmail.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16411>

src/compiler/nir/nir_opt_algebraic.py

index 222727d..3c78fc0 100644 (file)
@@ -1210,6 +1210,8 @@ optimizations.extend([
    (('ior', a, True), True),
    (('ixor', a, a), 0),
    (('ixor', a, 0), a),
+   (('ixor', a, ('ixor', a, b)), b),
+   (('ixor', a, -1), ('inot', a)),
    (('inot', ('inot', a)), a),
    (('ior', ('iand', a, b), b), b),
    (('ior', ('ior', a, b), b), ('ior', a, b)),
@@ -1222,6 +1224,7 @@ optimizations.extend([
    (('ishl', 0, a), 0),
    (('ishl', a, 0), a),
    (('ishr', 0, a), 0),
+   (('ishr', -1, a), -1),
    (('ishr', a, 0), a),
    (('ushr', 0, a), 0),
    (('ushr', a, 0), a),