public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: iain.templeton@cisra.canon.com.au
To: gcc-gnats@gcc.gnu.org
Subject: optimization/5328: Optimisation causes code ordering to be incorrect on x86
Date: Tue, 08 Jan 2002 18:56:00 -0000	[thread overview]
Message-ID: <20020109024845.0790C2015E@yves.research.canon.com.au> (raw)


>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:


             reply	other threads:[~2002-01-09  2:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-08 18:56 iain.templeton [this message]
2002-02-06  8:05 jakub

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020109024845.0790C2015E@yves.research.canon.com.au \
    --to=iain.templeton@cisra.canon.com.au \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).