Mesa (master): glsl: Avoid excess tree walking when folding ir_dereference_arrays.

Kenneth Graunke kwg at kemper.freedesktop.org
Mon May 16 07:05:11 UTC 2016


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Fri Apr 29 13:19:33 2016 -0700

glsl: Avoid excess tree walking when folding ir_dereference_arrays.

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 at whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/compiler/glsl/opt_constant_folding.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/compiler/glsl/opt_constant_folding.cpp b/src/compiler/glsl/opt_constant_folding.cpp
index 0ea53a5..ee67420 100644
--- a/src/compiler/glsl/opt_constant_folding.cpp
+++ b/src/compiler/glsl/opt_constant_folding.cpp
@@ -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;




More information about the mesa-commit mailing list