Bug 53977 - gcc produces bad code when using -O2 option
gcc produces bad code when using -O2 option
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.2
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-09-24 17:09 EDT by Marius Kintel
Modified: 2007-04-18 12:37 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-12-15 12:47:50 EST
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 17:11 EDT, Marius Kintel
no flags Details

  None (edit)
Description Marius Kintel 2001-09-24 17:09:43 EDT
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 17:11:49 EDT
Created attachment 32539 [details]
.cpp file triggering the bug.
Comment 2 William Cohen 2002-04-30 17:33:44 EDT
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 12:47:50 EST
Ok with 3.2

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