[Mesa-dev] glsl: ideas how to improve dead code elimination?

Matt Turner mattst88 at gmail.com
Mon May 19 16:53:27 PDT 2014


On Mon, May 19, 2014 at 10:56 AM, Aras Pranckevicius <aras at unity3d.com> wrote:
> Hi,
>
> When Mesa's GLSL compiler is faced with a code like this:
>
>     // vec4 packednormal exists
>     vec3 normal;
>     normal.xy = packednormal.wy * 2.0 - 1.0;
>     normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
>     // now do not use the "normal" at all anywhere
>
> Then the dead code elimination pass will not be able to eliminate the
> "normal" variable, nor anything that lead to it (possibly sampling textures
> into packed normal, etc.).
>
> This is because variable refcounting visitor sees "normal" as having four
> references, but only two assignments, and can not consider it dead. Even if
> these two references are from assignment to normal.z where both LHS & RHS
> reference the same variable.
>
> Any ideas on how to improve this?
>
>
> If the original code was doing something like this, then dead code
> elimination is able to "properly" eliminate this whole thing:
>
>     // vec4 packednormal exists
>     vec3 normal;
>     vec2 nxy = packednormal.wy * 2.0 - 1.0;
>     float nz = sqrt(1.0 - dot(nxy, nxy));
>     normal.xy = nxy;
>     normal.z = nz;
>     // now do not use the "normal" at all anywhere

Eric is working on a better GLSL IR dead code elimination pass. I'm
not sure of the current status.

It's in his tree:

   git://people.freedesktop.org/~anholt/mesa deadcode


More information about the mesa-dev mailing list