Re: Uncounted loop vectorization example doesn't work with unsigned index

Richard Biener via Gcc <[email protected]>
Newsgroups gmane.comp.gcc.devel
Message-ID <CAFiYyc2fQx1xmFf3xTTg-j-XFE8tKwLYtzgq6+Ob0wq+UuUJDw@mail.gmail.com>
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++;
>         }
>     }
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.