possible bug in 4.1.2 g++ arm compiler -O2 optimization
Blair Barnett
blairbarnett@sbcglobal.net
Tue Oct 14 20:57:00 GMT 2008
I already sent this to gcc-help@gcc.gnu.org, but no responses, so posting here also.
-b
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;
}
More information about the Gcc-bugs
mailing list