glsl: Rework lowering of non-constant array indexing
glsl: Rework lowering of non-constant array indexing

The previous implementation could easily get tricked if the LHS of an
assignment included a non-constant index that was "inside" another
dereference.  For example:

    mat4 m[2];
    m[0][i] = vec4(0.0);

Due to the way it tracked whether the array was being assigned, it
would think that the non-constant index was in an r-value.  The new
code fixes that by tracking l-values and r-values differently.  The
index is also replaced by cloning the IR and replacing the index
variable instead of the odd way it was done before.

v2: Apply some simplifications suggested by Eric Anholt.  Making
assignment_generator::rvalue be ir_dereference instead of ir_rvalue
simplified the code a bit.

Fixes i965 piglit fs-temp-array-mat[234]-index-wr and
vs-varying-array-mat[234]-index-wr.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=34691
Reviewed-by: Eric Anholt <96f164ad4d9b2b0dacf8ebee2bb1eeb3aa69adf1@anholt.net>

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