Mesa (master): glsl: Pick ast_conditional branch regardless of op1/ 2 being constant.

Kenneth Graunke kwg at kemper.freedesktop.org
Tue Feb 3 01:15:33 UTC 2015


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Thu Aug 21 21:49:07 2014 -0700

glsl: Pick ast_conditional branch regardless of op1/2 being constant.

If the ?: operator's condition is a constant value, and both branches
were pure expressions, we can just make the resulting value one or the
other.

Previously, we only did this if op[1] and op[2] were also constant
values - but there's no actual reason for that restriction.

No changes in shader-db, probably because we usually optimize this later
anyway.  But it does make us generate less stupid code up front.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/glsl/ast_to_hir.cpp |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 1ba29f7..4d28069 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1597,13 +1597,11 @@ ast_expression::do_hir(exec_list *instructions,
       }
 
       ir_constant *cond_val = op[0]->constant_expression_value();
-      ir_constant *then_val = op[1]->constant_expression_value();
-      ir_constant *else_val = op[2]->constant_expression_value();
 
       if (then_instructions.is_empty()
           && else_instructions.is_empty()
-          && (cond_val != NULL) && (then_val != NULL) && (else_val != NULL)) {
-         result = (cond_val->value.b[0]) ? then_val : else_val;
+          && cond_val != NULL) {
+         result = cond_val->value.b[0] ? op[1] : op[2];
       } else {
          ir_variable *const tmp =
             new(ctx) ir_variable(type, "conditional_tmp", ir_var_temporary);




More information about the mesa-commit mailing list