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

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 23 18:29:28 UTC 2021


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

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Thu Jul  1 08:41:04 2021 +0200

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

Found with Cyberpunk 2077.

fossils-db (GFX10.3):
Totals from 128 (2.34% of 5465) affected shaders:
CodeSize: 769720 -> 767656 (-0.27%); split: -0.27%, +0.00%
Instrs: 145748 -> 145229 (-0.36%)

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

---

 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 449f114da6b..48129c9ce45 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -652,6 +652,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(b, -a)
+   # min(-max(b, a), b) -> min(-b, -a)
+   (('fmax', ('fneg', ('fmin', b, a)), b), ('fmax', b, ('fneg', a))),
+   (('fmin', ('fneg', ('fmax', b, a)), b), ('fmin', ('fneg', 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