summaryrefslogtreecommitdiffstats
path: root/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2015-03-16 21:33:31 -0700
committerMatt Turner <[email protected]>2015-04-24 11:39:01 -0700
commit9b577d57029bb643f2b48b80648b4f901818e93b (patch)
tree6f26080e4c237304c8aeed14e395580d76ebbbd3 /src/glsl/opt_algebraic.cpp
parent18f44d303014c3c16084c1b15d1999833e0d55db (diff)
glsl: Transform pow(x, 4) into (x*x)*(x*x).
Reviewed-by: Juha-Pekka Heikkila <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/glsl/opt_algebraic.cpp')
-rw-r--r--src/glsl/opt_algebraic.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 3d2f2ca0bab..fa5db70f2dd 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -99,6 +99,12 @@ is_vec_two(ir_constant *ir)
}
static inline bool
+is_vec_four(ir_constant *ir)
+{
+ return (ir == NULL) ? false : ir->is_value(4.0, 4);
+}
+
+static inline bool
is_vec_negative_one(ir_constant *ir)
{
return (ir == NULL) ? false : ir->is_negative_one();
@@ -774,6 +780,20 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
return mul(x, x);
}
+ if (is_vec_four(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]));
+
+ ir_variable *squared = new(ir) ir_variable(ir->operands[1]->type,
+ "squared",
+ ir_var_temporary);
+ base_ir->insert_before(squared);
+ base_ir->insert_before(assign(squared, mul(x, x)));
+ return mul(squared, squared);
+ }
+
break;
case ir_binop_min: