[Mesa-dev] [PATCH v3 3/3] glsl: propagate full variables eagerly

Caio Marcelo de Oliveira Filho caio.oliveira at intel.com
Wed Jul 25 01:03:41 UTC 2018


When creating a new acp_entry after an assignment "c = b", check if b
itself has an acp_entry with a full variable associated and use
that. This reduces the number of passes the algorithm needs to
propagate a value in a chain of assignments.

I've tried to make a similar change to the write_partial, but it
caused noise in the final output (hurting instruction count). The
reason is for partials, a propagation might imply a swizzle
operation.

We could later investigate if it is worth to restrict the cases we are
eager to avoid getting things worse because of swizzling.
---
 .../glsl/opt_copy_propagation_elements.cpp    | 23 ++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/opt_copy_propagation_elements.cpp b/src/compiler/glsl/opt_copy_propagation_elements.cpp
index cae6d3c0707..c44f7c56f11 100644
--- a/src/compiler/glsl/opt_copy_propagation_elements.cpp
+++ b/src/compiler/glsl/opt_copy_propagation_elements.cpp
@@ -169,8 +169,29 @@ public:
          }
       }
 
+      /* If the rhs has an acp_entry pointing to another full variable, use
+       * that. This allows propagation to happen all in one pass, instead of
+       * having the value walking slowly. E.g.
+       *
+       *     b = a
+       *     c = b
+       *     d = c
+       *     use(d)
+       *
+       * will need one pass to propagate to
+       *
+       *     b = a
+       *     c = a    // Because of b acp_entry.
+       *     d = a    // Because of c acp_entry that uses 'a' directly.
+       *     use(a)   // Because of d acp_entry that uses 'a' directly.
+       */
+      acp_entry *rhs_entry = read(rhs);
+      if (rhs_entry && rhs_entry->rhs_full != NULL) {
+         rhs = rhs_entry->rhs_full;
+      }
+      rhs_entry = pull_acp(rhs);
+
       lhs_entry->rhs_full = rhs;
-      acp_entry *rhs_entry = pull_acp(rhs);
       _mesa_set_add(rhs_entry->dsts, lhs);
 
       if (lhs->type->is_vector()) {
-- 
2.18.0



More information about the mesa-dev mailing list