nir/lower_io: don't reduce range if parent length is zero
After commit f3b33a5a landed, the following test started to fail with v3dv: dEQP-VK.graphicsfuzz.cov-simplify-clamp-max-itself
with the following assertion:
error: nir_intrinsic_range(instr) != 0 (../src/compiler/nir/nir_validate.c:605)
Initially I thought that perhaps we were calling nir_lower_explicit_io too early, as we are doing it before lowering vulkan resource index and similar. So doing that later fixed that text, but introduced a regression on dEQP-VK.graphicsfuzz.function-with-uniform-return. For this one there is an existing ANV issue #2357 (closed). First thing I tried was @jekstrand patch at MR !4747. But that one removed one assertion ("src failed") and introduced other. Also final nir generated was somewhat more complex.
So then I moved to investigate the issue and wrote the patch included with this MR. What I found is that when computing the ranges, for that test, it ends with a range_base/range of 0,0, raising that assertion. That value is computed at nir_get_explicit_deref_range. When adding to the range the stride based on the array size, for that test the type length is zero. Curiously the parent type is ivec4. As far as I understand that code, that line is intended to increase or keep the range size, not reduce it, so I just avoid any change with parent length being zero.
The reason of this being WIP is that Im not sure if that is the correct solution, and if parent length being zero was a possible case at that point. Perhaps should return 0, ~0 instead?
Any comment is welcome.
CCing @anholt too.