summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2015-02-27 22:15:43 -0800
committerIan Romanick <ian.d.romanick@intel.com>2015-03-11 10:13:11 -0700
commitc34a12ad7f51be309d0b09c6a803c1da4824a216 (patch)
treeadcae6f114abe07a31a4c39d4b1f548a0c00655c
parentb9f3331e3bef27250470e5931a09ec97e6cf35e9 (diff)
glsl: Distribute ir_unop_neg over ir_binop_mul of a constantbool-optimizations-v5
-rw-r--r--src/glsl/opt_algebraic.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 9a3c10cc2b4..efa955c35fe 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -443,6 +443,27 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
if (op_expr[0]->operation == ir_unop_neg) {
return op_expr[0]->operands[0];
}
+
+ /* Replace -(x * constant) with (x * -constant).
+ */
+ if (op_expr[0]->operation == ir_binop_mul) {
+ for (i = 0; i < 2; i++) {
+ if (op_expr[0]->operands[i]->as_constant()) {
+ ir_expression *const tmp_expr =
+ new(mem_ctx) ir_expression(ir_unop_neg,
+ op_expr[0]->operands[i]);
+
+ /* Constant-fold the expression now to (possibly) save an
+ * interation through the optimization loop.
+ */
+ op_expr[0]->operands[i] =
+ tmp_expr->constant_expression_value();
+
+ assert(op_expr[0]->operands[i] != NULL);
+ return op_expr[0];
+ }
+ }
+ }
break;
case ir_unop_exp: