Mesa (master): glsl: Optimize (not A) and (not B) into not (A or B).

Matt Turner mattst88 at kemper.freedesktop.org
Fri Oct 25 17:35:29 UTC 2013


Module: Mesa
Branch: master
Commit: 64c081e8b788ba87c9edc505127b87c3fba47599
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=64c081e8b788ba87c9edc505127b87c3fba47599

Author: Matt Turner <mattst88 at gmail.com>
Date:   Wed Oct 23 16:42:34 2013 -0700

glsl: Optimize (not A) and (not B) into not (A or B).

No shader-db changes, but seems like a good idea.

Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/glsl/opt_algebraic.cpp |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 22d2dbf..1351904 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -401,6 +401,15 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       } else if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) {
 	 this->progress = true;
 	 return ir_constant::zero(mem_ctx, ir->type);
+      } else if (op_expr[0] && op_expr[0]->operation == ir_unop_logic_not &&
+                 op_expr[1] && op_expr[1]->operation == ir_unop_logic_not) {
+         /* De Morgan's Law:
+          *    (not A) and (not B) === not (A or B)
+          */
+         temp = logic_not(logic_or(op_expr[0]->operands[0],
+                                   op_expr[1]->operands[0]));
+         this->progress = true;
+         return swizzle_if_required(ir, temp);
       }
       break;
 




More information about the mesa-commit mailing list