We want to run CSE and algebraic optimizations again after lowering IO.
Some of the passes in the optimization loop don't handle saturates and
other modifiers, so run it before lowering to source modifiers.

total instructions in shared programs: 6046190 -> 6045768 (-0.01%)
instructions in affected programs:     22406 -> 21984 (-1.88%)
helped:                                47
HURT:                                  0
GAINED:                                0
LOST:                                  0

Signed-off-by: Kenneth Graunke <[email protected]>
---
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 34 ++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 13 deletions(-)

I'm not sure about this patch.  It's obviously beneficial, but...
I wonder if we want some kind of optimization loop in core NIR,
along the lines of do_common_optimization.  Right now, NIR seems
like a collection of tools to build your own compile process.
Which works, and the flexibility is nice.  But having everything
in one place isn't a crazy plan either...

diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp 
b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
index 510092e..40a1673 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
@@ -26,20 +26,9 @@
 #include "glsl/nir/glsl_to_nir.h"
 #include "brw_fs.h"
 
-void
-fs_visitor::emit_nir_code()
+static void
+nir_optimize(nir_shader *nir)
 {
-   /* first, lower the GLSL IR shader to NIR */
-   lower_output_reads(shader->base.ir);
-   nir_shader *nir = glsl_to_nir(shader->base.ir, NULL, true);
-   nir_validate_shader(nir);
-
-   nir_lower_global_vars_to_local(nir);
-   nir_validate_shader(nir);
-
-   nir_split_var_copies(nir);
-   nir_validate_shader(nir);
-
    bool progress;
    do {
       progress = false;
@@ -58,6 +47,23 @@ fs_visitor::emit_nir_code()
       progress |= nir_opt_constant_folding(nir);
       nir_validate_shader(nir);
    } while (progress);
+}
+
+void
+fs_visitor::emit_nir_code()
+{
+   /* first, lower the GLSL IR shader to NIR */
+   lower_output_reads(shader->base.ir);
+   nir_shader *nir = glsl_to_nir(shader->base.ir, NULL, true);
+   nir_validate_shader(nir);
+
+   nir_lower_global_vars_to_local(nir);
+   nir_validate_shader(nir);
+
+   nir_split_var_copies(nir);
+   nir_validate_shader(nir);
+
+   nir_optimize(nir);
 
    /* Lower a bunch of stuff */
    nir_lower_var_copies(nir);
@@ -81,6 +87,8 @@ fs_visitor::emit_nir_code()
    nir_lower_atomics(nir);
    nir_validate_shader(nir);
 
+   nir_optimize(nir);
+
    nir_lower_to_source_mods(nir);
    nir_validate_shader(nir);
    nir_copy_prop(nir);
-- 
2.2.2

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to