glsl: Avoid excessive loop unrolling.

Avoid unrollong loops that are either nested loops or
where the loop body times the unroll count is huge.

The change is far from being perfect but it extends the
loop unrolling decision heuristic by some additional
safeguard. In particular this cuts down compilation of
a shader precomputing atmospheric scattering integral
tables containing two nesting levels in a loop from
something way beyond some minutes (I never waited for
it to finish) to some fractions of a second.

This fixes piglit tests glsl-fs-unroll-explosion and
glsl-vs-unroll-explosion on r600g.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
This commit is contained in:
Mathias Fröhlich 2012-01-25 17:35:01 +01:00
parent ea228d97f8
commit 67007080b7
1 changed files with 15 additions and 0 deletions

View File

@ -56,6 +56,7 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
{
loop_variable_state *const ls = this->state->get(ir);
int iterations;
unsigned ir_count;
/* If we've entered a loop that hasn't been analyzed, something really,
* really bad has happened.
@ -78,6 +79,20 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
if (iterations > (int) max_iterations)
return visit_continue;
/* Don't try to unroll nested loops and loops with a huge body.
*/
ir_count = 0;
foreach_list(node, &ir->body_instructions) {
++ir_count;
/* If the loop body gets to huge, do not unroll. */
if (5*max_iterations < ir_count*iterations)
return visit_continue;
/* Do not unroll loops with child loop nodes. */
if (((ir_instruction *) node)->as_loop())
return visit_continue;
}
if (ls->num_loop_jumps > 1)
return visit_continue;
else if (ls->num_loop_jumps) {