[Mesa-dev] [PATCH 02/10] glsl: Optimize !A || A == 1

thomashelland90 at gmail.com thomashelland90 at gmail.com
Mon Jul 14 15:22:31 PDT 2014


From: Thomas Helland <thomashelland90 at gmail.com>

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

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index c179d53..385f0a2 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -591,6 +591,18 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       } else if (ir->operands[0]->equals(ir->operands[1])) {
          /* (a || a) == a */
          return ir->operands[0];
+      } else if ( (op_expr[0] && op_expr[0]->operation == ir_unop_logic_not &&
+                  ir->operands[1]->equals(op_expr[0]->operands[0])) || 
+                  /* !A || A == 1 */
+                  (op_expr[1] && op_expr[1]->operation == ir_unop_logic_not &&
+                 ir->operands[0]->equals(op_expr[1]->operands[0])) ) {
+                  /* A || !A == 1 */
+         ir_constant_data data;
+
+	 for (unsigned i = 0; i < 16; i++)
+	    data.b[i] = true;
+
+	 return new(mem_ctx) ir_constant(ir->type, &data);
       }
       break;
 
-- 
2.0.0



More information about the mesa-dev mailing list