[Mesa-dev] [PATCH 5/9] nir: Add a flag for lowering fneg/ineg.
Eric Anholt
eric at anholt.net
Sun Feb 1 13:17:24 PST 2015
vc4 cse/algebraic-disabled stats:
total instructions in shared programs: 44911 -> 44732 (-0.40%)
instructions in affected programs: 11371 -> 11192 (-1.57%)
---
src/gallium/drivers/vc4/vc4_program.c | 1 +
src/glsl/nir/nir.h | 2 ++
src/glsl/nir/nir_opt_algebraic.py | 10 ++++++++++
3 files changed, 13 insertions(+)
diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index fd818b4..304cd04 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -2100,6 +2100,7 @@ nir_to_qir(struct vc4_compile *c)
static const nir_shader_compiler_options nir_options = {
.lower_fpow = true,
.lower_fsqrt = true,
+ .lower_negate = true,
};
static struct vc4_compile *
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index b0ad4b0..0746adf 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1329,6 +1329,8 @@ typedef struct nir_function {
typedef struct nir_shader_compiler_options {
bool lower_fpow;
bool lower_fsqrt;
+ /** lowers fneg and ineg to fsub and isub. */
+ bool lower_negate;
} nir_shader_compiler_options;
typedef struct nir_shader {
diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
index 2020997..7d5f543 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -136,6 +136,16 @@ optimizations = [
(('bcsel', a, b, b), b),
(('fcsel', a, b, b), b),
+ # Subtracts
+ (('fsub', 0.0, ('fsub', 0.0, a)), a),
+ (('isub', 0, ('isub', 0, a)), a),
+ (('fneg', a), ('fsub', 0.0, a), 'options->lower_negate'),
+ (('ineg', a), ('isub', 0, a), 'options->lower_negate'),
+ (('fadd', a, ('fsub', 0.0, b)), ('fsub', a, b)),
+ (('iadd', a, ('isub', 0, b)), ('isub', a, b)),
+ (('fabs', ('fsub', 0.0, a)), ('fabs', a)),
+ (('iabs', ('isub', 0, a)), ('fabs', a)),
+
# This one may not be exact
(('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
]
--
2.1.4
More information about the mesa-dev
mailing list