Mesa (master): nir/algebraic: optimize fmul(x, bcsel(c, -1.0, 1.0)) -> bcsel(c, -x, x)

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 20 16:31:07 UTC 2020


Module: Mesa
Branch: master
Commit: 9d22c5ed718abcf98444f9654b912ccb42b2ccdd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9d22c5ed718abcf98444f9654b912ccb42b2ccdd

Author: Daniel Schürmann <daniel at schuermann.dev>
Date:   Wed Apr 29 15:38:54 2020 +0100

nir/algebraic: optimize fmul(x, bcsel(c, -1.0, 1.0)) -> bcsel(c, -x, x)

Totals from affected shaders: (VEGA)
SGPRS: 545712 -> 545712 (0.00 %)
VGPRS: 413092 -> 413116 (0.01 %)
Spilled SGPRs: 10616 -> 10616 (0.00 %)
Spilled VGPRs: 0 -> 0 (0.00 %)
Private memory VGPRs: 0 -> 0 (0.00 %)
Scratch size: 0 -> 0 (0.00 %) dwords per thread
Code Size: 37031684 -> 36984248 (-0.13 %) bytes
LDS: 427 -> 427 (0.00 %) blocks
Max Waves: 54350 -> 54340 (-0.02 %)

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4830>

---

 src/compiler/nir/nir_opt_algebraic.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 6a94d404309..bd84966821a 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -1134,6 +1134,9 @@ optimizations.extend([
 
    (('bcsel', ('ine', a, -1), ('ifind_msb', a), -1), ('ifind_msb', a)),
 
+   (('~fmul', ('bcsel(is_used_once)', c, -1.0, 1.0), b), ('bcsel', c, ('fneg', b), b)),
+   (('~fmul', ('bcsel(is_used_once)', c, 1.0, -1.0), b), ('bcsel', c, b, ('fneg', b))),
+
    (('fmin3 at 64', a, b, c), ('fmin at 64', a, ('fmin at 64', b, c))),
    (('fmax3 at 64', a, b, c), ('fmax at 64', a, ('fmax at 64', b, c))),
    (('fmed3 at 64', a, b, c), ('fmax at 64', ('fmin at 64', ('fmax at 64', a, b), c), ('fmin at 64', a, b))),



More information about the mesa-commit mailing list