[Mesa-dev] [PATCH 03/10] glsl: Optimize !A && A == 0

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


From: Thomas Helland <thomashelland90 at gmail.com>

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

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 385f0a2..748fd05 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -551,6 +551,14 @@ 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 == 0 */
+         return ir_constant::zero(mem_ctx, ir->type);
+      } else if (op_expr[1] && op_expr[1]->operation == ir_unop_logic_not &&
+                 ir->operands[0]->equals(op_expr[1]->operands[0])) {
+         /* A && !A == 0 */
+         return ir_constant::zero(mem_ctx, ir->type);
       }
       break;
 
-- 
2.0.0



More information about the mesa-dev mailing list