Mesa (master): nir: optimise min/max fadd combos
Timothy Arceri
tarceri at kemper.freedesktop.org
Sat Jan 14 12:33:45 UTC 2017
Module: Mesa
Branch: master
Commit: 772cd3104852302aedf87895cef7828ccacedee2
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=772cd3104852302aedf87895cef7828ccacedee2
Author: Timothy Arceri <timothy.arceri at collabora.com>
Date: Thu Jan 12 21:51:56 2017 +1100
nir: optimise min/max fadd combos
shader-db results BDW:
total instructions in shared programs: 13060410 -> 13060313 (-0.00%)
instructions in affected programs: 24533 -> 24436 (-0.40%)
helped: 88
HURT: 0
total cycles in shared programs: 256585692 -> 256586698 (0.00%)
cycles in affected programs: 647290 -> 648296 (0.16%)
helped: 35
HURT: 30
Reviewed-by: Matt Turner <mattst88 at gmail.com>
---
src/compiler/nir/nir_opt_algebraic.py | 4 ++++
src/compiler/nir/nir_search_helpers.h | 22 ++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index a557f7b..d7ad1f2 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -522,6 +522,10 @@ late_optimizations = [
(('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)),
+
+ # we do these late so that we don't get in the way of creating ffmas
+ (('fmin', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmin', a, b))),
+ (('fmax', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmax', a, b))),
]
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 e925a2b..ddaff52 100644
--- a/src/compiler/nir/nir_search_helpers.h
+++ b/src/compiler/nir/nir_search_helpers.h
@@ -131,6 +131,28 @@ is_used_more_than_once(nir_alu_instr *instr)
}
static inline bool
+is_used_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_if_use && zero_use)
+ return false;
+
+ if (!zero_if_use && list_is_singular(&instr->dest.dest.ssa.uses))
+ return false;
+
+ if (!zero_use && list_is_singular(&instr->dest.dest.ssa.if_uses))
+ return false;
+
+ if (!list_is_singular(&instr->dest.dest.ssa.if_uses) &&
+ !list_is_singular(&instr->dest.dest.ssa.uses))
+ return false;
+
+ return true;
+}
+
+static inline bool
is_not_used_by_if(nir_alu_instr *instr)
{
return list_empty(&instr->dest.dest.ssa.if_uses);
More information about the mesa-commit
mailing list