glsl: Eliminate assigments to out-of-bounds elements of vector
authorDanylo Piliaiev <danylo.piliaiev@globallogic.com>
Mon, 17 Aug 2020 15:22:47 +0000 (18:22 +0300)
committerMarge Bot <eric+marge@anholt.net>
Fri, 21 Aug 2020 15:00:51 +0000 (15:00 +0000)
commit5922d57a184fcb27955d959e949e1ef68873bd19
treef32a8ec5538aebd9ce496b8448edf5271c0a55c2
parente93979ba599355c42df01a89073362b970489a3a
glsl: Eliminate assigments to out-of-bounds elements of vector

Several optimization paths, including constant folding, can lead to
indexing vector with an out of bounds index.

Out-of-bounds writes could be eliminated per spec:

Section 5.11 (Out-of-Bounds Accesses) of the GLSL 4.60 spec says:

"In the subsections described above for array, vector, matrix and
 structure accesses, any out-of-bounds access produced undefined
 behavior.... Out-of-bounds writes may be discarded or overwrite
 other variables of the active program."

Fixes piglit tests:
spec@glsl-1.20@execution@vector-out-of-bounds-access@fs-vec4-out-of-bounds-1
spec@glsl-1.20@execution@vector-out-of-bounds-access@fs-vec4-out-of-bounds-6

CC: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Marcin Ĺšlusarz <marcin.slusarz@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6363>
.gitlab-ci/piglit/quick_shader.txt
src/compiler/glsl/lower_vector_derefs.cpp