From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29050 invoked by alias); 9 Jan 2002 02:56:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 28960 invoked by uid 71); 9 Jan 2002 02:56:00 -0000 Resent-Date: 9 Jan 2002 02:56:00 -0000 Resent-Message-ID: <20020109025600.28959.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, iain.templeton@cisra.canon.com.au Received:(qmail 17619 invoked from network); 9 Jan 2002 02:48:48 -0000 Received: from unknown (HELO b.mx.canon.com.au) (203.12.172.125) by sources.redhat.com with SMTP; 9 Jan 2002 02:48:48 -0000 Received: from bellmann.research.canon.com.au (kwanon.research.canon.com.au [203.12.172.254]) by b.mx.canon.com.au (Postfix) with ESMTP id 8E5F91AC716 for ; Wed, 9 Jan 2002 02:48:47 +0000 (GMT) Received: from yves.research.canon.com.au (yves.research.canon.com.au [10.8.1.15]) by bellmann.research.canon.com.au (Postfix) with ESMTP id 37EE28B2B for ; Wed, 9 Jan 2002 13:28:11 +1100 (EST) Received: by yves.research.canon.com.au (Postfix, from userid 683) id 0790C2015E; Wed, 9 Jan 2002 13:48:45 +1100 (EST) Message-Id:<20020109024845.0790C2015E@yves.research.canon.com.au> Date: Tue, 08 Jan 2002 18:56:00 -0000 From: iain.templeton@cisra.canon.com.au To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:3.113 Subject: optimization/5328: Optimisation causes code ordering to be incorrect on x86 X-SW-Source: 2002-01/txt/msg00373.txt.bz2 List-Id: >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: