Possible ARM 4.1.2 g++ optimizer bug

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

 



I seem to have found a bug in the ARM 4.1.2 g++ optimization code. This attached test case demonstrates an apparent optimizer bug in the 4.1.2 ARM g++ compiler.

Compile this code:

            arm-linux-g++ -O2 -S optbug.cpp

 and look at the assembly for the test() method:

 _ZN6OptBug4testEv:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldr     r0, [r0, #1028]
        ldr     r3, [r0, #1024]
        sub     r0, r3, r0
        cmp     r0, #16384
        movlt   r0, #0
        movge   r0, #1
       @ lr needed for prologue
       mov     pc, lr

 Notice the two ldr instructions. The first puts a value into r0 but the
 second assumes r0 has not been modified. The order of the two lines appears
 to be flipped.


I'm hoping there is a patch for this problem and if not, perhaps there is a work-around you folks can suggest. I'm tied to this tool chain version for the near term.

Thanks in advance for any assistance you can provide.

Blair


=========================cut here===========================
#include <stdio.h>

// This test case demonstrates an optimizer bug in the 4.1.2 ARM g++ compiler.
// Compile this code:
//
//            arm-linux-g++ -O2 -S optbug.cpp
//
// and look at the assembly for the test() method:
//
// _ZN6OptBug4testEv:
//        @ args = 0, pretend = 0, frame = 0
//        @ frame_needed = 0, uses_anonymous_args = 0
//        @ link register save eliminated.
//        ldr    r0, [r0, #1028]
//        ldr    r3, [r0, #1024]
//        sub    r0, r3, r0
//        cmp    r0, #16384
//        movlt  r0, #0
//        movge  r0, #1
//        @ lr needed for prologue
//        mov    pc, lr
//
// Notice the two ldr instructions. The first puts a value into r0 but the
// second assumes r0 has not been modified. The order of the two lines appears
// to be flipped.

class OptBug
{
public:
    OptBug(): v1(200), v2(200) {}

    bool test();

protected:
    // The presence of this buffer effects the type of assembly that is
    // generated. With the buffer around 1024 we get the assembly with the bug.
    char data[1024];
   
    int v1;
    int v2;
};



bool OptBug::test()
{
    if ((v2 - v1) < 16*1024)
        return false;

    return true;
}

int main(int argc, char **argv)
{
    OptBug ob;
   
    printf("Should return 0\n");
    printf("%d\n", ob.test());
    return 0;
}



[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