From jeremyp@gsmx07.alcatel.com.au  Wed Nov 28 16:01:51 2001
Return-Path: <jeremyp@gsmx07.alcatel.com.au>
Received: from netau1.alcanet.com.au (ntp.alcanet.com.au [203.62.196.27])
	by hub.freebsd.org (Postfix) with ESMTP id 5E23D37B416
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Nov 2001 16:01:48 -0800 (PST)
Received: from mfg1.cim.alcatel.com.au (mfg1.cim.alcatel.com.au [139.188.23.1])
	by netau1.alcanet.com.au (8.9.3 (PHNE_22672)/8.9.3) with ESMTP id LAA13087
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Nov 2001 11:01:41 +1100 (EDT)
Received: from gsmx07.alcatel.com.au by cim.alcatel.com.au
 (PMDF V5.2-32 #37641) with ESMTP id <01KB9VDJC5U8VFKI5H@cim.alcatel.com.au>
 for FreeBSD-gnats-submit@freebsd.org; Thu, 29 Nov 2001 11:00:54 +1100
Received: (from jeremyp@localhost)	by gsmx07.alcatel.com.au (8.11.6/8.11.6)
 id fAT013876664; Thu, 29 Nov 2001 11:01:03 +1100 (EST envelope-from jeremyp)
Message-Id: <200111290001.fAT013876664@gsmx07.alcatel.com.au>
Date: Thu, 29 Nov 2001 11:01:03 +1100 (EST)
From: Peter Jeremy <peter.jeremy@alcatel.com.au>
To: FreeBSD-gnats-submit@freebsd.org
Subject: gcc optimiser bug with -O -march=i686
X-Send-Pr-Version: 3.113
X-GNATS-Notify: ru

>Number:         32365
>Category:       gnu
>Synopsis:       gcc optimiser bug with -O -march=i686
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    obrien
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 28 16:10:01 PST 2001
>Closed-Date:    Tue May 06 16:28:36 PDT 2003
>Last-Modified:  Tue May 06 16:28:36 PDT 2003
>Originator:     Peter Jeremy
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Alcatel Australia Limited
>Environment:
System: FreeBSD gsmx07.alcatel.com.au 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Mon Nov 26 08:22:11 EST 2001 root@gsmx07.alcatel.com.au:/usr/obj/3.0/cvs/src/sys/gsmx i386

This bug also appears in a recent 4-STABLE.

	
>Description:
	gcc generates incorrect code for the program below when compiled
	with options "-O -march=i686".  The problem appears to be an
	incorrect assumption in	gcc/config/i386/i386.c:notice_update_cc()
	which assumes that moves don't affect condition codes.  The
	double arguments are passed using movdf_push, but the IA32
	doesn't have a floating point push, so this is implemented as
	a store followed by a stack pointer adjustment - which does
	affect CC.  Changing all the floating point constants/arguments
	to integer removes the bug.

	This showed up building the gnuplot port.  I don't know if
	it affects anything in the base system.

>How-To-Repeat:
	Save the following code as x.c and compile with
	"/usr/libexec/cc1 -O -march=i686 -quiet x.c"
---
int x;

void foo(double, double);

void bar()
{
	foo(x?1.5:1.0, x?1.5:1.0);
}
---
	This results in the following assember (annotations added by me):
---
	.file	"x.c"
	.version	"01.01"
gcc2_compiled.:
	.section	.rodata
	.p2align 3
.LC0:
	.long 0x0,0x3ff80000
.text
	.p2align 2,0x90
.globl bar
		.type		 bar,@function
bar:
	pushl %ebp
	movl %esp,%ebp
	subl $8,%esp
	fld1
	movl x,%eax
	fldl .LC0
	fld %st(1)
	testl %eax,%eax		<-- this is the "x?" part of the code.
	fcmovne %st(1),%st
	subl $8,%esp		<-- this destroys CC from the above testl
	fstpl (%esp)
	fcmove %st(1),%st	<-- this assumes the testl CC is still valid
	fstp %st(1)
	subl $8,%esp
	fstpl (%esp)
	call foo
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe1:
		.size		 bar,.Lfe1-bar
	.comm	x,4,4
	.ident	"[ASM_FILE_END]GCC: (c) 2.95.3 20010315 (release)"
---
>Fix:
	Not known at this time.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: ru 
Responsible-Changed-When: Thu Nov 29 00:32:54 PST 2001 
Responsible-Changed-Why:  
David, would you please take care of this? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32365 

From: Peter Pentchev <roam@ringlet.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: gnu/32365: gcc optimiser bug with -O -march=i686
Date: Thu, 29 Nov 2001 15:35:36 +0200

 On Thu, Nov 29, 2001 at 12:33:24AM -0800, ru@FreeBSD.org wrote:
 > Synopsis: gcc optimiser bug with -O -march=i686
 > 
 > Responsible-Changed-From-To: freebsd-bugs->obrien
 > Responsible-Changed-By: ru
 > Responsible-Changed-When: Thu Nov 29 00:32:54 PST 2001
 > Responsible-Changed-Why: 
 > David, would you please take care of this?
 
 Please also take a look at the recent thread in -hackers:
 
  Subject: add some constraints in cpufunc.h
  Message-ID: <00e701c17264$a4617130$ef01a8c0@davidwnt>
 
 G'luck,
 Peter
 
 -- 
 This sentence contradicts itself - or rather - well, no, actually it doesn't!
State-Changed-From-To: open->closed 
State-Changed-By: gerald 
State-Changed-When: Tue May 6 16:22:00 PDT 2003 
State-Changed-Why:  
Would you mind checking whether this still applies, and if it does, report 
the problem to the GCC developers using http://gcc.gnu.org/cgi-bin/gnatsweb.pl? 

I'm sorry I hadn't noticed this earlier, but it seems the problem has been 
solved with the rewrite of the i386 backend for GCC 3.x? 

.file   "x.c" 
.section        .rodata.cst4,"aM",@progbits,4 
.align 4 
.LC0: 
.long   1069547520 
.text 
.globl bar 
.type   bar, @function 
bar: 
pushl   %ebp 
movl    %esp, %ebp 
subl    $24, %esp 
cmpl    $0, x 
je      .L2 
flds    .LC0 
jmp     .L3 
.L2: 
fld1 
.L3: 
fstpl   8(%esp) 
cmpl    $0, x 
je      .L4 
flds    .LC0 
jmp     .L5 
.L4: 
fld1 
.L5: 
fstpl   (%esp) 
call    foo 
movl    %ebp, %esp 
popl    %ebp 
ret 
.size   bar, .-bar 
.comm   x,4,4 
.ident  "GCC: (GNU) 3.3 20030429 (prerelease)" 

http://www.freebsd.org/cgi/query-pr.cgi?pr=32365 
>Unformatted:
