aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl/opt_algebraic.cpp')
-rw-r--r--mesalib/src/glsl/opt_algebraic.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/mesalib/src/glsl/opt_algebraic.cpp b/mesalib/src/glsl/opt_algebraic.cpp
index a07e153ae..05a589989 100644
--- a/mesalib/src/glsl/opt_algebraic.cpp
+++ b/mesalib/src/glsl/opt_algebraic.cpp
@@ -357,7 +357,6 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
break;
case ir_binop_logic_and:
- /* FINISHME: Also simplify (a && a) to (a). */
if (is_vec_one(op_const[0])) {
return ir->operands[1];
} else if (is_vec_one(op_const[1])) {
@@ -371,11 +370,13 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
*/
return logic_not(logic_or(op_expr[0]->operands[0],
op_expr[1]->operands[0]));
+ } else if (ir->operands[0]->equals(ir->operands[1])) {
+ /* (a && a) == a */
+ return ir->operands[0];
}
break;
case ir_binop_logic_xor:
- /* FINISHME: Also simplify (a ^^ a) to (false). */
if (is_vec_zero(op_const[0])) {
return ir->operands[1];
} else if (is_vec_zero(op_const[1])) {
@@ -384,11 +385,13 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
return logic_not(ir->operands[1]);
} else if (is_vec_one(op_const[1])) {
return logic_not(ir->operands[0]);
+ } else if (ir->operands[0]->equals(ir->operands[1])) {
+ /* (a ^^ a) == false */
+ return ir_constant::zero(mem_ctx, ir->type);
}
break;
case ir_binop_logic_or:
- /* FINISHME: Also simplify (a || a) to (a). */
if (is_vec_zero(op_const[0])) {
return ir->operands[1];
} else if (is_vec_zero(op_const[1])) {
@@ -407,6 +410,9 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
*/
return logic_not(logic_and(op_expr[0]->operands[0],
op_expr[1]->operands[0]));
+ } else if (ir->operands[0]->equals(ir->operands[1])) {
+ /* (a || a) == a */
+ return ir->operands[0];
}
break;
@@ -414,10 +420,11 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp)
return op_expr[0]->operands[0];
- /* FINISHME: We should do rcp(rsq(x)) -> sqrt(x) for some
- * backends, except that some backends will have done sqrt ->
- * rcp(rsq(x)) and we don't want to undo it for them.
+ /* While ir_to_mesa.cpp will lower sqrt(x) to rcp(rsq(x)), it does so at
+ * its IR level, so we can always apply this transformation.
*/
+ if (op_expr[0] && op_expr[0]->operation == ir_unop_rsq)
+ return sqrt(op_expr[0]->operands[0]);
/* As far as we know, all backends are OK with rsq. */
if (op_expr[0] && op_expr[0]->operation == ir_unop_sqrt) {