summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2013-10-16 16:56:44 -0700
committerMatt Turner <[email protected]>2013-10-21 22:53:36 -0700
commit963df4d37da7a7a1ee02cf26e142386a62a611f8 (patch)
treeb43242309a457cc8294579521741cc191e5a784b
parent5b3aec412e1bcbc19b492a2ddd0ce0322acea5f6 (diff)
glsl: Optimize abs(-expr) and abs(abs(expr)) into abs(expr).
Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
-rw-r--r--src/glsl/opt_algebraic.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index b915f3c429b..9b0596cd71a 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -210,6 +210,24 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
this->mem_ctx = ralloc_parent(ir);
switch (ir->operation) {
+ case ir_unop_abs:
+ if (op_expr[0] == NULL)
+ break;
+
+ switch (op_expr[0]->operation) {
+ case ir_unop_abs:
+ case ir_unop_neg:
+ this->progress = true;
+ temp = new(mem_ctx) ir_expression(ir_unop_abs,
+ ir->type,
+ op_expr[0]->operands[0],
+ NULL);
+ return swizzle_if_required(ir, temp);
+ default:
+ break;
+ }
+ break;
+
case ir_unop_logic_not: {
enum ir_expression_operation new_op = ir_unop_logic_not;