[Mesa-dev] [PATCH v2 01/11] glsl: Optimize X - X == 0

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


From: Thomas Helland <thomashelland90 at gmail.com>

v1 -> v2: Corrected indentation.

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 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 ac7514a..c179d53 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -439,6 +439,9 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
 	 return neg(ir->operands[1]);
       if (is_vec_zero(op_const[1]))
 	 return ir->operands[0];
+      /* X - X == 0 */
+      if (ir->operands[0]->equals(ir->operands[1]))
+         return ir_constant::zero(ir, ir->type);
       break;
 
    case ir_binop_mul:
-- 
2.0.3



More information about the mesa-dev mailing list