[Mesa-dev] [PATCH v2 1/2] nir/algebraic: Simplify max(abs(a), 0.0) -> abs(a)

Alyssa Rosenzweig alyssa at rosenzweig.io
Sun May 26 01:52:44 UTC 2019


I noticed this pattern in glmark's jellyfish scene.

v2: Add inexact qualifier to avoid changing NaN behaviour

I would appreciate if someone did a shader-db run.

Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Cc: Ilia Mirkin <imirkin at alum.mit.edu>
Cc: Ian Romanick <idr at freedesktop.org>
Cc: Elie Tournier <tournier.elie at gmail.com>
---
 src/compiler/nir/nir_opt_algebraic.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 89d07aa1261..e607e5b6fe2 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -397,6 +397,7 @@ optimizations = [
    (('imax', a, ('iabs', a)), ('iabs', a)),
    (('fmax', a, ('fneg', a)), ('fabs', a)),
    (('imax', a, ('ineg', a)), ('iabs', a)),
+   (('~fmax', ('fabs', a), 0.0), ('fabs', a)),
    (('~fmin', ('fmax', a, 0.0), 1.0), ('fsat', a), '!options->lower_fsat'),
    (('~fmax', ('fmin', a, 1.0), 0.0), ('fsat', a), '!options->lower_fsat'),
    (('~fmin', ('fmax', a, -1.0),  0.0), ('fneg', ('fsat', ('fneg', a))), '!options->lower_negate && !options->lower_fsat'),
-- 
2.20.1



More information about the mesa-dev mailing list