summaryrefslogtreecommitdiffstats
path: root/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2015-02-10 12:31:37 -0800
committerMatt Turner <mattst88@gmail.com>2015-02-10 17:48:44 -0800
commitea0f0eb6c0a8b20bcce50c63170df94892a51142 (patch)
treebc45fafd47f685fdc1774b671f27a196dbade54f /src/glsl/opt_algebraic.cpp
parenta9065cef4879509c3dc96a5195f785647576f409 (diff)
downloadexternal_mesa3d-ea0f0eb6c0a8b20bcce50c63170df94892a51142.zip
external_mesa3d-ea0f0eb6c0a8b20bcce50c63170df94892a51142.tar.gz
external_mesa3d-ea0f0eb6c0a8b20bcce50c63170df94892a51142.tar.bz2
glsl: Optimize 1/exp(x) into exp(-x).
Lots of shaders divide by exp2(...) which we turn into a multiplication by the reciprocal. We can avoid the reciprocal by simply negating exp2's argument. total instructions in shared programs: 5947154 -> 5946695 (-0.01%) instructions in affected programs: 118661 -> 118202 (-0.39%) helped: 380 Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Diffstat (limited to 'src/glsl/opt_algebraic.cpp')
-rw-r--r--src/glsl/opt_algebraic.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index c6f4a9c..616ed37 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -747,6 +747,12 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp)
return op_expr[0]->operands[0];
+ if (op_expr[0] && (op_expr[0]->operation == ir_unop_exp2 ||
+ op_expr[0]->operation == ir_unop_exp)) {
+ return new(mem_ctx) ir_expression(op_expr[0]->operation, ir->type,
+ neg(op_expr[0]->operands[0]));
+ }
+
/* While ir_to_mesa.cpp will lower sqrt(x) to rcp(rsq(x)), it does so at
* its IR level, so we can always apply this transformation.
*/