Bug 121114 - Wrong floating-point code generated (Bad fcomi instruction)
Wrong floating-point code generated (Bad fcomi instruction)
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
9
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-04-17 09:59 EDT by r6144
Modified: 2007-04-18 13:06 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-04-19 05:37:56 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description r6144 2004-04-17 09:59:54 EDT
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 05:37:56 EDT
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.