On Monday, May 11th, 2026 at 12:55, Richard Biener
<[email protected]> wrote:

> 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.

Sorry, I somehow messed up my tests and misunderstood what was going on.

I was more interested in this example. This doesn't get vectorized (`-O3
-march=znver5 -ffreestanding`):

    unsigned long foo(uint8_t *data) {
        unsigned long i = 0;
        while (1) {
            if (data[i] == 0)
                return i;
            i++;
        }
    }

But this does:

    long foo(uint8_t *data) {
        long i = 0;
        while (1) {
            if (data[i] == 0)
                return i;
            i++;
        }
    }

`unsigned long` index coupled `uint16_t *` data does get vectorized,
though.

Is it because technically `uint8_t[size_t]` can span the whole address
space and therefore the `size_t` index can validly wrap around, whereas
`uint16_t[size_t]` is bounded by the address space so you can never
reach `uint16_t[2 + (SIZE_MAX/2)]`?

Reply via email to