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

--- Comment #2 from Anton Blanchard <anton at ozlabs dot org> ---
In this case it took -flto to trigger, but I'm not sure if it is -flto
specific.

When trying to understand the problem I ended up with the following test case.
The call to tick() after the loop causes gcc to write VXRM every row, remove it
and we hoist it before the loop.

#include <stdint.h>

void tick(void);

void avg_then_call(uint8_t *dst, const uint8_t *s1, const uint8_t *s2,
                   int w, int h, int ds, int ss1, int ss2)
{
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++)
            dst[x] = (s1[x] + s2[x] + 1) >> 1;
        dst += ds; s1 += ss1; s2 += ss2;
    }
    tick();
}

bad:

.L3:
        minu    t1,a2,t2
        bleu    t1,a7,.L18
        csrwi   vxrm,0
        mv      t4,s1
        mv      t3,a0
        mv      t6,a5
        mv      t5,a1
.L4:
        vsetvli t1,t4,e8,m1,ta,ma
        vle8.v  v1,0(t5)
        vle8.v  v2,0(t6)
        sub     t4,t4,t1
        add     t5,t5,t1
        add     t6,t6,t1
        vaaddu.vv       v1,v1,v2
        vse8.v  v1,0(t3)
        add     t3,t3,t1
        bne     t4,zero,.L4
        addiw   a4,a4,1
        add     a0,a0,a3
        add     a1,a1,a6
        add     a5,a5,s2
        add     a2,a2,s4
        add     t2,t2,s3
        add     t0,t0,a6
        bne     s0,a4,.L3

good (remove call to tick()):

.L3:
        minu    t1,a2,t2
        bleu    t1,a7,.L19
        mv      t4,s1
        mv      t3,a0
        mv      t6,a5
        mv      t5,a1
.L4:
        vsetvli t1,t4,e8,m1,ta,ma
        vle8.v  v1,0(t5)
        vle8.v  v2,0(t6)
        sub     t4,t4,t1
        add     t5,t5,t1
        add     t6,t6,t1
        vaaddu.vv       v1,v1,v2
        vse8.v  v1,0(t3)
        add     t3,t3,t1
        bne     t4,zero,.L4
        addiw   a4,a4,1
        add     a0,a0,a3
        add     a1,a1,a6
        add     a5,a5,s2
        add     a2,a2,s4
        add     t2,t2,s3
        add     t0,t0,a6
        bne     s0,a4,.L3

Reply via email to