http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61131
Bug ID: 61131
Summary: [4.8 regression] ARM -Os: incorrect code generation
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: swarren at nvidia dot com
Created attachment 32771
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32771&action=edit
Source sample that exhibits the issue when compiled
When running gcc 4.8 for ARM with -Os, the following function:
int count_entries(struct s *p)
{
int i = 0;
while (p->fd[i] >= 0 && i < MAX_COUNT) {
i++;
}
return i;
}
... gets compiled to essentially a no-op:
000083f8 <count_entries>:
83f8: e5900000 ldr r0, [r0]
83fc: e1e00000 mvn r0, r0
8400: e1a00fa0 lsr r0, r0, #31
8404: e12fff1e bx lr
If I don't use -Os, then I get much larger, and working, code.
If I swap the order of the two conditions in the while expression, I get
working code:
while (i < MAX_COUNT && p->fd[i] >= 0) {
If I use gcc-4.7 insteaad, I get working code.
A complete source sample is attached.
The bug is NOT present in
gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux.tar.xz, which is
apparently GCC 4.7.2+svn197188.
The bug IS present in gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz,
which is apparently GCC 4.8.3+svn208968.
I wasn't able to quickly track down any more recent gcc-4.8.x binaries, or
gcc-4.9.x binaries.
The bug IS present in some toolchain I received from a customer in directory
name yocto/gcc-4.8.1-glibc-2.18-hard/.