On Fri, May 8, 2026 at 10:48 PM Ionuț Nicula via Gcc <[email protected]> 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++;
>         }
>     }
>
>

Reply via email to