<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 10, 2017 at 1:10 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, Oct 10, 2017 at 9:16 AM, Connor Abbott <span dir="ltr"><<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm a little nervous about this, because really, the only solution to<br>
this problem is to ignore all non-WE_all definitions of all variables<br>
in liveness analysis. For example, in something like:<br>
<br>
vec4 color2 = ...<br>
if (...) {<br>
   color2 = texture();<br>
}<br>
<br>
texture() can also overwrite inactive channels of color2. We happen to<br>
get this right because we turn live ranges into live intervals without<br>
holes, but I can't come up with a good reason why that would save us<br>
in all cases except the one in this patch -- which makes me worry that<br>
we'll find yet another case where there's a similar problem. I think<br>
it would be clearer if we what I said above, i.e. ignore all<br>
non-WE_all definitions, which will make things much worse, but then<br>
apply Curro's patch which will return things to pretty much how they<br>
were before, except this case will be fixed and maybe some other cases<br>
we haven't thought of.<br></blockquote><div><br></div></span><div>What you're suggesting may actually be less code and is arguably better in terms of being more straightforward.  However, I think intervals plus this patch is equivalent.  Curro's patch + always-partial will cause us to start the live range at the IP where it first *may* be defined and we keep the behavior of ending the live range at the last IP where some reachable instruction may use it.  With my patch + Curro's, we start the live range at the IP where it is first defined which will always all places it *may* be defined unless there is a back edge.  If there is a back-edge, I pull the live range up across the back edge.</div><div><br></div><div>That said, I think I agree with you that my solution treats it as a special case and not a general problem.  However, I'm relucant to just change liveness analysis to assume partial writes because we use it for more than computing variable interference.  In particular, we use it for dead code elimination and the concept of partial/complete writes is crucial there.  I've got another patch cooking which I'll send out soon which should make you happier with it.</div></div></div></div></blockquote><div><br></div><div>Forget the other patch I have cooking.  It came out burned. :-(  At the moment, I have no better plan than the one in this patch.  Every "more general" thing I've tried today has ended up extending the live ranges far further than needed and making hash of shader-db.  The more I think about it, the more I only see two solutions:</div><div><br></div><div> 1) Take advantage of structure like this patch does.  I really don't think there's anything wrong, given that we have a structured IR, in thinking of it in a structured way.<br></div><div><br></div><div> 2) Go fully for the dual-liveness model. Have what amounts to a virtual "physical" CFG which is just the logical CFG with some edges added and have "physical" livein/out sets which model the conflicting version.  The tricky part would be to get the physical CFG right.  You would need at least:</div><div><br></div><div>    a) Edges from each break to the block after the break like the first attempt</div><div><br></div><div>    b) Same thing for the continues</div><div><br></div><div>    c) Edges from the then block into the else block (this shouldn't actually matter thanks to intervals but we may as well)</div><div><br></div><div>    d) An edge from the top of every loop to the bottom to simulate going through the entire loop as a disabled channel.  You can think of this as putting the entire contents of the loop in a virtual "if" statement.<br></div><div><br></div><div>I believe what was missing from the patch I sent out first was actually edge d.  It's all well and good to get to the point where the def is available at the top of the loop (which a) does) but it's another thing entirely to say that there's a path from the top to the bottom where nothing in the middle has a chance to kill it.  The thing I don't like about option 2 is that it's still taking advantage of structure, it's just adds enough compiler theory language on top to confuse things to the point where you almost can't see it.  We may be able to come up with a model that's truly unstructured but I'd need to think long and hard about how unstructured SIMD control flow works.<br></div><div><br></div><div>Thoughts?  Curro, I'm happy for you to chime in too now that you're back.</div><div><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="HOEnZb"><font color="#888888"><div>--Jason<br></div></font></span><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_973678921657474435m_8147699526858001451h5">
<br>
On Thu, Oct 5, 2017 at 2:52 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> wrote:<br>
> No Shader-db changes.<br>
><br>
> Cc: <a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank">mesa-stable@lists.freedesktop.<wbr>org</a><br>
> ---<br>
>  src/intel/compiler/brw_fs_live<wbr>_variables.cpp | 55 ++++++++++++++++++++++++++++<br>
>  1 file changed, 55 insertions(+)<br>
><br>
> diff --git a/src/intel/compiler/brw_fs_li<wbr>ve_variables.cpp b/src/intel/compiler/brw_fs_li<wbr>ve_variables.cpp<br>
> index c449672..380060d 100644<br>
> --- a/src/intel/compiler/brw_fs_li<wbr>ve_variables.cpp<br>
> +++ b/src/intel/compiler/brw_fs_li<wbr>ve_variables.cpp<br>
> @@ -223,6 +223,61 @@ fs_live_variables::compute_sta<wbr>rt_end()<br>
>           }<br>
>        }<br>
>     }<br>
> +<br>
> +   /* Due to the explicit way the SIMD data is handled on GEN, we need to be a<br>
> +    * bit more careful with live ranges and loops.  Consider the following<br>
> +    * example:<br>
> +    *<br>
> +    *    vec4 color2;<br>
> +    *    while (1) {<br>
> +    *       vec4 color = texture();<br>
> +    *       if (...) {<br>
> +    *          color2 = color * 2;<br>
> +    *          break;<br>
> +    *       }<br>
> +    *    }<br>
> +    *    gl_FragColor = color2;<br>
> +    *<br>
> +    * In this case, the definition of color2 dominates the use because the<br>
> +    * loop only has the one exit.  This means that the live range interval for<br>
> +    * color2 goes from the statement in the if to it's use below the loop.<br>
> +    * Now suppose that the texture operation has a header register that gets<br>
> +    * assigned one of the registers used for color2.  If the loop condition is<br>
> +    * non-uniform and some of the threads will take the and others will<br>
> +    * continue.  In this case, the next pass through the loop, the WE_all<br>
> +    * setup of the header register will stomp the disabled channels of color2<br>
> +    * and corrupt the value.<br>
> +    *<br>
> +    * This same problem can occur if you have a mix of 64, 32, and 16-bit<br>
> +    * registers because the channels do not line up or if you have a SIMD16<br>
> +    * program and the first half of one value overlaps the second half of the<br>
> +    * other.<br>
> +    *<br>
> +    * To solve this problem, we take any VGRFs whose live ranges cross the<br>
> +    * while instruction of a loop and extend their live ranges to the top of<br>
> +    * the loop.  This more accurately models the hardware because the value in<br>
> +    * the VGRF needs to be carried through subsequent loop iterations in order<br>
> +    * to remain valid when we finally do break.<br>
> +    */<br>
> +   foreach_block (block, cfg) {<br>
> +      if (block->end()->opcode != BRW_OPCODE_WHILE)<br>
> +         continue;<br>
> +<br>
> +      /* This is a WHILE instrution. Find the DO block. */<br>
> +      bblock_t *do_block = NULL;<br>
> +      foreach_list_typed(bblock_link<wbr>, child_link, link, &block->children) {<br>
> +         if (child_link->block->start_ip < block->end_ip) {<br>
> +            assert(do_block == NULL);<br>
> +            do_block = child_link->block;<br>
> +         }<br>
> +      }<br>
> +      assert(do_block);<br>
> +<br>
> +      for (int i = 0; i < num_vars; i++) {<br>
> +         if (start[i] < block->end_ip && end[i] > block->end_ip)<br>
> +            start[i] = MIN2(start[i], do_block->start_ip);<br>
> +      }<br>
> +   }<br>
>  }<br>
><br>
>  fs_live_variables::fs_live_var<wbr>iables(fs_visitor *v, const cfg_t *cfg)<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>