Mesa (master): nir: Add a flag for lowering fneg/ineg.
Eric Anholt
anholt at kemper.freedesktop.org
Wed Feb 18 22:57:23 UTC 2015
Module: Mesa
Branch: master
Commit: 42a8ace66e539957b31ea96fe9a2aaacdb90f30e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=42a8ace66e539957b31ea96fe9a2aaacdb90f30e
Author: Eric Anholt <eric at anholt.net>
Date: Wed Jan 28 10:52:53 2015 -0800
nir: Add a flag for lowering fneg/ineg.
vc4 cse/algebraic-disabled stats:
total instructions in shared programs: 44911 -> 44732 (-0.40%)
instructions in affected programs: 11371 -> 11192 (-1.57%)
v2: Fix broken iabs(isub(0, a)) transformation.
v3: Rebase to master (no TGSI->NIR present)
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org> (v1)
---
src/glsl/nir/nir.h | 2 ++
src/glsl/nir/nir_opt_algebraic.py | 10 ++++++++++
2 files changed, 12 insertions(+)
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 37e15ef..6448d4a 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 f93757e..8d5c03b 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -141,6 +141,16 @@ optimizations = [
# next round of opt_algebraic, get picked up by one of the above two.
(('bcsel', '#a', b, c), ('bcsel', ('ine', 'a', 0), b, c)),
+ # 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)), ('iabs', a)),
+
# This one may not be exact
(('feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
]
More information about the mesa-commit
mailing list