[Mesa-dev] [PATCH] nir: remove jump from two merging jump-ending blocks

Caio Marcelo de Oliveira Filho caio.oliveira at intel.com
Tue Feb 12 18:32:29 UTC 2019


On Tue, Feb 12, 2019 at 04:38:04PM +0100, Juan A. Suarez Romero wrote:
> In opt_peel_initial_if optimization, when moving the continue list to
> end of the continue block, before the jump, could happen that the
> continue list itself also ends with a jump.
> 
> This would mean that we would have two jump instructions in a row: the
> first one from the continue list and the second one from the contine
> block.
> 
> As inserting an instruction after a jump is not allowed (and it does not
> make sense, as it will not be executed), remove the jump from the
> continue block and keep the one from continue list, as it will be
> executed first.
> 
> CC: Jason Ekstrand <jason at jlekstrand.net>
> ---
>  src/compiler/nir/nir_opt_if.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)


Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>



> diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c
> index 932af9e37ab..a011401b3b4 100644
> --- a/src/compiler/nir/nir_opt_if.c
> +++ b/src/compiler/nir/nir_opt_if.c
> @@ -241,12 +241,29 @@ opt_peel_loop_initial_if(nir_loop *loop)
>     nir_cf_reinsert(&header,
>                     nir_after_block_before_jump(find_continue_block(loop)));
>  
> +   bool continue_list_jumps =
> +      nir_block_ends_in_jump(exec_node_data(nir_block,
> +                                            exec_list_get_tail(continue_list),
> +                                            cf_node.node));
> +
>     nir_cf_extract(&tmp, nir_before_cf_list(continue_list),
>                          nir_after_cf_list(continue_list));
>  
> -   /* Get continue block again as the previous reinsert might have removed the block. */
> +   /* Get continue block again as the previous reinsert might have removed the
> +    * block.  Also, if both the continue list and the continue block ends in
> +    * jump instructions, removes the jump from the later, as it will not be

"latter"

> +    * executed if we insert the continue list before it */

"...before it."


> +
> +   nir_block *continue_block = find_continue_block(loop);
> +
> +   if (continue_list_jumps) {
> +      nir_instr *last_instr = nir_block_last_instr(continue_block);
> +      if (last_instr && last_instr->type == nir_instr_type_jump)
> +         nir_instr_remove(last_instr);
> +   }
> +
>     nir_cf_reinsert(&tmp,
> -                   nir_after_block_before_jump(find_continue_block(loop)));
> +                   nir_after_block_before_jump(continue_block));
>  
>     nir_cf_node_remove(&nif->cf_node);
>  
> -- 
> 2.20.1
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


	Caio


More information about the mesa-dev mailing list