Mesa (main): nir/opt_algebraic: optimize fmax(-fmin(b, a), b) -> fmax(fabs(b), -a)

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 25 06:35:09 UTC 2021


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

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Tue Aug 24 08:35:59 2021 +0200

nir/opt_algebraic: optimize fmax(-fmin(b, a), b) -> fmax(fabs(b), -a)

and fmin(-fmax(b, a)) to fmin(-fabs(b), -a).

fossils-db (Sienna Cichlid):
Totals from 34 (0.02% of 150170) affected shaders:
CodeSize: 388540 -> 387748 (-0.20%)
Instrs: 74621 -> 74423 (-0.27%)
Latency: 1039407 -> 1039011 (-0.04%)
InvThroughput: 208364 -> 208150 (-0.10%)

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12519>

---

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

diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index bb07031e615..140b92c2dec 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -717,6 +717,11 @@ optimizations.extend([
    # fmin(0.0, b)) while the right one is "b", so this optimization is inexact.
    (('~fmin', ('fsat', a), '#b(is_zero_to_one)'), ('fsat', ('fmin', a, b))),
 
+   # max(-min(b, a), b) -> max(abs(b), -a)
+   # min(-max(b, a), b) -> min(-abs(b), -a)
+   (('fmax', ('fneg', ('fmin', b, a)), b), ('fmax', ('fabs', b), ('fneg', a))),
+   (('fmin', ('fneg', ('fmax', b, a)), b), ('fmin', ('fneg', ('fabs', b)), ('fneg', a))),
+
    # If a in [0,b] then b-a is also in [0,b].  Since b in [0,1], max(b-a, 0) =
    # fsat(b-a).
    #



More information about the mesa-commit mailing list