Re: Amusing bad code generation for ARM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2010-04-21 16:56, Ian Lance Taylor wrote:
This is presumably happening because of the volatile declarations.

Further experimentation reveals that it isn't the case. The following code:

    struct A { int r0; int r1; };
    void ugh(struct A *restrict a, const int *restrict d)
    {
        for (int i = 0; i < 8; ++i) {
            if (*d++)
                a->r0 = 1;
            else
                a->r1 = 1;
        }
    }

compiled using

    arm-none-eabi-gcc -O3 -S -o- -std=c99 tmp.c

also produces very suboptimal code:

ugh:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldr     r3, [r1, #0]
        cmp     r3, #0
        moveq   r2, #1
        movne   r2, #1
        streq   r2, [r0, #4]
        strne   r2, [r0, #0]
        ldr     r2, [r1, #4]
        cmp     r2, #0
        add     r3, r1, #4
        moveq   r1, #1
        movne   r1, #1
        streq   r1, [r0, #4]
        strne   r1, [r0, #0]
        add     r2, r3, #4
        ldr     r3, [r3, #4]
        cmp     r3, #0
        moveq   r1, #1
        movne   r1, #1
        streq   r1, [r0, #4]
        strne   r1, [r0, #0]
        add     r3, r2, #4
        ldr     r2, [r2, #4]
        ... and keeps repeating six times more...

Note the silly reloading of r1. I'll file a bug report about this case instead.

/Tobias


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux