[Mesa-dev] [PATCH 8/9] nir: add late opt to turn inot/b2f combos back to bcsel
Timothy Arceri
timothy.arceri at collabora.com
Tue Jan 10 09:41:57 UTC 2017
We turn these from bcsel into inot/b2f combos in order for other
optimisation passes to get further. Once we have finished turn
the ones that remain and are used in more than a single expression
back into a bcsel.
On BDW:
total instructions in shared programs: 13060965 -> 13060297 (-0.01%)
instructions in affected programs: 835701 -> 835033 (-0.08%)
helped: 670
HURT: 2
total cycles in shared programs: 256599536 -> 256598006 (-0.00%)
cycles in affected programs: 114655488 -> 114653958 (-0.00%)
helped: 419
HURT: 240
LOST: 0
GAINED: 1
The 2 HURT is because inserting bcsel creates the only use of
const 1.0 in two shaders from tri-of-friendship-and-madness.
---
src/compiler/nir/nir_opt_algebraic.py | 3 +++
src/compiler/nir/nir_search_helpers.h | 16 ++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 57e3862..1852a4d 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -519,6 +519,9 @@ late_optimizations = [
(('fdot3', a, b), ('fdot_replicated3', a, b), 'options->fdot_replicates'),
(('fdot4', a, b), ('fdot_replicated4', a, b), 'options->fdot_replicates'),
(('fdph', a, b), ('fdph_replicated', a, b), 'options->fdot_replicates'),
+
+ (('b2f(is_used_more_than_once)', ('inot', a)), ('bcsel', a, 0.0, 1.0)),
+ (('fneg(is_used_more_than_once)', ('b2f', ('inot', a))), ('bcsel', a, -0.0, -1.0)),
]
print nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render()
diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h
index 59b7a0a..313f232 100644
--- a/src/compiler/nir/nir_search_helpers.h
+++ b/src/compiler/nir/nir_search_helpers.h
@@ -112,4 +112,20 @@ is_zero_to_one(nir_alu_instr *instr, unsigned src, unsigned num_components)
return true;
}
+static inline bool
+is_used_more_than_once(nir_alu_instr *instr)
+{
+ bool zero_if_use = list_empty(&instr->dest.dest.ssa.if_uses);
+ bool zero_use = list_empty(&instr->dest.dest.ssa.uses);
+
+ if (zero_use && zero_if_use)
+ return false;
+ else if (zero_use && list_is_singular(&instr->dest.dest.ssa.if_uses))
+ return false;
+ else if (zero_if_use && list_is_singular(&instr->dest.dest.ssa.uses))
+ return false;
+
+ return true;
+}
+
#endif /* _NIR_SEARCH_ */
--
2.9.3
More information about the mesa-dev
mailing list