glsl: Optimize pow(x, 2) into x * x.
authorMatt Turner <mattst88@gmail.com>
Fri, 28 Feb 2014 21:33:19 +0000 (13:33 -0800)
committerMatt Turner <mattst88@gmail.com>
Wed, 19 Mar 2014 06:20:29 +0000 (23:20 -0700)
Cuts two instructions out of SynMark's Gl32VSInstancing benchmark.

Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/opt_algebraic.cpp

index 5c49a785ccd6f1f1e873469aabb4e49f9530febb..8494bd9ec539f21ac2a912fea225a60f86829de5 100644 (file)
@@ -528,6 +528,14 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       if (is_vec_two(op_const[0]))
          return expr(ir_unop_exp2, ir->operands[1]);
 
+      if (is_vec_two(op_const[1])) {
+         ir_variable *x = new(ir) ir_variable(ir->operands[1]->type, "x",
+                                              ir_var_temporary);
+         base_ir->insert_before(x);
+         base_ir->insert_before(assign(x, ir->operands[0]));
+         return mul(x, x);
+      }
+
       break;
 
    case ir_unop_rcp: