linker: Eliminate more dead code after demoting shader inputs and outputs
linker: Eliminate more dead code after demoting shader inputs and outputs

Consider the following vertex shader and fragment shader:

// vertex shader
varying vec4 v;
uniform vec4 u;

void main() { gl_Position = vec4(0.0); v = u; }

// fragment shader
void main() { gl_FragColor = vec4(0.0); }

Since the fragment shader does not use 'v', it is demoted from a
varying to a simple global variable.  Once that happens, the
assignment to 'v' is useless, and it should be removed.  In addition,
'u' is no longer active, and it should also be removed.

Performing extra dead code elimination after demoting shader inputs
and outputs takes care of this.  This elimination must occur before
assigning uniform locations, or the declaration of 'u' cannot be
removed.

This change *breaks* the piglit test getuniform-01, but that test is
already incorrect.  The test uses a vertex shader that assigns to a
user-defined varying, but it has no fragment shader.  Since Mesa does
not support ARB_separate_shader_objects (we only support the EXT
version), the linker correctly eliminates the user-defined varying.
The cascading effect is that the uniform queried by the C code of the
test is also (correctly) eliminated.

Signed-off-by: Ian Romanick <2b237cafb16dc45038e85df6c85e74e6d899eba9@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41980
Tested-by: Brian Paul <3cb4e1df5ec4da2c7c4af7c52cec8cf340a55a10@vmware.com>
Cc: Bryan Cain <684228a7723bc0002d27fb518de96af5b5ddae81@gmail.com>
Cc: Vinson Lee <25a259f709b0f1b620605d2518271a846d8826e5@vmware.com>
Cc: José Fonseca <61b5a29db2c0650f7c8510f93eece059c1b09320@vmware.com>
Reviewed-by: Kenneth Graunke <bd2562f754ec92342f93f61c25d731e290a2ffa8@whitecape.org>
Reviewed-by: Yuanhan Liu <5dcef21195e64c9c08aa779bb62b25e9133eaa33@linux.intel.com>

zz85/glsl-optimizer,wolf96/glsl-optimizer,metora/MesaGLSLCompiler,zeux/glsl-optimizer,bkaradzic/glsl-optimizer,benaadams/glsl-optimizer,bkaradzic/glsl-optimizer,zeux/glsl-optimizer,tokyovigilante/glsl-optimizer,benaadams/glsl-optimizer,benaadams/glsl-optimizer,mapbox/glsl-optimizer,zz85/glsl-optimizer,mapbox/glsl-optimizer,zz85/glsl-optimizer,zz85/glsl-optimizer,djreep81/glsl-optimizer,zeux/glsl-optimizer,wolf96/glsl-optimizer,jbarczak/glsl-optimizer,dellis1972/glsl-optimizer,zz85/glsl-optimizer,bkaradzic/glsl-optimizer,mapbox/glsl-optimizer,wolf96/glsl-optimizer,benaadams/glsl-optimizer,djreep81/glsl-optimizer,dellis1972/glsl-optimizer,metora/MesaGLSLCompiler,jbarczak/glsl-optimizer,bkaradzic/glsl-optimizer,jbarczak/glsl-optimizer,benaadams/glsl-optimizer,mcanthony/glsl-optimizer,dellis1972/glsl-optimizer,mcanthony/glsl-optimizer,wolf96/glsl-optimizer,zeux/glsl-optimizer,wolf96/glsl-optimizer,mcanthony/glsl-optimizer,benaadams/glsl-optimizer,jbarczak/glsl-optimizer,mcanthony/glsl-optimizer,tokyovigilante/glsl-optimizer,zz85/glsl-optimizer,mapbox/glsl-optimizer,bkaradzic/glsl-optimizer,tokyovigilante/glsl-optimizer,mcanthony/glsl-optimizer,mapbox/glsl-optimizer,metora/MesaGLSLCompiler,jbarczak/glsl-optimizer,djreep81/glsl-optimizer,djreep81/glsl-optimizer,tokyovigilante/glsl-optimizer,dellis1972/glsl-optimizer,dellis1972/glsl-optimizer,tokyovigilante/glsl-optimizer,zeux/glsl-optimizer,djreep81/glsl-optimizer