[Mesa-dev] [PATCH] nir: shuffle fmuls to allow const evaluation

Timothy Arceri timothy.arceri at collabora.com
Thu Jan 12 03:36:24 UTC 2017


Shader-db results BDW:

total instructions in shared programs: 13059905 -> 13059274 (-0.00%)
instructions in affected programs: 88407 -> 87776 (-0.71%)
helped: 329
HURT: 0

total cycles in shared programs: 256570054 -> 256548062 (-0.01%)
cycles in affected programs: 2308020 -> 2286028 (-0.95%)
helped: 242
HURT: 69

LOST:   1
GAINED: 0
---
 src/compiler/nir/nir_opt_algebraic.py |  3 ++-
 src/compiler/nir/nir_search_helpers.h | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index a557f7b..b5974a7 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -323,9 +323,10 @@ optimizations = [
    (('imul', ('ineg', a), b), ('ineg', ('imul', a, b))),
 
    # Reassociate constants in add/mul chains so they can be folded together.
-   # For now, we only handle cases where the constants are separated by
+   # For now, we mostly only handle cases where the constants are separated by
    # a single non-constant.  We could do better eventually.
    (('~fmul', '#a', ('fmul', b, '#c')), ('fmul', ('fmul', a, c), b)),
+   (('~fmul', '#a', ('fmul(is_used_once)', b, ('fmul(is_used_once)', c, '#d'))), ('fmul', ('fmul', b, ('fmul', a, d)), c)),
    (('imul', '#a', ('imul', b, '#c')), ('imul', ('imul', a, c), b)),
    (('~fadd', '#a', ('fadd', b, '#c')), ('fadd', ('fadd', a, c), b)),
    (('iadd', '#a', ('iadd', b, '#c')), ('iadd', ('iadd', a, c), b)),
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);
-- 
2.9.3



More information about the mesa-dev mailing list