There are a couple of cycle count changes in shader-db, but it's
basically a wash.

However, with the Broadwell scalar TCS backend enabled, many
Shadow of Mordor shaders benefit from this patch.  Because we don't
batch up output writes for TCS, vec4 outputs might not have all
components defined.  Many output writes have a value of undef,
which is useless.

With scalar TCS, stats for tessellation shaders on Broadwell:

total instructions in shared programs: 1283000 -> 1280444 (-0.20%)
instructions in affected programs: 34302 -> 31746 (-7.45%)
helped: 71
HURT: 0

total cycles in shared programs: 10798768 -> 10780682 (-0.17%)
cycles in affected programs: 158004 -> 139918 (-11.45%)
helped: 71
HURT: 0

Signed-off-by: Kenneth Graunke <kenn...@whitecape.org>
---
 src/compiler/nir/nir_opt_undef.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/compiler/nir/nir_opt_undef.c b/src/compiler/nir/nir_opt_undef.c
index a7bb887..c4777a8 100644
--- a/src/compiler/nir/nir_opt_undef.c
+++ b/src/compiler/nir/nir_opt_undef.c
@@ -100,6 +100,33 @@ opt_undef_vecN(nir_builder *b, nir_alu_instr *alu)
    return true;
 }
 
+/**
+ * Remove any store intrinsics whose value is undefined (the existing
+ * value is a fine representation of "undefined").
+ */
+static bool
+opt_undef_store(nir_intrinsic_instr *intrin)
+{
+   switch (intrin->intrinsic) {
+   case nir_intrinsic_store_var:
+   case nir_intrinsic_store_output:
+   case nir_intrinsic_store_per_vertex_output:
+   case nir_intrinsic_store_ssbo:
+   case nir_intrinsic_store_shared:
+      break;
+   default:
+      return false;
+   }
+
+   if (!intrin->src[0].is_ssa ||
+       intrin->src[0].ssa->parent_instr->type != nir_instr_type_ssa_undef)
+      return false;
+
+   nir_instr_remove(&intrin->instr);
+
+   return true;
+}
+
 bool
 nir_opt_undef(nir_shader *shader)
 {
@@ -116,6 +143,9 @@ nir_opt_undef(nir_shader *shader)
 
                   progress = opt_undef_csel(alu) || progress;
                   progress = opt_undef_vecN(&b, alu) || progress;
+               } else if (instr->type == nir_instr_type_intrinsic) {
+                  nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+                  progress = opt_undef_store(intrin) || progress;
                }
             }
          }
-- 
2.8.2

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to