[Mesa-dev] [PATCH] i965: Don't emit an empty then-branch

Francisco Jerez currojerez at riseup.net
Wed Feb 24 18:56:38 UTC 2016


Ian Romanick <idr at freedesktop.org> writes:

> From: Ian Romanick <ian.d.romanick at intel.com>
>
> Invert the condition and just emit the non-empty else-branch.
>
> total instructions in shared programs: 8448571 -> 8448373 (-0.00%)
> instructions in affected programs: 20880 -> 20682 (-0.95%)
> helped: 114
> HURT: 0
>
> Jason suggested that there were several places that tried to determine
> that a flow control path had no instructions and the code should be
> refactored.  Using 'grep -r is_empty' in src/mesa/drivers/dri/i965 and
> src/compiler/nir, I could not find any such locations.  As a result, I
> just open coded the check.  Did I just miss the other occurrences?
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> index db20c71..06e8aff 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> @@ -417,13 +417,21 @@ fs_visitor::nir_emit_if(nir_if *if_stmt)
>                                     BRW_REGISTER_TYPE_D));
>     inst->conditional_mod = BRW_CONDITIONAL_NZ;
>  
> -   bld.IF(BRW_PREDICATE_NORMAL);
> +   fs_inst *if_inst = bld.IF(BRW_PREDICATE_NORMAL);
>  
> -   nir_emit_cf_list(&if_stmt->then_list);
> +   const nir_cf_node *const cf = nir_if_first_then_node(if_stmt);
> +   const nir_block *const block = nir_cf_node_as_block(cf);
>  
> -   /* note: if the else is empty, dead CF elimination will remove it */
> -   bld.emit(BRW_OPCODE_ELSE);
> +   /* If the then-list has no instructions, don't emit it. */
> +   if (nir_cf_node_is_last(cf) && block->instr_list.is_empty()) {
> +      if_inst->predicate_inverse = true;
> +   } else {
> +      nir_emit_cf_list(&if_stmt->then_list);
>  
> +      bld.emit(BRW_OPCODE_ELSE);
> +   }
> +
> +   /* note: if the else is empty, dead CF elimination will remove it */

I guess it would make more sense to implement this optimization in an
optimization pass (e.g. dead control flow elimination) rather than at
translation time, that way you'd be able to remove if-branches that
become empty after DCE and it would help the VEC4 back-end too.

>     nir_emit_cf_list(&if_stmt->else_list);
>  
>     bld.emit(BRW_OPCODE_ENDIF);
> -- 
> 2.5.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160224/f45d562f/attachment.sig>


More information about the mesa-dev mailing list