[Mesa-dev] Mesa (master): loop_unroll: unroll loops with (lowered) breaks

Brian Paul brianp at vmware.com
Tue Sep 14 08:07:45 PDT 2010


On 09/13/2010 07:00 PM, Ian Romanick wrote:
> Module: Mesa
> Branch: master
> Commit: 2cdbced10d98214616bcc5f960b21185c433d23b
> URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2cdbced10d98214616bcc5f960b21185c433d23b
>
> Author: Luca Barbieri<luca at luca-barbieri.com>
> Date:   Tue Sep  7 17:03:43 2010 +0200
>
> loop_unroll: unroll loops with (lowered) breaks
>
> If the loop ends with an if with one break or in a single break unroll
> it.  Loops that end with a continue will have that continue removed by
> the redundant jump optimizer.  Likewise loops that end with an
> if-statement with a break at the end of both branches will have the
> break pulled out after the if-statement.
>
> Loops of the form
>
>     for (...) {
>        do_something1();
>        if (cond) {
> 	 do_something2();
> 	 break;
>        } else {
> 	 do_something3();
>        }
>     }
>
> will be unrolled as
>
>     do_something1();
>     if (cond) {
>        do_something2();
>     } else {
>        do_something3();
>        do_something1();
>        if (cond) {
> 	 do_something2();
>        } else {
> 	 do_something3();
> 	 /* Repeat inserting iterations here.*/
>        }
>     }
>
> ir_lower_jumps can guarantee that all loops are put in this form
> and thus all loops are now potentially unrollable if an upper bound
> on the number of iterations can be found.

It would be nice if the example above was in a comment in the 
loop_unroll.cpp file.  Similarly, it would be nice if there were 
comments/examples showing the transformation done by each of the 
(non-trivial) lowering passes.  I think that'd help people better 
understand what's going on.

-Brian




More information about the mesa-dev mailing list