[Mesa-dev] [PATCH 4/5] i965/fs: Dead code eliminate instructions writing the flag.

Matt Turner mattst88 at gmail.com
Mon Nov 3 11:54:50 PST 2014


On Wed, Oct 29, 2014 at 1:10 PM, Matt Turner <mattst88 at gmail.com> wrote:
> Most prominently helps Natural Selection 2, which has a surprising
> number shaders that do very complicated things before drawing black.
>
> instructions in affected programs:     23824 -> 19570 (-17.86%)
> ---
>  .../dri/i965/brw_fs_dead_code_eliminate.cpp        | 23 +++++++++++++++++++---
>  1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp b/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp
> index 9cf8d89..414c4a0 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp
> @@ -43,15 +43,16 @@ fs_visitor::dead_code_eliminate()
>
>     int num_vars = live_intervals->num_vars;
>     BITSET_WORD *live = ralloc_array(NULL, BITSET_WORD, BITSET_WORDS(num_vars));
> +   BITSET_WORD *flag_live = ralloc_array(NULL, BITSET_WORD, 1);
>
>     foreach_block (block, cfg) {
>        memcpy(live, live_intervals->block_data[block->num].liveout,
>               sizeof(BITSET_WORD) * BITSET_WORDS(num_vars));
> +      memcpy(flag_live, live_intervals->block_data[block->num].flag_liveout,
> +             sizeof(BITSET_WORD));
>
>        foreach_inst_in_block_reverse(fs_inst, inst, block) {
> -         if (inst->dst.file == GRF &&
> -             !inst->has_side_effects() &&
> -             !inst->writes_flag()) {
> +         if (inst->dst.file == GRF && !inst->has_side_effects()) {
>              bool result_live = false;
>
>              if (inst->regs_written == 1) {
> @@ -76,6 +77,13 @@ fs_visitor::dead_code_eliminate()
>              }
>           }
>
> +         if (inst->dst.is_null() && inst->writes_flag()) {
> +            if (!BITSET_TEST(flag_live, inst->flag_subreg)) {
> +               inst->opcode = BRW_OPCODE_NOP;

progress = true;

> +               continue;
> +            }
> +         }
> +
>           if (inst->dst.file == GRF) {
>              if (!inst->is_partial_write()) {
>                 int var = live_intervals->var_from_reg(&inst->dst);


More information about the mesa-dev mailing list