NIR loop analysis can't analyze some loops that it seems like it could
I've been working on a loop transformation pass that converts loops like
x = ...
for (i = 0; i != 8; i++) {
... i + x ...
}
into
x = ...
for (i = x; i != (8 + x); i++) {
... i ...
}
Loop analysis is able to determine that the original loop executes 8 times, but it is unable to determine anything about the second loop.
This does occur in a real shader. In fossils/fossil-db/steam-dxvk/fallout_4_dxvk_g2.foz/a9c768ea760e5d3c/compute, there is a shader that looks something like
i = 0;
do {
if (i != 0)
break;
... i + x ...
i++;
} while (true);
The transformation converts this to
i = x;
do {
if (i != x)
break;
... i ...
i++;
} while (true);
Solving the general problem is likely difficult, but it seems like this limited case should be easier. I have no idea whether any real shaders contain this pattern without the transformation I'm developing.