[Mesa-dev] [PATCH 2/5] i965: Add a pass to remove dead control flow.

Eric Anholt eric at anholt.net
Mon Nov 4 10:17:11 PST 2013


Matt Turner <mattst88 at 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 <stereotype441 at 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 <eric at anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131104/e39b224a/attachment-0001.pgp>


More information about the mesa-dev mailing list