glsl: Avoid excess tree walking when folding ir_dereference_arrays.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 29 Apr 2016 20:19:33 +0000 (13:19 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 16 May 2016 06:59:33 +0000 (23:59 -0700)
If an ir_dereference_array has non-constant components, there's no
point in trying to evaluate its value (which involves walking down
the tree and possibly allocating memory for portions of the subtree
which are constant).

This also removes convoluted tree walking in opt_constant_folding(),
which tries to fold constants while walking up the tree.  No need to
walk down, then up, then down again.

We did this for swizzles and expressions already, but I was lazy
back in the day and didn't do this for ir_dereference_array.

No change in shader-db.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/compiler/glsl/opt_constant_folding.cpp

index 0ea53a5ed1b2020c327882ecf54ce6344294f10c..ee67420adf851fb4d152e0c127983f3a90871a00 100644 (file)
@@ -85,6 +85,12 @@ ir_constant_fold(ir_rvalue **rvalue)
    if (swiz && !swiz->val->as_constant())
       return false;
 
+   /* Ditto for array dereferences */
+   ir_dereference_array *array_ref = (*rvalue)->as_dereference_array();
+   if (array_ref && (!array_ref->array->as_constant() ||
+                     !array_ref->array_index->as_constant()))
+      return false;
+
    ir_constant *constant = (*rvalue)->constant_expression_value();
    if (constant) {
       *rvalue = constant;