Bug 121114 - Wrong floating-point code generated (Bad fcomi instruction)
Summary: Wrong floating-point code generated (Bad fcomi instruction)
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 9
Hardware: i686
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
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:
Clone Of:
Environment:
Last Closed: 2004-04-19 09:37:56 UTC
Embargoed:


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

get_path_loss:
	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
	ret

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):
gcc-3.2.2-5

How reproducible:
Always

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.