[Mesa-dev] [PATCH 2/2] glsl: Make opt_copy_propagation_elements actually propagate into loops.

Kenneth Graunke kenneth at whitecape.org
Wed Jun 1 04:20:23 UTC 2016


We've had a FINISHME here since Eric originally wrote the code in 2011.
This patch implements his suggested approach, which makes us actually
able to copy propagate into the loops, at the unfortunate cost of making
this pass even more expensive.

The shader-db statistics are basically a wash:

   No change in instruction counts.

   total cycles in shared programs: 78685980 -> 78680730 (-0.01%)
   cycles in affected programs: 2102646 -> 2097396 (-0.25%)
   helped: 48
   HURT: 83

I figured if we're going to do this for one copy propagation pass,
we may as well do it in both.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/compiler/glsl/opt_copy_propagation_elements.cpp | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/opt_copy_propagation_elements.cpp b/src/compiler/glsl/opt_copy_propagation_elements.cpp
index e9e7c53..e4237cc 100644
--- a/src/compiler/glsl/opt_copy_propagation_elements.cpp
+++ b/src/compiler/glsl/opt_copy_propagation_elements.cpp
@@ -106,6 +106,7 @@ public:
       ralloc_free(mem_ctx);
    }
 
+   void handle_loop(ir_loop *, bool keep_acp);
    virtual ir_visitor_status visit_enter(class ir_loop *);
    virtual ir_visitor_status visit_enter(class ir_function_signature *);
    virtual ir_visitor_status visit_leave(class ir_assignment *);
@@ -374,8 +375,8 @@ ir_copy_propagation_elements_visitor::visit_enter(ir_if *ir)
    return visit_continue_with_parent;
 }
 
-ir_visitor_status
-ir_copy_propagation_elements_visitor::visit_enter(ir_loop *ir)
+void
+ir_copy_propagation_elements_visitor::handle_loop(ir_loop *ir, bool keep_acp)
 {
    exec_list *orig_acp = this->acp;
    exec_list *orig_kills = this->kills;
@@ -389,6 +390,13 @@ ir_copy_propagation_elements_visitor::visit_enter(ir_loop *ir)
    this->kills = new(mem_ctx) exec_list;
    this->killed_all = false;
 
+   if (keep_acp) {
+      /* Populate the initial acp with a copy of the original */
+      foreach_in_list(acp_entry, a, orig_acp) {
+         this->acp->push_tail(new(this->acp) acp_entry(a));
+      }
+   }
+
    visit_list_elements(this, &ir->body_instructions);
 
    if (this->killed_all) {
@@ -406,6 +414,13 @@ ir_copy_propagation_elements_visitor::visit_enter(ir_loop *ir)
    }
 
    ralloc_free(new_kills);
+}
+
+ir_visitor_status
+ir_copy_propagation_elements_visitor::visit_enter(ir_loop *ir)
+{
+   handle_loop(ir, false);
+   handle_loop(ir, true);
 
    /* already descended into the children. */
    return visit_continue_with_parent;
-- 
2.8.3



More information about the mesa-dev mailing list