summaryrefslogtreecommitdiffstats
path: root/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2013-10-23 16:40:16 -0700
committerMatt Turner <mattst88@gmail.com>2013-10-25 10:35:13 -0700
commit65a600f58a7a35016e32e9774560b71f675566fd (patch)
tree5af9dedba8488edf50f736dd680946b33bbca091 /src/glsl/opt_algebraic.cpp
parente52959e9612e6e645407c6256d35fac9c8fe3276 (diff)
downloadexternal_mesa3d-65a600f58a7a35016e32e9774560b71f675566fd.zip
external_mesa3d-65a600f58a7a35016e32e9774560b71f675566fd.tar.gz
external_mesa3d-65a600f58a7a35016e32e9774560b71f675566fd.tar.bz2
glsl: Optimize (not A) or (not B) into not (A and B).
A few Serious Sam 3 shaders affected: instructions in affected programs: 4384 -> 4344 (-0.91%) Reviewed-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'src/glsl/opt_algebraic.cpp')
-rw-r--r--src/glsl/opt_algebraic.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 37b2f02..22d2dbf 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -32,8 +32,11 @@
#include "ir_visitor.h"
#include "ir_rvalue_visitor.h"
#include "ir_optimization.h"
+#include "ir_builder.h"
#include "glsl_types.h"
+using namespace ir_builder;
+
namespace {
/**
@@ -436,6 +439,15 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
this->progress = true;
return new(mem_ctx) ir_constant(ir->type, &data);
+ } 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) or (not B) === not (A and B)
+ */
+ temp = logic_not(logic_and(op_expr[0]->operands[0],
+ op_expr[1]->operands[0]));
+ this->progress = true;
+ return swizzle_if_required(ir, temp);
}
break;