Matt Turner <matts...@gmail.com> writes:

> Removes IF/ENDIF and IF/ELSE/ENDIF with no intervening instructions.
>
> total instructions in shared programs: 1360393 -> 1360387 (-0.00%)
> instructions in affected programs:     157 -> 151 (-3.82%)
>
> (no change in vertex shaders)
>
> Reviewed-by: Paul Berry <stereotype...@gmail.com> [v1]
> v2: Moved before SEL peephole in series. Made function useful for VS.

> +bool
> +dead_control_flow_eliminate(backend_visitor *v)
> +{
> +   bool progress = false;
> +
> +   cfg_t cfg(v);
> +
> +   for (int b = 0; b < cfg.num_blocks; b++) {
> +      bblock_t *block = cfg.blocks[b];
> +      bool found = false;
> +
> +      /* ENDIF instructions, by definition, can only be found at the ends of
> +       * basic blocks.
> +       */
> +      backend_instruction *endif_inst = block->end;
> +      if (endif_inst->opcode != BRW_OPCODE_ENDIF)
> +         continue;
> +
> +      backend_instruction *if_inst = NULL, *else_inst = NULL;
> +      backend_instruction *prev_inst = (backend_instruction *) 
> endif_inst->prev;
> +      if (prev_inst->opcode == BRW_OPCODE_IF) {
> +         if_inst = prev_inst;
> +         found = true;
> +      } else if (prev_inst->opcode == BRW_OPCODE_ELSE) {
> +         else_inst = prev_inst;
> +
> +         prev_inst = (backend_instruction *) prev_inst->prev;
> +         if (prev_inst->opcode == BRW_OPCODE_IF) {
> +            if_inst = prev_inst;
> +            found = true;
> +         }
> +      }
> +
> +      if (found) {
> +         if_inst->remove();
> +         if (else_inst)
> +            else_inst->remove();
> +         endif_inst->remove();
> +         progress = true;
> +      }
> +   }

Since you've modified the ip of instructions, this needs

   if (progress)
      invalidate_live_intervals();

> +
> +   return progress;

Other than that,

Reviewed-by: Eric Anholt <e...@anholt.net>

Attachment: pgpB_8H18m9h8.pgp
Description: PGP signature

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to