This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/5328: Optimisation causes code ordering to be incorrect on x86
- From: iain dot templeton at cisra dot canon dot com dot au
- To: gcc-gnats at gcc dot gnu dot org
- Date: Wed, 9 Jan 2002 13:48:45 +1100 (EST)
- Subject: optimization/5328: Optimisation causes code ordering to be incorrect on x86
>Number: 5328
>Category: optimization
>Synopsis: Optimisation causes code ordering to be incorrect on x86
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Jan 08 18:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Iain Templeton
>Release: 3.0.2
>Organization:
Canon Information Systems Research Australia
>Environment:
System: Linux yves.research.canon.com.au 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
Architecture: i686
PIII-850/Linux 2.4.2/Redhat 7.1
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --prefix=/opt/gcc-3.0.2
>Description:
A really simple bit of code shown below comes out with the comparison
instruction and the mov instruction the wrong way around when using -O2.
Using -O2 -fno-schedule-insns2 doesn't show this problem, and neither
does -O1 -fschedule-insns -fschedule-insns2
This problem also effects 2.96 (but we don't talk about that). 2.95.3 (on
FreeBSD though) doesn't do this, rather it does it using some other kind
of optimisation and never outputs the assert test.
Ie:
gcc test.c -S -o test.S -O2 WRONG
gcc test.c -S -o test.S -O2 -fno-schedule-insns2 OK
gcc test.c -S -o test.S -O1 -fschedule-insns -fschedule-insns2 OK
gcc -v gives:
yves% gcc -v -save-temps -O2 -S simpletest.c -o simpletest.S
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-85)
/usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v -iprefix /opt/bin/../lib/gcc-lib/i386-redhat-linux/2.96/ -D__GNUC__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__OPTIMIZE__ -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ simpletest.c simpletest.i
GNU CPP version 2.96 20000731 (Red Hat Linux 7.1 2.96-85) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/opt/lib/gcc-lib/i386-redhat-linux/2.96/include"
ignoring nonexistent directory "/opt/i386-redhat-linux/include"
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-lib/i386-redhat-linux/2.96/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1 simpletest.i -quiet -dumpbase simpletest.c -O2 -version -o simpletest.S
GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-85) (i386-redhat-linux) compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-85).
The assembly below gives the output, the cmpl is before the movl.
.file "simpletest.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "main"
.LC1:
.string "simpletest.c"
.align 32
.LC2:
.string "(f1 = -12345.6789F, *(unsigned int *)&f1 == 0xC640E6B7U)"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
cmpl $-968825161, -4(%ebp)
movl $0xc640e6b7, -4(%ebp)
je .L4
pushl $.LC0
pushl $7
pushl $.LC1
pushl $.LC2
call __assert_fail
.p2align 2
.L4:
xorl %eax, %eax
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-85)"
>How-To-Repeat:
Compile the C code and look at the assembler output.
-- Code Start
extern void __assert_fail (__const char *__assertion, __const char *__file,
unsigned int __line, __const char *__function)
__attribute__ ((__noreturn__));
extern void __assert_perror_fail (int __errnum, __const char *__file,
unsigned int __line,
__const char *__function)
__attribute__ ((__noreturn__));
extern void __assert (const char *__assertion, const char *__file, int __line)
__attribute__ ((__noreturn__));
int main(int argc, char **argv)
{
float f1;
/* assert((f1 = -12345.6789F, *(unsigned int *)&f1 == 0xC640E6B7U)); */
((void) (((f1 = -12345.6789F, *(unsigned int *)&f1 == 0xC640E6B7U)) ? 0 : (__assert_fail ("(f1 = -12345.6789F, *(unsigned int *)&f1 == 0xC640E6B7U)", "simpletest.c", 7, __PRETTY_FUNCTION__), 0)));
return 0;
}
-- Code End
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: