[Mesa-dev] [PATCH 2/2] nir: Add a global dead write var removal pass

Caio Marcelo de Oliveira Filho caio.oliveira at intel.com
Wed Aug 15 21:34:34 UTC 2018


Disregard this patch. I'm sending a replacement for it.

For the record:

> The pass works by walking through the control flow nodes, and traverse
> the instructions keeping track of the write instructions whose
> destination were not overwritten by other instructions (called "live
> writes"). Reading from the destinations cause the writes to be marked
> as "used". If statements and loops are handled specially to take into
> account the different codepaths. The writes that are not "used" are
> removed.

(...)

> +   case nir_cf_node_loop: {
> +      nir_loop *loop = nir_cf_node_as_loop(cf_node);
> +
> +      /* For tracking used variables in a loop, there are three cases: (a) the
> +       * body is not entered; (b) the body is executed once; (c) the body is
> +       * executed more than once.
> +       *
> +       * The case (c) is exemplified below:
> +       *
> +       *     c = x
> +       *     while condition
> +       *         use(c)
> +       *         c = y
> +       *     c = z
> +       *     use(c)
> +       *
> +       * All writes to c must be considered used.  This is achieved by
> +       * performing a second pass in the loop body, with the live write table
> +       * produced by a first pass on it.
> +       */
> +
> +      struct hash_table *loop_live_writes = _mesa_hash_table_clone(live_writes, mem_ctx);
> +      for (int i = 0; i < 2; i++) {
> +         foreach_list_typed_safe(nir_cf_node, cf_node, node, &loop->body)
> +            mark_used_writes_in_node(mem_ctx, loop_live_writes, cf_node);
> +      }

Doing two iterations here has a bad consequence: the number of times
we execute blocks will blows up, since if there's a loop inside the
loop, we'll execute each block in the inner loop 4 times, and so on.

I've tried other approaches to do this "following the CFG", but for
the case at hand (eliminate dead writes) all them ended up pointing
towards doing the analysis considering the block graph (preds/succs).
So that's what I've done in the new patch.


Thanks,
Caio





More information about the mesa-dev mailing list