[Mesa-dev] [PATCH 12/13] nir: add a loop unrolling pass

Connor Abbott cwabbott0 at gmail.com
Tue Aug 30 05:58:20 UTC 2016


On Tue, Aug 30, 2016 at 12:40 AM, Matt Turner <mattst88 at gmail.com> wrote:
> On Mon, Aug 29, 2016 at 9:06 PM, Timothy Arceri
> <timothy.arceri at collabora.com> wrote:
>> Can't the phi have more than one source from before the loop? e.g
>>
>>    int i = 0;
>>    if (somthing)
>>      i = 1;
>>    else
>>      i = 2;
>>
>>    for ( ; i < 5; i++)
>>       do_stuff(i);
>
> In fact, no. :)
>
> NIR's control flow avoids so-called "critical edges" by ensuring that
> all if/else must be preceded by a single basic block and followed by a
> single basic block. It simplifies a lot of situations. This invariant
> and a few more are documented at the top of nir_control_flow.c.
>
> In your example, there will be a basic block between the end of the
> if/else construct and the beginning of the loop which will contain a
> phi node for i.
>
> phi nodes only have as many sources as its containing basic block has
> incoming edges. There are only two ways (that I can think of) that a
> block may have more than two incoming edges in NIR: multiple break or
> continue statements in a loop.

Matt is exactly right here... FWIW, I wrote up more details on NIR
control flow at
https://people.freedesktop.org/~cwabbott0/nir-docs/control_flow.html#the-nir-control-flow-model
(although I need to rebase my series and update the control flow
modification part... hmm).


More information about the mesa-dev mailing list