<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 23, 2019 at 7:46 AM Samuel Pitoiset <<a href="mailto:samuel.pitoiset@gmail.com">samuel.pitoiset@gmail.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"><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>> wrote:<br>
>> Signed-off-by: Samuel Pitoiset <<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>
>>   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 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 *shader, bool optimize_conservatively,<br>
>>                          NIR_PASS(progress, shader, 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, false);<br>
>>                   NIR_PASS(progress, shader, nir_opt_dead_cf);<br>
>>                   NIR_PASS(progress, shader, nir_opt_cse);<br>
>>                   NIR_PASS(progress, shader, 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 value_number);<br>
>><br>
>>   bool nir_opt_idiv_const(nir_shader *shader, unsigned min_bit_size);<br>
>><br>
>> -bool nir_opt_if(nir_shader *shader, bool 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 what is<br>
> for what arg.<br>
Yes, that seems better to me.<br></blockquote><div><br></div><div>This is the worst kind of hack all around.  We're making NIR more complicated and adding a flag to disable a useful and correct piece of an optimization, not because it causes a perf regression but because the back-end compiler is broken and this is easier than fixing it properly.  Seriously?  Can't we just fix the LLVM back-end?  Or, if this optimization is actually doing something wrong, fix it?  Or maybe actually figure out what pattern is causing LLVM to fall over and have a hack in your NIR -> LLVM pass?  On the list of "good ways to fix this problem", this seems to be pretty far down if it hasn't fallen off the bottom.<br></div><div><br></div><div>--Jason<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">
>>   bool nir_opt_intrinsics(nir_shader *shader);<br>
>><br>
>> diff --git a/src/compiler/nir/nir_opt_if.c 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 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, 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, skip_alu_of_phi);<br>
>> +         progress |= opt_if_safe_cf_list(b, &nif->else_list, 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, 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, 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 aggressive_last_continue)<br>
>><br>
>>         nir_metadata_require(function->impl, 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, &function->impl->body, skip_alu_of_phi);<br>
>>         nir_metadata_preserve(function->impl, nir_metadata_block_index |<br>
>>                               nir_metadata_dominance);<br>
>><br>
>> diff --git a/src/freedreno/ir3/ir3_nir.c 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 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 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, true, true);<br>
>> diff --git a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c 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, 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 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, 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, 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, nir_opt_peephole_select, 8, true, true);<br>
>> diff --git a/src/intel/compiler/brw_nir.c 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 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 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, 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>
>> <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><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a></blockquote></div></div>