[Mesa-dev] [PATCH 09/10] glsl: Optimize A - neg(B) == A + B
thomashelland90 at gmail.com
thomashelland90 at gmail.com
Mon Jul 14 15:22:38 PDT 2014
From: Thomas Helland <thomashelland90 at gmail.com>
...and neg(A) - B == neg(A + B)
Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
---
src/glsl/opt_algebraic.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 2361d0f..fba9de6 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -454,6 +454,12 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
/* X - X == 0 */
if (ir->operands[0]->equals(ir->operands[1]))
return ir_constant::zero(ir, ir->type);
+ /* A - neg(B) = A + B */
+ if (op_expr[1] && op_expr[1]->operation == ir_unop_neg)
+ return add(ir->operands[0], op_expr[1]->operands[0]);
+ /* neg(A) - B = neg(A + B) */
+ if (op_expr[0] && op_expr[0]->operation == ir_unop_neg)
+ return neg(add(op_expr[0]->operands[0], ir->operands[1]));
break;
case ir_binop_mul:
--
2.0.0
More information about the mesa-dev
mailing list