<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 23, 2019 at 7:39 PM Timothy Arceri <<a href="mailto:tarceri@itsqueeze.com">tarceri@itsqueeze.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 24/4/19 1:45 am, Samuel Pitoiset wrote:<br>
> <br>
> On 4/23/19 5:16 PM, Jason Ekstrand wrote:<br>
>> On Tue, Apr 23, 2019 at 7:46 AM Samuel Pitoiset <br>
>> <<a href="mailto:samuel.pitoiset@gmail.com" target="_blank">samuel.pitoiset@gmail.com</a> <mailto:<a href="mailto:samuel.pitoiset@gmail.com" target="_blank">samuel.pitoiset@gmail.com</a>>> wrote:<br>
>><br>
>><br>
>>     On 4/23/19 10:45 AM, Bas Nieuwenhuizen wrote:<br>
>>     > On Tue, Apr 23, 2019 at 9:35 AM Samuel Pitoiset<br>
>>     > <<a href="mailto:samuel.pitoiset@gmail.com" target="_blank">samuel.pitoiset@gmail.com</a> <mailto:<a href="mailto:samuel.pitoiset@gmail.com" target="_blank">samuel.pitoiset@gmail.com</a>>><br>
>>     wrote:<br>
>>     >> Signed-off-by: Samuel Pitoiset <<a href="mailto:samuel.pitoiset@gmail.com" target="_blank">samuel.pitoiset@gmail.com</a><br>
>>     <mailto:<a href="mailto:samuel.pitoiset@gmail.com" target="_blank">samuel.pitoiset@gmail.com</a>>><br>
>>     >> ---<br>
>>     >>   src/amd/vulkan/radv_shader.c                 |  2 +-<br>
>>     >>   src/compiler/nir/nir.h                       |  3 ++-<br>
>>     >>   src/compiler/nir/nir_opt_if.c                | 17<br>
>>     ++++++++++-------<br>
>>     >>   src/freedreno/ir3/ir3_nir.c                  |  2 +-<br>
>>     >>   src/gallium/auxiliary/nir/tgsi_to_nir.c      |  2 +-<br>
>>     >>   src/gallium/drivers/freedreno/a2xx/ir2_nir.c |  2 +-<br>
>>     >>   src/gallium/drivers/radeonsi/si_shader_nir.c |  2 +-<br>
>>     >>   src/intel/compiler/brw_nir.c                 |  2 +-<br>
>>     >>   src/mesa/state_tracker/st_glsl_to_nir.cpp    |  2 +-<br>
>>     >>   9 files changed, 19 insertions(+), 15 deletions(-)<br>
>>     >><br>
>>     >> diff --git a/src/amd/vulkan/radv_shader.c<br>
>>     b/src/amd/vulkan/radv_shader.c<br>
>>     >> index 13f1f9aa9dc..54a4e732230 100644<br>
>>     >> --- a/src/amd/vulkan/radv_shader.c<br>
>>     >> +++ b/src/amd/vulkan/radv_shader.c<br>
>>     >> @@ -158,7 +158,7 @@ radv_optimize_nir(struct nir_shader<br>
>>     *shader, bool optimize_conservatively,<br>
>>     >>                          NIR_PASS(progress, shader,<br>
>>     nir_opt_remove_phis);<br>
>>     >>                           NIR_PASS(progress, shader, nir_opt_dce);<br>
>>     >>                   }<br>
>>     >> -                NIR_PASS(progress, shader, nir_opt_if, true);<br>
>>     >> +                NIR_PASS(progress, shader, nir_opt_if, true,<br>
>>     false);<br>
>>     >>                   NIR_PASS(progress, shader, nir_opt_dead_cf);<br>
>>     >>                   NIR_PASS(progress, shader, nir_opt_cse);<br>
>>     >>                   NIR_PASS(progress, shader,<br>
>>     nir_opt_peephole_select, 8, true, true);<br>
>>     >> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
>>     >> index 7d2062d3691..d7506d6ddd1 100644<br>
>>     >> --- a/src/compiler/nir/nir.h<br>
>>     >> +++ b/src/compiler/nir/nir.h<br>
>>     >> @@ -3474,7 +3474,8 @@ bool nir_opt_gcm(nir_shader *shader, bool<br>
>>     value_number);<br>
>>     >><br>
>>     >>   bool nir_opt_idiv_const(nir_shader *shader, unsigned<br>
>>     min_bit_size);<br>
>>     >><br>
>>     >> -bool nir_opt_if(nir_shader *shader, bool<br>
>>     aggressive_last_continue);<br>
>>     >> +bool nir_opt_if(nir_shader *shader, bool aggressive_last_continue,<br>
>>     >> +                bool skip_alu_of_phi);<br>
>>     > Can we have a flag for this instead (e.g. something like<br>
>>     > nir_opt_if_skip_alu_of_phi)? I think have a function with a bunch of<br>
>>     > bools is less than ideal as you can't see at the calling site<br>
>>     what is<br>
>>     > for what arg.<br>
>>     Yes, that seems better to me.<br>
>><br>
>><br>
>> This is the worst kind of hack all around.  We're making NIR more <br>
>> complicated and adding a flag to disable a useful and correct piece of <br>
>> an optimization, not because it causes a perf regression but because <br>
>> the back-end compiler is broken and this is easier than fixing it <br>
>> properly. Seriously?  Can't we just fix the LLVM back-end?  Or, if <br>
>> this optimization is actually doing something wrong, fix it?  Or maybe <br>
>> actually figure out what pattern is causing LLVM to fall over and have <br>
>> a hack in your NIR -> LLVM pass?  On the list of "good ways to fix <br>
>> this problem", this seems to be pretty far down if it hasn't fallen <br>
>> off the bottom.<br>
> <br>
> Best hack of the month? :-)<br>
> <br>
> As discussed over IRC, this is definitely not the best solution, I don't <br>
> like it either as I said.<br>
> <br>
> I will work on a different solution maybe in our NIR->LLVM pass.<br>
> <br>
> The aggressive_last_continue option should also be removed (make it <br>
> default?).<br>
<br>
The aggressive_last_continue option is not a hack to avoid a bug in a <br>
driver backend it is to avoid perf regressions. That said we may be able <br>
to remove it now that Jason has landed <br>
cd4ffb376f2aeefdd6a1b80d69a1580c4e569778<br></blockquote><div><br></div><div>I don't think anyone was claiming it was.  The only claim made was that it's probably an ultimately unnecessary option and we should try to apply it universally.</div><div><br></div><div>--Jason</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> <br>
>><br>
>> --Jason<br>
>><br>
>>     >>   bool nir_opt_intrinsics(nir_shader *shader);<br>
>>     >><br>
>>     >> diff --git a/src/compiler/nir/nir_opt_if.c<br>
>>     b/src/compiler/nir/nir_opt_if.c<br>
>>     >> index f674185f1e2..149b3bd1659 100644<br>
>>     >> --- a/src/compiler/nir/nir_opt_if.c<br>
>>     >> +++ b/src/compiler/nir/nir_opt_if.c<br>
>>     >> @@ -1385,7 +1385,8 @@ opt_if_cf_list(nir_builder *b, struct<br>
>>     exec_list *cf_list,<br>
>>     >>    * not do anything to cause the metadata to become invalid.<br>
>>     >>    */<br>
>>     >>   static bool<br>
>>     >> -opt_if_safe_cf_list(nir_builder *b, struct exec_list *cf_list)<br>
>>     >> +opt_if_safe_cf_list(nir_builder *b, struct exec_list *cf_list,<br>
>>     >> +                    bool skip_alu_of_phi)<br>
>>     >>   {<br>
>>     >>      bool progress = false;<br>
>>     >>      foreach_list_typed(nir_cf_node, cf_node, node, cf_list) {<br>
>>     >> @@ -1395,16 +1396,17 @@ opt_if_safe_cf_list(nir_builder *b,<br>
>>     struct exec_list *cf_list)<br>
>>     >><br>
>>     >>         case nir_cf_node_if: {<br>
>>     >>            nir_if *nif = nir_cf_node_as_if(cf_node);<br>
>>     >> -         progress |= opt_if_safe_cf_list(b, &nif->then_list);<br>
>>     >> -         progress |= opt_if_safe_cf_list(b, &nif->else_list);<br>
>>     >> +         progress |= opt_if_safe_cf_list(b, &nif->then_list,<br>
>>     skip_alu_of_phi);<br>
>>     >> +         progress |= opt_if_safe_cf_list(b, &nif->else_list,<br>
>>     skip_alu_of_phi);<br>
>>     >>            progress |= opt_if_evaluate_condition_use(b, nif);<br>
>>     >>            break;<br>
>>     >>         }<br>
>>     >><br>
>>     >>         case nir_cf_node_loop: {<br>
>>     >>            nir_loop *loop = nir_cf_node_as_loop(cf_node);<br>
>>     >> -         progress |= opt_if_safe_cf_list(b, &loop->body);<br>
>>     >> -         progress |= opt_split_alu_of_phi(b, loop);<br>
>>     >> +         progress |= opt_if_safe_cf_list(b, &loop->body,<br>
>>     skip_alu_of_phi);<br>
>>     >> +         if (!skip_alu_of_phi)<br>
>>     >> +            progress |= opt_split_alu_of_phi(b, loop);<br>
>>     >>            break;<br>
>>     >>         }<br>
>>     >><br>
>>     >> @@ -1417,7 +1419,8 @@ opt_if_safe_cf_list(nir_builder *b,<br>
>>     struct exec_list *cf_list)<br>
>>     >>   }<br>
>>     >><br>
>>     >>   bool<br>
>>     >> -nir_opt_if(nir_shader *shader, bool aggressive_last_continue)<br>
>>     >> +nir_opt_if(nir_shader *shader, bool aggressive_last_continue,<br>
>>     >> +           bool skip_alu_of_phi)<br>
>>     >>   {<br>
>>     >>      bool progress = false;<br>
>>     >><br>
>>     >> @@ -1430,7 +1433,7 @@ nir_opt_if(nir_shader *shader, bool<br>
>>     aggressive_last_continue)<br>
>>     >><br>
>>     >>         nir_metadata_require(function->impl,<br>
>>     nir_metadata_block_index |<br>
>>     >> nir_metadata_dominance);<br>
>>     >> -      progress = opt_if_safe_cf_list(&b, &function->impl->body);<br>
>>     >> +      progress = opt_if_safe_cf_list(&b,<br>
>>     &function->impl->body, skip_alu_of_phi);<br>
>>     >>         nir_metadata_preserve(function->impl,<br>
>>     nir_metadata_block_index |<br>
>>     >>  nir_metadata_dominance);<br>
>>     >><br>
>>     >> diff --git a/src/freedreno/ir3/ir3_nir.c<br>
>>     b/src/freedreno/ir3/ir3_nir.c<br>
>>     >> index 76230e3be50..1bec3c030a9 100644<br>
>>     >> --- a/src/freedreno/ir3/ir3_nir.c<br>
>>     >> +++ b/src/freedreno/ir3/ir3_nir.c<br>
>>     >> @@ -147,7 +147,7 @@ ir3_optimize_loop(nir_shader *s)<br>
>>     >>                          OPT(s, nir_copy_prop);<br>
>>     >>                          OPT(s, nir_opt_dce);<br>
>>     >>                  }<br>
>>     >> -               progress |= OPT(s, nir_opt_if, false);<br>
>>     >> +               progress |= OPT(s, nir_opt_if, false, false);<br>
>>     >>                  progress |= OPT(s, nir_opt_remove_phis);<br>
>>     >>                  progress |= OPT(s, nir_opt_undef);<br>
>>     >><br>
>>     >> diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c<br>
>>     b/src/gallium/auxiliary/nir/tgsi_to_nir.c<br>
>>     >> index c55e8b84a41..6b40bff1f73 100644<br>
>>     >> --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c<br>
>>     >> +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c<br>
>>     >> @@ -2066,7 +2066,7 @@ ttn_optimize_nir(nir_shader *nir, bool<br>
>>     scalar)<br>
>>     >>            NIR_PASS(progress, nir, nir_opt_dce);<br>
>>     >>         }<br>
>>     >><br>
>>     >> -      NIR_PASS(progress, nir, nir_opt_if, false);<br>
>>     >> +      NIR_PASS(progress, nir, nir_opt_if, false, false);<br>
>>     >>         NIR_PASS(progress, nir, nir_opt_dead_cf);<br>
>>     >>         NIR_PASS(progress, nir, nir_opt_cse);<br>
>>     >>         NIR_PASS(progress, nir, nir_opt_peephole_select, 8,<br>
>>     true, true);<br>
>>     >> diff --git a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c<br>
>>     b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c<br>
>>     >> index ee348ca6a93..3522971e435 100644<br>
>>     >> --- a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c<br>
>>     >> +++ b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c<br>
>>     >> @@ -94,7 +94,7 @@ ir2_optimize_loop(nir_shader *s)<br>
>>     >>                          OPT(s, nir_opt_dce);<br>
>>     >>                  }<br>
>>     >>                  progress |= OPT(s, nir_opt_loop_unroll,<br>
>>     nir_var_all);<br>
>>     >> -               progress |= OPT(s, nir_opt_if, false);<br>
>>     >> +               progress |= OPT(s, nir_opt_if, false, false);<br>
>>     >>                  progress |= OPT(s, nir_opt_remove_phis);<br>
>>     >>                  progress |= OPT(s, nir_opt_undef);<br>
>>     >><br>
>>     >> diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c<br>
>>     b/src/gallium/drivers/radeonsi/si_shader_nir.c<br>
>>     >> index 5a925f19e09..7f1fe4ba2e9 100644<br>
>>     >> --- a/src/gallium/drivers/radeonsi/si_shader_nir.c<br>
>>     >> +++ b/src/gallium/drivers/radeonsi/si_shader_nir.c<br>
>>     >> @@ -879,7 +879,7 @@ si_lower_nir(struct si_shader_selector* sel)<br>
>>     >>                          NIR_PASS(progress, sel->nir,<br>
>>     nir_copy_prop);<br>
>>     >>                          NIR_PASS(progress, sel->nir, nir_opt_dce);<br>
>>     >>                  }<br>
>>     >> -               NIR_PASS(progress, sel->nir, nir_opt_if, true);<br>
>>     >> +               NIR_PASS(progress, sel->nir, nir_opt_if, true,<br>
>>     false);<br>
>>     >>                  NIR_PASS(progress, sel->nir, nir_opt_dead_cf);<br>
>>     >>                  NIR_PASS(progress, sel->nir, nir_opt_cse);<br>
>>     >>                  NIR_PASS(progress, sel->nir,<br>
>>     nir_opt_peephole_select, 8, true, true);<br>
>>     >> diff --git a/src/intel/compiler/brw_nir.c<br>
>>     b/src/intel/compiler/brw_nir.c<br>
>>     >> index e0a393fc298..ba911049ce3 100644<br>
>>     >> --- a/src/intel/compiler/brw_nir.c<br>
>>     >> +++ b/src/intel/compiler/brw_nir.c<br>
>>     >> @@ -607,7 +607,7 @@ brw_nir_optimize(nir_shader *nir, const<br>
>>     struct brw_compiler *compiler,<br>
>>     >>            OPT(nir_copy_prop);<br>
>>     >>            OPT(nir_opt_dce);<br>
>>     >>         }<br>
>>     >> -      OPT(nir_opt_if, false);<br>
>>     >> +      OPT(nir_opt_if, false, false);<br>
>>     >>         if (nir->options->max_unroll_iterations != 0) {<br>
>>     >>            OPT(nir_opt_loop_unroll, indirect_mask);<br>
>>     >>         }<br>
>>     >> diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp<br>
>>     b/src/mesa/state_tracker/st_glsl_to_nir.cpp<br>
>>     >> index 97b2831b880..3f1f78e875b 100644<br>
>>     >> --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp<br>
>>     >> +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp<br>
>>     >> @@ -324,7 +324,7 @@ st_nir_opts(nir_shader *nir, bool scalar)<br>
>>     >>            NIR_PASS(progress, nir, nir_copy_prop);<br>
>>     >>            NIR_PASS(progress, nir, nir_opt_dce);<br>
>>     >>         }<br>
>>     >> -      NIR_PASS(progress, nir, nir_opt_if, false);<br>
>>     >> +      NIR_PASS(progress, nir, nir_opt_if, false, false);<br>
>>     >>         NIR_PASS(progress, nir, nir_opt_dead_cf);<br>
>>     >>         NIR_PASS(progress, nir, nir_opt_cse);<br>
>>     >>         NIR_PASS(progress, nir, nir_opt_peephole_select, 8,<br>
>>     true, true);<br>
>>     >> --<br>
>>     >> 2.21.0<br>
>>     >><br>
>>     >> _______________________________________________<br>
>>     >> mesa-dev mailing list<br>
>>     >> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
>>     <mailto:<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/mailman/listinfo/mesa-dev</a><br>
>>     _______________________________________________<br>
>>     mesa-dev mailing list<br>
>>     <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a> <mailto:<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/mailman/listinfo/mesa-dev</a><br>
>><br>
> <br>
> _______________________________________________<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/mailman/listinfo/mesa-dev</a><br>
> <br>
</blockquote></div></div>