[Mesa-dev] [PATCH 2/3] glsl: Optimize abs(-expr) and abs(abs(expr)) into abs(expr).

Matt Turner mattst88 at gmail.com
Thu Oct 17 01:56:44 CEST 2013


---
 src/glsl/opt_algebraic.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index b915f3c..9b0596c 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;
 
-- 
1.8.3.2



More information about the mesa-dev mailing list