<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Oct 27, 2017 at 5:24 PM, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've submitted an alternative to this approach here [1], more along the<br>
lines of the v1 patch you borrowed from my jenkins branch. Most of the<br>
reasons for that we have discussed already in the office (except for the<br>
last point), but FTR:<br>
<br>
- This patch only works around the problem by tweaking the live<br>
intervals, which makes the live intervals inconsistent with the block<br>
live sets (the latter are used by some back-end passes that this<br>
patch isn't going to help with, like DCE and scheduling).<br></blockquote><div><br></div><div>I'm not sure that's strictly true. It changes the mapping function from the live sets to the liveness intervals but it's still directly computable from live sets + cfg. That said, there is something to be said for treating back-edges specially when computing the live sets.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- This patch doesn't fix the same bug on the VEC4 back-end.<br>
<br>
- I feel that the alternative approach [1] admits more straightforward<br>
extension to more exotic control-flow constructs.<br>
<br>
- It doesn't actually fix the problem for all possible patterns of<br>
divergent loop execution. Consider the following GLSL pseudocode:<br>
<br>
| b = 0;<br>
| do {<br>
| use(b);<br>
| b = non_uniform_condition();<br>
| if (b)<br>
| continue;<br>
|<br>
| stomp_neighboring_channels();<br>
| break;<br>
|<br>
| } while(true);<br>
<br>
With this series applied, the live interval of 'b' will be calculated<br>
to be between the 'b = 0' and 'continue' statements, which allows<br>
stomp_neighboring_channels() to overwrite the contents of 'b'<br>
depending on how the register allocator lays things out in the<br>
register file. OTOH with [1] applied the live interval calculated<br>
for 'b' will be the region between the 'b = 0' and 'break'<br>
statements, which overlaps the whole region of divergent control flow<br>
as expected.<br></blockquote><div><br></div><div>It does handle that case correctly before your patch to add defin/out but not after. :-) This is because we always propagate livein from the top of the loop into the liveout of the while so anything livein at the top automatically gets extended down. We do not, however, propagate defout that way (since the while is not reachable) so your patch breaks it.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Cheers.<br>
<br>
[1] <a href="https://lists.freedesktop.org/archives/mesa-dev/2017-October/174591.html" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>archives/mesa-dev/2017-<wbr>October/174591.html</a><br>
<div><div class="h5"><br>
Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> writes:<br>
<br>
> No Shader-db changes.<br>
><br>
> Cc: <a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.freedesktop.<wbr>org</a><br>
> ---<br>
> src/intel/compiler/brw_fs_<wbr>live_variables.cpp | 55 ++++++++++++++++++++++++++++<br>
> 1 file changed, 55 insertions(+)<br>
><br>
> diff --git a/src/intel/compiler/brw_fs_<wbr>live_variables.cpp b/src/intel/compiler/brw_fs_<wbr>live_variables.cpp<br>
> index c449672..380060d 100644<br>
> --- a/src/intel/compiler/brw_fs_<wbr>live_variables.cpp<br>
> +++ b/src/intel/compiler/brw_fs_<wbr>live_variables.cpp<br>
> @@ -223,6 +223,61 @@ fs_live_variables::compute_<wbr>start_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_<wbr>link, 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_<wbr>variables(fs_visitor *v, const cfg_t *cfg)<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-stable mailing list<br>
> <a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.freedesktop.<wbr>org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-stable" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-stable</a><br>
</blockquote></div><br></div></div>