Bug 121114 - Wrong floating-point code generated (Bad fcomi instruction)
Summary: Wrong floating-point code generated (Bad fcomi instruction)
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc   
(Show other bugs)
Version: 9
Hardware: i686 Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
Depends On:
TreeView+ depends on / blocked
Reported: 2004-04-17 13:59 UTC by r6144
Modified: 2007-04-18 17:06 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-04-19 09:37:56 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description r6144 2004-04-17 13:59:54 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5)
Gecko/20031016 Galeon/1.3.11a

Description of problem:
The following code is incorrectly compiled by gcc 3.2.2-5 when using
options "-march=pentium4 -O2 -ffast-math -mfpmath=sse":

=== CUT HERE ===
const double max_loss = 1e7;

double get_basic_path_loss(double a)
  return 1.0;

double get_path_loss(void)
  double loss;

  loss = get_basic_path_loss(1.0);
  return (loss < max_loss) ? loss : max_loss;

int main(void)
  return get_path_loss() < 1e7 ? 0 : 1;
=== CUT HERE ===

get_path_loss() should return 1.0, therefore main() should return 0,
but actually 1 is returned.

The generated assembly for get_path_loss() is

	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp
	movl	$0, (%esp)
	movl	$1072693248, 4(%esp)
	call	get_basic_path_loss
	fstpl	-8(%ebp)
	fldl	.LC2
	fldl	-8(%ebp)
	fcomi	%st(0), %st
	fcmovbe	%st(1), %st
	fstp	%st(1)
	movl	%ebp, %esp
	popl	%ebp

The "fcomi" instruction seems to be wrong.

Stock gcc-3.4-cvs seems to be fine.  I have not tried other versions.
 I will upgrade if I have to, but I hope someone will make sure that
the bug is really fixed.

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

How reproducible:

Steps to Reproduce:
1. Saved the sample program above as test.c.
2. Compile it as follows:
gcc -o test -march=pentium4 -O2 -ffast-math -mfpmath=sse test.c
3. Run it:
./test ; echo $?


Actual Results:  1

(which is the exit code from ./test)

Expected Results:  0

Additional info:

Comment 1 Jakub Jelinek 2004-04-19 09:37:56 UTC
This testcase works in 3.3.3-7 (current rawhide compiler).

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