Bug 53977 - gcc produces bad code when using -O2 option
Summary: gcc produces bad code when using -O2 option
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.2
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2001-09-24 21:09 UTC by Marius Kintel
Modified: 2007-04-18 16:37 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2002-12-15 17:47:50 UTC

Attachments (Terms of Use)
.cpp file triggering the bug. (374 bytes, text/plain)
2001-09-24 21:11 UTC, Marius Kintel
no flags Details

Description Marius Kintel 2001-09-24 21:09:43 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.3-20mdk i686)

Description of problem:
The attached program produces wrong output when compiled with the -O2
$ gcc -o gcctest gcctest.cpp
$ ./gcctest
result: -3.000000
$ gcc -o gcctest gcctest.cpp -O2
$ ./gcctest
result: 3.000000

This is tested under gcc-2.96-69 (RH-7.0), gcc-2.96-85 (RH-7.1) and
gcc-2.96-0.48mdk (Mandrake 8.0).

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. compile
2. run

Additional info:

Comment 1 Marius Kintel 2001-09-24 21:11:49 UTC
Created attachment 32539 [details]
.cpp file triggering the bug.

Comment 2 William Cohen 2002-04-30 21:33:44 UTC
The compiler is mis-optimizing the code when -O2 set. The following code from
init function implement "f = -(v0+1);":

	flds	12(%ebp)
	fadds	.LC0
	fstps	12(%ebp)
	flds	12(%ebp)       /* load into fp register */
	xorb	$128, 15(%ebp) /* value in fp register, not memory */
	fstps	(%eax)
	movl	-12(%ebp), %eax
	movl	%eax, (%esi)

The "xorb $128, 15(%ebp)" should be a "fchs" instruction.

Comment 3 Alan Cox 2002-12-15 17:47:50 UTC
Ok with 3.2

Note You need to log in before you can comment on or make changes to this bug.