glsl: Speed up constant folding for swizzles

Graphics / Mesa 3D Graphics Library / Mesa - Kenneth Graunke [whitecape.org] - 12 September 2014 18:35 UTC

ir_rvalue::constant_expression_value() recursively walks down an IR tree, attempting to reduce it to a single constant value. This is useful when you want to know whether a variable has a constant expression value at all, and if so, what it is.

The constant folding optimization pass attempts to replace rvalues with their constant expression value from the bottom up. That way, we can optimize subexpressions, and ideally stop as soon as we find a non-constant subexpression.

In order to obtain the actual value of an expression, the optimization pass calls constant_expression_value(). But it should only do so if it knows the value can be combined into a constant. Otherwise, at each step of walking back up the tree, it will walk down the tree again, only to discover what it already knew: it isn't constant.

We properly avoided this call for ir_expression nodes, but not for ir_swizzle nodes. This patch fixes that, drastically reducing compile times on certain shaders where tree grafting has given us huge expression trees. It also fixes SuperTuxKart.

Thanks to Iago and Mike for help in tracking this down.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=78468

84a40ce glsl: Speed up constant folding for swizzles.
src/glsl/opt_constant_folding.cpp | 5 +++++
1 file changed, 5 insertions(+)

Upstream: cgit.freedesktop.org


  • Share