[Mesa-dev] [PATCH 2/2] prog_optimize: Add reads without writes optimization pass

Tom Stellard tstellar at gmail.com
Tue Mar 29 11:35:33 PDT 2011

On Tue, Mar 29, 2011 at 10:19:13AM -0700, Eric Anholt wrote:
> On Mon, 28 Mar 2011 22:59:31 -0700, Tom Stellard <tstellar at gmail.com> wrote:
> > This pass scans programs for instructions that read registers that have
> > not been written and replaces these reads with a read from a constant
> > register with the value of zero.  This pass prevents phantom
> > dependencies from being introduced by the register allocator and
> > improves the efficiency of subsequent optimization passes.
> I'm not sure why optimizing a program with undefined behavior (using
> undefined register values) is interesting.  It just seems like an
> opportunity to make a mistake and break programs that should have
> defined behavior.

The main problem I am trying to fix with this is that these reads
from undefined register values are causing the Mesa IR register allocator
to alter the structure of the program by adding dependencies between
instructions that should not be there.  This is limiting the number of
optimization opportunities that are available to drivers, especially
on architectures like r300 that need IFs lowered and thus use a lot of
CMP instructions.

The other solution I considered was giving drivers the option to disable
the register allocation pass in Mesa IR, but each driver would still
need to do something like this anyway, so I figured it was better to
just push this pass up to Mesa IR.

-Tom Stellard

More information about the mesa-dev mailing list