[Mesa-dev] [PATCH v2 08/11] glsl: Optimize A - neg(B) = A + B

thomashelland90 at gmail.com thomashelland90 at gmail.com
Thu Aug 7 13:51:09 PDT 2014


From: Thomas Helland <thomashelland90 at gmail.com>

v1 -> v2: Drop the neg(A) - B == neg(A+B) part

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
---
 src/glsl/opt_algebraic.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 0ecadbe..c673495 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -454,6 +454,9 @@ 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]);
       break;
 
    case ir_binop_mul:
-- 
2.0.3



More information about the mesa-dev mailing list