Uncounted loop vectorization example doesn't work with unsigned index
Richard Biener
richard.guenther@gmail.com
Mon May 11 11:55:34 GMT 2026
On Fri, May 8, 2026 at 10:48 PM Ionuț Nicula via Gcc <gcc@gcc.gnu.org> wrote:
>
> Regarding the new uncounted loop vectorization capability in GCC 16: is
> it a known current limitation that the 'simple' uncounted vectorization
> example (i.e. gcc/testsuite/gcc.dg/vect/vect-uncounted_1.c) doesn't work
> if you use an *unsigned* type for indexing?
>
> This gets vectorized:
>
> int foo(int *haystack, int needle) {
> int i = 0;
> while (1) {
> if (haystack[i] == needle)
> return i;
> i++;
> }
> }
>
> But this doesn't get vectorized:
>
> unsigned foo(int *haystack, int needle) {
> unsigned i = 0;
> while (1) {
> if (haystack[i] == needle)
The reason is that i might overflow and thus
the evolution of 'i' for the haystack[i] access isn't affine.
Use unsigned long and it works again.
This is a general issue with unsigned IVs smaller than
pointer size.
> return i;
> i++;
> }
> }
>
>
More information about the Gcc
mailing list