glsl: Optimize abs(-expr) and abs(abs(expr)) into abs(expr).
authorMatt Turner <mattst88@gmail.com>
Wed, 16 Oct 2013 23:56:44 +0000 (16:56 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 22 Oct 2013 05:53:36 +0000 (22:53 -0700)
Reviewed-by: Paul Berry <stereotype441@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/opt_algebraic.cpp

index b915f3c429b46c01d5bddc6f253caff305dcd47c..9b0596cd71a55aa79d20a61bd01c3f010c90f5b0 100644 (file)
@@ -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;