Bug 53977 - gcc produces bad code when using -O2 option
Summary: gcc produces bad code when using -O2 option
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc   
(Show other bugs)
Version: 7.2
Hardware: i686
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
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:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-12-15 17:47:50 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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
option:
$ 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:
Always

Steps to Reproduce:
1. compile
2. run
3.
	

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.