Mesa (master): glsl: Avoid making a temporary for lower_mat_op_to_vec if not needed.

Eric Anholt anholt at kemper.freedesktop.org
Wed Jun 29 15:23:14 PDT 2011


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

Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 24 12:20:09 2011 -0700

glsl: Avoid making a temporary for lower_mat_op_to_vec if not needed.

Our copy propagation tends to be bad at handling the later array
accesses of the matrix argument we moved to a temporary.  Generally we
don't need to move it to a temporary, though, so this avoids needing
more copy propagation complexity.

Reduces instruction count of some Unigine Tropics and Sanctuary
fragment shaders that do operations on uniform matrix arrays by 5.9%
on gen6.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/lower_mat_op_to_vec.cpp |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/glsl/lower_mat_op_to_vec.cpp b/src/glsl/lower_mat_op_to_vec.cpp
index fe89802..9d593f9 100644
--- a/src/glsl/lower_mat_op_to_vec.cpp
+++ b/src/glsl/lower_mat_op_to_vec.cpp
@@ -329,7 +329,18 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
     */
    for (i = 0; i < orig_expr->get_num_operands(); i++) {
       ir_assignment *assign;
+      ir_dereference *deref = orig_expr->operands[i]->as_dereference();
 
+      /* Avoid making a temporary if we don't need to to avoid aliasing. */
+      if (deref &&
+	  deref->variable_referenced() != result->variable_referenced()) {
+	 op[i] = deref;
+	 continue;
+      }
+
+      /* Otherwise, store the operand in a temporary generally if it's
+       * not a dereference.
+       */
       ir_variable *var = new(mem_ctx) ir_variable(orig_expr->operands[i]->type,
 						  "mat_op_to_vec",
 						  ir_var_temporary);



More information about the mesa-commit mailing list