Matt Turner <matts...@gmail.com> writes: > On Mon, May 19, 2014 at 10:56 AM, Aras Pranckevicius <a...@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
Yeah, the code is passing piglit iirc, and with Matt's register renaming, it's a nice win: total instructions in shared programs: 1826879 -> 1813610 (-0.73%) instructions in affected programs: 270257 -> 256988 (-4.91%) GAINED: 15 LOST: 15 however, the nasty thing is that unigine heaven #208 now compiles forever, and I haven't tracked it down. I have noticed in Source engine shaders that a more aggressive register renaming at the GLSL IR level would be useful. Or rework tree grafting to deal with values used only once, not just whole variables used only once. With the live variables code in my deadcode branch, a better tree grafting might be easy.
pgprN8F1Z23uk.pgp
Description: PGP signature
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev