[Mesa-dev] [PATCH v2 04/11] glsl: Optimize (A || B) && A == A

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


From: Thomas Helland <thomashelland90 at gmail.com>

And it's cousins

v1 -> v2: Correct indentation
          Correct returned operand from second if statement

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 src/glsl/opt_algebraic.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index cdabdb8..42a70e3 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -559,6 +559,16 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
                  ir->operands[0]->equals(op_expr[1]->operands[0])) {
          /* A && !A == 0 */
          return ir_constant::zero(mem_ctx, ir->type);
+      } else if (op_expr[0] && op_expr[0]->operation == ir_binop_logic_or &&
+                 (op_expr[0]->operands[0]->equals(ir->operands[1]) ||
+                  op_expr[0]->operands[1]->equals(ir->operands[1]))) {
+         /* (A || B) && A == A or (B || A) && A == A */
+         return ir->operands[1];
+      } else if (op_expr[1] && op_expr[1]->operation == ir_binop_logic_or &&
+                 (op_expr[1]->operands[0]->equals(ir->operands[0]) ||
+                  op_expr[1]->operands[1]->equals(ir->operands[0]))) {
+         /* A && (A || B) == A or A && (B || A) == A */
+         return ir->operands[0];
       }
       break;
 
-- 
2.0.3



More information about the mesa-dev mailing list