https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126941

--- Comment #3 from Alfie Richards <alfierichards at gcc dot gnu.org> ---
So to take a really simple case, the below generates code that looks like:

> unsigned long foo (char);
> int bad_addressing (char *arr1, unsigned long n) {
>     for (unsigned long i = 0; i < n;) {
>        *arr1 += 1;
>        unsigned long advance = foo (*arr1);
>        arr1 += advance;
>        i += advance;
>     }
> }

Generates the following loop body

> .L3:
>        ldrb    w0, [x19]
>        add     w0, w0, 1
>        strb    w0, [x19]
>        bl      foo
>        add     x20, x20, x0
>        add     x19, x19, x0
>        cmp     x21, x20
>        bhi     .L3

Where it could do


> .L3:
>        ldrb    w0, [x19, x20]
>        add     w0, w0, 1
>        strb    w0, [x19, x20]
>        bl      foo
>        add     x20, x20, x0
>        cmp     x21, x20
>        bhi     .L3

As arr1 can be safely expressed as arr1_base + advance (even with overflow
considerations)

Reply via email to