Mesa (master): glsl: Skip rewriting instructions in opt_cpe when unnecessary.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Sep 4 00:24:17 UTC 2014


Module: Mesa
Branch: master
Commit: 702b6ea05178388aef22af36a53362212ce9b629
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=702b6ea05178388aef22af36a53362212ce9b629

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Thu Aug 28 15:44:49 2014 -0700

glsl: Skip rewriting instructions in opt_cpe when unnecessary.

Previously, opt_copy_propagation_elements would always rewrite the
instruction stream, even if was the same thing as before.  In order to
report progress correctly, we'll need to bail if the suggested
replacement is identical (or equivalent) to the original code.

This also introduced unnecessary noop swizzles, as far as I can tell.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/glsl/opt_copy_propagation_elements.cpp |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/glsl/opt_copy_propagation_elements.cpp b/src/glsl/opt_copy_propagation_elements.cpp
index f131894..a67f507 100644
--- a/src/glsl/opt_copy_propagation_elements.cpp
+++ b/src/glsl/opt_copy_propagation_elements.cpp
@@ -209,6 +209,7 @@ ir_copy_propagation_elements_visitor::handle_rvalue(ir_rvalue **ir)
    ir_variable *source[4] = {NULL, NULL, NULL, NULL};
    int source_chan[4] = {0, 0, 0, 0};
    int chans;
+   bool noop_swizzle = true;
 
    if (!*ir)
       return;
@@ -250,6 +251,9 @@ ir_copy_propagation_elements_visitor::handle_rvalue(ir_rvalue **ir)
 	    if (entry->write_mask & (1 << swizzle_chan[c])) {
 	       source[c] = entry->rhs;
 	       source_chan[c] = entry->swizzle[swizzle_chan[c]];
+
+               if (source_chan[c] != swizzle_chan[c])
+                  noop_swizzle = false;
 	    }
 	 }
       }
@@ -266,6 +270,12 @@ ir_copy_propagation_elements_visitor::handle_rvalue(ir_rvalue **ir)
    if (!shader_mem_ctx)
       shader_mem_ctx = ralloc_parent(deref_var);
 
+   /* Don't pointlessly replace the rvalue with itself (or a noop swizzle
+    * of itself, which would just be deleted by opt_noop_swizzle).
+    */
+   if (source[0] == var && noop_swizzle)
+      return;
+
    if (debug) {
       printf("Copy propagation from:\n");
       (*ir)->print();




More information about the mesa-commit mailing list