Bug 22576 - [4.0/4.1 regression] ICE with simple factorial program compiled with -ffast-math on gcc 4.0.2
Summary: [4.0/4.1 regression] ICE with simple factorial program compiled with -ffast-m...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.2
: P2 normal
Target Milestone: 4.0.2
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2005-07-20 19:29 UTC by Paul Lauria
Modified: 2005-07-21 20:33 UTC (History)
2 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-20 21:26:27


Attachments
bug causing program... (437 bytes, text/plain)
2005-07-20 19:29 UTC, Paul Lauria
Details
-save-temps output (3.38 KB, text/plain)
2005-07-20 19:29 UTC, Paul Lauria
Details
-save-temps output (77 bytes, text/plain)
2005-07-20 19:30 UTC, Paul Lauria
Details
#included file (5.67 KB, text/plain)
2005-07-20 19:33 UTC, Paul Lauria
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Lauria 2005-07-20 19:29:06 UTC
Hello. Sorry if the summary is a little vague, I dont really know a whole bunch
about gcc terminology ;) So anyway, I wrote a simple program in C that computes
the factorials of numbers 1 through 100 (yes, after 7 they get super big). When
this program is compiled as 

gcc -ffast-math factorial.c

I get an ICE;

paul@nephilim:~/c$ gcc -Wall -ffast-math factorials.c
factorials.c:8: warning: return type defaults to ‘int’
factorials.c: In function ‘main’:
factorials.c:24: internal compiler error: in instantiate_virtual_regs_lossage,
at function.c:1442
paul@nephilim:~/c$ gcc -dumpversion
4.0.2

This gcc is from Ubuntu-breezy, gcc-4.0 branch, CVS 20050718. Running on a
Pentium 4.

It told me to report this bug, so here I am :) Regardless of whether this can be
done in a simpler manner, and I'm /sure/ it can, I dont think gcc should die
because of it. The offending code is attached. -save-temps output also attached.
Comment 1 Paul Lauria 2005-07-20 19:29:39 UTC
Created attachment 9309 [details]
bug causing program...
Comment 2 Paul Lauria 2005-07-20 19:29:59 UTC
Created attachment 9310 [details]
-save-temps output
Comment 3 Paul Lauria 2005-07-20 19:30:20 UTC
Created attachment 9311 [details]
-save-temps output
Comment 4 Paul Lauria 2005-07-20 19:32:28 UTC
If it is at all relevant, I'm using the glibc that breezy provides (2.3.5).
Comment 5 Andrew Pinski 2005-07-20 19:33:09 UTC
This is a target bug.
Comment 6 Paul Lauria 2005-07-20 19:33:28 UTC
Created attachment 9312 [details]
#included file
Comment 7 Volker Reichelt 2005-07-20 21:26:27 UTC
Reduced testcase:

========================
int foo(long double d)
{
    return d==0;
}
========================

Comparison of long doubles with zero seems to be a problem.
This is a regression from gcc 3.4.x.
Comment 8 Paul Lauria 2005-07-20 23:13:10 UTC
Comment on attachment 9309 [details]
bug causing program...

>#include <stdio.h>
>
>/* Program prints the first 10 postitive integers and their factorials */
>
>main()
>{
>long double i, j, k = 1;
>
>for(i = 1; i <= 100; i++) 
>	{
>	for(j = i; j > 0; j = j - 1)
>		{		
>		k = k * j; 			
>		if(j == 1) 	
>			{
>			printf("factorial of %Lf is %Lf\n", i, k);
>			k = 1; 
>			}
>		}
>	}
>	return 0;
>}
Comment 9 Uroš Bizjak 2005-07-21 08:01:06 UTC
Patch that fixes attached testcase and reduced testcase from comment #7.

BTW: In the attached testcase, there is a comment that program falls apart if 
long double isn't used. With (patched) gcc-4.1 CVS, it works for me with "only" 
doubles, with SSE or x87 math, -ffast-math or without it.

...
factorial of 99 is 9.33262e+155
factorial of 100 is 9.33262e+157

Comment 10 Volker Reichelt 2005-07-21 17:07:20 UTC
The problem is related to PR22585 where another ICE with long doubles occurs.
Unfortunately Uros' patch doesn't fix the problem there.
Comment 11 GCC Commits 2005-07-21 19:55:07 UTC
Subject: Bug 22576

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2005-07-21 19:55:03

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.md 

Log message:
	PR target/22576
	* config/i386/i386.md (cmpxf): Change operand constraints
	to "nonmemory_operand".

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9504&r2=2.9505
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.md.diff?cvsroot=gcc&r1=1.649&r2=1.650

Comment 12 GCC Commits 2005-07-21 19:56:37 UTC
Subject: Bug 22576

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	rth@gcc.gnu.org	2005-07-21 19:56:30

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.md 

Log message:
	PR target/22576
	* config/i386/i386.md (cmpxf): Change operand constraints
	to "nonmemory_operand".

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.325&r2=2.7592.2.326
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.md.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.618.4.4&r2=1.618.4.5

Comment 13 Andrew Pinski 2005-07-21 20:33:21 UTC
Fixed.
Comment 15 GCC Commits 2005-10-07 05:32:44 UTC
Subject: Bug 22576

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	uros@gcc.gnu.org	2005-10-07 05:32:37

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.c sse.md 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.target/i386: pr22576.c pr22585.c pr23570.c 

Log message:
	PR target/23570
	* config/i386/sse.md (*sse_concatv2sf): Change operand 2 constraint
	to "reg_or_0_operand".
	(sse2_loadld): Change operand 1 constraint to "reg_or_0_operand".
	
	testsuite/
	
	PR target/22576
	* gcc.target/i386/pr22576.c: New test.
	
	PR target/22585
	* gcc.target/i386/pr22585.c: New test.
	
	PR target/23570
	* gcc.target/i386/pr23570.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.451&r2=2.7592.2.452
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.795.6.11&r2=1.795.6.12
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/sse.md.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.7.14.2&r2=1.7.14.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.434&r2=1.5084.2.435
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.target/i386/pr22576.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.10.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.target/i386/pr22585.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.2.10.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.target/i386/pr23570.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.20.1