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

Aras Pranckevicius aras at unity3d.com
Mon May 19 10:56:33 PDT 2014


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



-- 
Aras Pranckevičius
work: http://unity3d.com
home: http://aras-p.info
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140519/51d96bad/attachment-0001.html>


More information about the mesa-dev mailing list