Bug 53977

Summary: gcc produces bad code when using -O2 option
Product: [Retired] Red Hat Linux Reporter: Marius Kintel <kintel>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact: Brian Brock <bbrock>
Severity: high Docs Contact:
Priority: medium    
Version: 7.2CC: t8m
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
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: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
.cpp file triggering the bug. none

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