[Mesa-dev] [PATCH] glsl: Rebalance expression trees that are reduction operations.

Matt Turner mattst88 at gmail.com
Tue Jun 10 17:08:20 PDT 2014


---
Easiest thing for now seems to be to bail if we see these
kinds of dereferences. I'll squash this in, adding a description
of the things we don't handle.

 src/glsl/opt_rebalance_tree.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/glsl/opt_rebalance_tree.cpp b/src/glsl/opt_rebalance_tree.cpp
index 5866a60..773aab3 100644
--- a/src/glsl/opt_rebalance_tree.cpp
+++ b/src/glsl/opt_rebalance_tree.cpp
@@ -167,6 +167,19 @@ is_reduction_operation(ir_expression_operation operation)
 
 /* Note that this function does not attempt to recognize that reduction trees
  * are already balanced.
+ *
+ * We return false from this function for a number of reasons other than an
+ * expression tree not being a mathematical reduction. Namely,
+ *
+ *    - if the tree contains multiple constants that we may be able to combine.
+ *    - if the tree contains matrices:
+ *       - they might contain vec4's with many constant components that we can
+ *         simplify after splitting.
+ *       - applying the matrix chain ordering optimization is more than just
+ *         balancing an expression tree.
+ *    - if the tree contains operations on multiple types.
+ *    - if the tree contains ir_dereference_{array,record}, since foo[a+b] + c
+ *      would trick the visiting pass.
  */
 static void
 is_reduction(ir_instruction *ir, void *data)
@@ -186,6 +199,15 @@ is_reduction(ir_instruction *ir, void *data)
       return;
    }
 
+   /* Array/record dereferences have subtrees that are not part of the expr
+    * tree we're balancing. Skip trees containing them.
+    */
+   if (ir->ir_type == ir_type_dereference_array ||
+       ir->ir_type == ir_type_dereference_record) {
+      ird->is_reduction = false;
+      return;
+   }
+
    ir_expression *expr = ir->as_expression();
    if (!expr)
       return;
-- 
1.8.3.2



More information about the mesa-dev mailing list