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

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


From: Thomas Helland <thomashelland90 at gmail.com>

v1 -> v2: Correct indentation

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 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..67326c5 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.3



More information about the mesa-dev mailing list