[Mesa-dev] [PATCH 2/2] prog_optimize: Add simplify CMP optimization pass

Matt Turner mattst88 at gmail.com
Wed Apr 6 20:51:40 PDT 2011


On Thu, Apr 7, 2011 at 3:06 AM, Tom Stellard <tstellar at gmail.com> wrote:

I don't know anything about this code, but I just want to verify that
T0 (tee zero) and TO (tee oh) are different things and are used in the
right places.

> +/**
> + * This pass replaces CMP T0, T1 T2 T0 with MOV TO, T2 when the CMP
> + * instruction is the first instruction to write to register T0.  The are
> + * several lowering passes done in GLSL IR (e.g. branches and
> + * relative addressing) that create a large number of conditional assignments
> + * that ir_to_mesa converts to CMP instructions like the one mentioned above.
> + *
> + * Here is why this conversion is safe:
> + * CMP TO, T1 T2 T0 can be expanded to:
> + * if (T1 < 0.0)
> + *     MOV T0, T2;
> + * else
> + *     MOV T0, TO;
> + *
> + * If (T1 < 0.0) evaluates to true then our replacement MOV T0, T2 is the same
> + * as the original program.  If (T1 < 0.0) evaluates to false, executing
> + * MOV T0, T0 will store a garbage value in T0 since T0 is uninitialized.
> + * Therefore, it doesn't matter that we are replacing MOV T0, T0 with MOV TO, T2
> + * because any instruction that was going to read from T0 after this was going
> + * to read a garbage value anyway.

I see "This pass replaces CMP T0, T1 T2 T0" but also "CMP TO, T1 T2 T0
can be expanded to" where the first has T0 twice and the second has TO
and T0. And a few other seemingly strange occurrences of TO also.

Matt


More information about the mesa-dev mailing list