glsl: Optimize log(exp(x)) and exp(log(x)) into x.
authorEric Anholt <eric@anholt.net>
Sat, 18 Jan 2014 18:47:19 +0000 (10:47 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 7 Feb 2014 20:46:47 +0000 (12:46 -0800)
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/glsl/opt_algebraic.cpp

index 681973dda0ee4c1960814042a7b04f0f11b5c22c..1e715817f765f599c8c54fde10b6e0d9275bca99 100644 (file)
@@ -245,6 +245,42 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       }
       break;
 
+   case ir_unop_exp:
+      if (op_expr[0] == NULL)
+        break;
+
+      if (op_expr[0]->operation == ir_unop_log) {
+         return op_expr[0]->operands[0];
+      }
+      break;
+
+   case ir_unop_log:
+      if (op_expr[0] == NULL)
+        break;
+
+      if (op_expr[0]->operation == ir_unop_exp) {
+         return op_expr[0]->operands[0];
+      }
+      break;
+
+   case ir_unop_exp2:
+      if (op_expr[0] == NULL)
+        break;
+
+      if (op_expr[0]->operation == ir_unop_log2) {
+         return op_expr[0]->operands[0];
+      }
+      break;
+
+   case ir_unop_log2:
+      if (op_expr[0] == NULL)
+        break;
+
+      if (op_expr[0]->operation == ir_unop_exp2) {
+         return op_expr[0]->operands[0];
+      }
+      break;
+
    case ir_unop_logic_not: {
       enum ir_expression_operation new_op = ir_unop_logic_not;