User account creation filtered due to spam.

Bug 8178 - [3.4 regression] __builtin_ffs broken with -march=k6
Summary: [3.4 regression] __builtin_ffs broken with -march=k6
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.0
: P1 critical
Target Milestone: 3.4.0
Assignee: Eric Botcazou
URL:
Keywords: ice-on-valid-code, monitored
Depends on:
Blocks:
 
Reported: 2002-10-09 17:06 UTC by christianbiere
Modified: 2004-01-17 04:22 UTC (History)
4 users (show)

See Also:
Host: i586-pc-linux-gnu
Target: i586-pc-linux-gnu
Build: i586-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-07-28 01:23:26


Attachments
if_pcn.i.bz2 (31.69 KB, application/octet-stream)
2003-05-21 15:17 UTC, christianbiere
Details

Note You need to log in before you can comment on or make changes to this bug.
Description christianbiere 2002-10-09 17:06:00 UTC
I wanted to compile the NetBSD GENERIC kernel. gcc 3.2 failed with this:

cc  -ffreestanding  -O0 -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wno-uninitialized  -Di386 -I.  -I../../../../arch -I../../../.. -nostdinc -DLKM -DMAXUSERS=32 -D_KERNEL -D_KERNEL_OPT   -c /sys/arch/i386/compile/GENERIC/../../../../dev/pci/if_pcn.c
/sys/dev/pci/if_pcn.c: In function `pcn_init':
/sys/dev/pci/if_pcn.c:1767: unrecognizable insn:
(insn 640 639 641 (parallel[ 
            (set (reg:CCZ 17 flags)
                (compare:CCZ (const_int 512 [0x200])
                    (const_int 0 [0x0])))
            (set (reg:SI 203)
                (unspec:SI[ 
                        (const_int 512 [0x200])
                    ]  5))
        ] ) -1 (nil)
    (nil))
/sys/dev/pci/if_pcn.c:1767: Internal compiler error in extract_insn, at recog.c:2148

This does only happen with with the option -O0 or if I use
no -Ox at all. The compiler does not fail if I use -O1,-O2 or -O3.

FYI, gcc 2.95.3 has a problem with the same piece of code as well:

/usr/bin/cc  -ffreestanding  -O0 -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wno-uninitialized  -Di386 -I.  -I../../../../arch -I../../../.. -nostdinc -DLKM -DMAXUSERS=32 -D_KERNEL -D_KERNEL_OPT   -c /sys/arch/i386/compile/GENERIC/../../../../dev/pci/if_pcn.c
/sys/arch/i386/compile/GENERIC/../../../../dev/pci/if_pcn.c: In function `pcn_init':
/sys/arch/i386/compile/GENERIC/../../../../dev/pci/if_pcn.c:1767: internal error--unrecognizable insn:
(insn 644 643 646 (set (reg:SI 170)
        (unspec:SI[ 
                (const_int 512 [0x200])
            ]  5)) -1 (nil)
    (nil))

Release:
3.2

Environment:
NetBSD/i386 1.6I

How-To-Repeat:
Instructions how to build the kernel can be read here:
http://www.netbsd.org/Documentation/kernel/#how_to_build_a_kernel

I have set the environment variable COPTS to '-O0'. If COPTS is not defined it will default to -O2.
Comment 1 Volker Reichelt 2002-11-22 15:19:32 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.
    
    The bug can be reproduced with the following line:
    
    int main() { return __builtin_ffs(4); }
    
    Just compile without optimization on i686-pc-linux-gnu.
    The bug affects all compilers since 2.95.x.
Comment 2 Volker Reichelt 2003-03-10 16:01:52 UTC
From: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
To: christianbiere@gmx.de, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org
Cc:  
Subject: Re: optimization/8178: __builtin_ffs broken
Date: Mon, 10 Mar 2003 16:01:52 +0100 (CET)

 The problem got apparently fixed on mainline.
 
 I'm leaving the PR open, since somebody might want to backport the fix
 to the 3.3 or 3.2 branch.
 
 Regards,
 Volker
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8178
 
 

Comment 3 Eric Botcazou 2003-03-10 16:41:50 UTC
From: Eric Botcazou <ebotcazou@libertysurf.fr>
To: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Cc: hristianbiere@gmx.de,
 gcc-gnats@gcc.gnu.org,
 gcc-bugs@gcc.gnu.org
Subject: Re: optimization/8178: __builtin_ffs broken
Date: Mon, 10 Mar 2003 16:41:50 +0100

 > The problem got apparently fixed on mainline.
 
 Probably by http://gcc.gnu.org/ml/gcc-patches/2003-02/msg00300.html
 
 > I'm leaving the PR open, since somebody might want to backport the fix
 > to the 3.3 or 3.2 branch.
 
 I'm still getting an ICE on k6 though: 
 http://gcc.gnu.org/ml/gcc-patches/2003-03/msg00707.html
 
 -- 
 Eric Botcazou

Comment 4 Volker Reichelt 2003-03-12 13:30:29 UTC
From: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
To: christianbiere@gmx.de, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
 rth@redhat.com, falk.hueffner@student.uni-tuebingen.de
Cc: ebotcazou@libertysurf.fr
Subject: Re: optimization/8178: __builtin_ffs broken
Date: Wed, 12 Mar 2003 13:30:29 +0100 (CET)

 I can confirm that the problem is still present on k6.
 According to Phil's tester the problem for the ix86 was fixed
 between 2003-01-31 and 2003-02-01.
 
 Therefore I strongly suspect that the following patch (by Richard
 Henderson and Falk Hueffner) was responsible for the fix:
 
 http://gcc.gnu.org/ml/gcc-cvs/2003-02/msg00033.html
 
 That's why I'm asking you, Richard and Falk, could you please
 have a look at the patch, whether it really did fix things and if yes,
 why it doesn't fix the k6-issue and whether the fix can be backported
 to 3.3 or even 3.2?
 
 Thanks,
 Volker
 
 

Comment 5 Richard Henderson 2003-03-12 16:42:15 UTC
From: Richard Henderson <rth@redhat.com>
To: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Cc: christianbiere@gmx.de, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
   falk.hueffner@student.uni-tuebingen.de, ebotcazou@libertysurf.fr,
   gcc-patches@gcc.gnu.org
Subject: Re: optimization/8178: __builtin_ffs broken
Date: Wed, 12 Mar 2003 16:42:15 -0800

 On Wed, Mar 12, 2003 at 01:30:29PM +0100, Volker Reichelt wrote:
 > I can confirm that the problem is still present on k6.
 > According to Phil's tester the problem for the ix86 was fixed
 > between 2003-01-31 and 2003-02-01.
 
 Backporting the patch you mention isn't an option, but
 this bug is fixable for 3.2/3.3 trivially.
 
 
 r~
 
 
 	* config/i386/i386.md (ffssi2): Tighten op1 predicate to 
 	match the requirements of the output insns.
 
 Index: gcc/config/i386/i386.md
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.md,v
 retrieving revision 1.404.2.10
 diff -c -p -d -u -r1.404.2.10 i386.md
 --- gcc/config/i386/i386.md	12 Mar 2003 09:35:27 -0000	1.404.2.10
 +++ gcc/config/i386/i386.md	13 Mar 2003 00:41:08 -0000
 @@ -13671,7 +13671,7 @@
  
  (define_expand "ffssi2"
    [(set (match_operand:SI 0 "nonimmediate_operand" "") 
 -	(ffs:SI (match_operand:SI 1 "general_operand" "")))]
 +	(ffs:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
    ""
  {
    rtx out = gen_reg_rtx (SImode), tmp = gen_reg_rtx (SImode);
Comment 6 Volker Reichelt 2003-04-18 15:36:52 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed in gcc 3.2 branch, 3.3 branch and mainline.
Comment 7 falk.hueffner 2003-04-18 18:23:15 UTC
From: Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
To: reichelt@igpm.rwth-aachen.de
Cc: christianbiere@gmx.de, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
   nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/8178: __builtin_ffs broken
Date: 18 Apr 2003 18:23:15 +0200

 reichelt@igpm.rwth-aachen.de writes:
 
 > Synopsis: __builtin_ffs broken
 > 
 > State-Changed-From-To: analyzed->closed
 > State-Changed-By: reichelt
 > State-Changed-When: Fri Apr 18 15:36:52 2003
 > State-Changed-Why:
 >     Fixed in gcc 3.2 branch, 3.3 branch and mainline.
 
 It still doesn't work for me on mainline with -march=k6:
 
 % cat ffs.c
 int f(int x) { return __builtin_ffs(x); }
 
 % /tmp/bla/bin/gcc -v 
 Reading specs from /usr/tmp/bla/bin/../lib/gcc-lib/i586-pc-linux-gnu/3.4/specs
 Configured with: ./configure --enable-languages=c --disable-nls
 Thread model: posix
 gcc version 3.4 20030415 (experimental)
 % /tmp/bla/bin/gcc -c ffs.c 
 % /tmp/bla/bin/gcc -c -march=k6 ffs.c
 ffs.c: In function `f':
 ffs.c:1: error: unrecognizable insn:
 (insn 26 22 27 0 0x401705d8 (parallel [
             (set (reg:SI 1 edx)
                 (const_int 0 [0x0]))
             (clobber (reg:CC 17 flags))
         ]) -1 (nil)
     (nil))
 ffs.c:1: internal compiler error: in extract_insn, at recog.c:2188
 Please submit a full bug report,
 with preprocessed source if appropriate.
 See <URL:http://gcc.gnu.org/bugs.html> for instructions.
 
 -- 
 	Falk
Comment 8 Volker Reichelt 2003-04-28 14:48:43 UTC
State-Changed-From-To: closed->analyzed
State-Changed-Why: As Falk pointed out, __builtin_ffs broken is still broken
    on mainline with -march=k6. The tests ffs-1.c, ffs-2.c
    from the testsuite Eric mentioned also still fail on mainline.
    
    Since this all works on the 3.3 branch, we have a regression.
Comment 9 Dara Hazeghi 2003-06-21 01:13:43 UTC
Confirmed with mainline (20030620). Does not fail with 3.3 branch.
Comment 10 Andrew Pinski 2003-07-07 11:28:39 UTC
Still happens on the mainline (20030706).
Comment 11 Volker Reichelt 2003-08-28 15:34:00 UTC
The testcase

-----------------------------------------
int main() { return __builtin_ffs(4); }
-----------------------------------------

now works on mainline even with -march=k6.
This is probably due to Rogers patch

http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00818.html

Alas, the following code snippet still fails with -march=k6:

-----------------------------------------
int i=4;
int main() { return __builtin_ffs(i); }
-----------------------------------------

The tests ffs-1.c and ffs-2.c from the testsuite also still fail.

Phil's regression tester says:
Search converges between 2003-02-04-trunk (#213) and 2003-02-05-trunk (#214).
Comment 12 Volker Reichelt 2003-08-28 18:01:05 UTC
Richard, could you please have a look, since your patch

http://gcc.gnu.org/ml/gcc-cvs/2003-02/msg00241.html

caused the regression?

Thanks,
Volker
Comment 13 Eric Botcazou 2003-10-16 17:07:41 UTC
Fixing.
Comment 14 CVS Commits 2003-10-18 07:25:06 UTC
Subject: Bug 8178

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2003-10-18 07:25:02

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

Log message:
	PR optimization/8178
	* config/i386/i386.md (*movsi_zero): New insn to set
	a register to zero on TARGET_USE_MOV0 targets.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1459&r2=2.1460
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.md.diff?cvsroot=gcc&r1=1.484&r2=1.485

Comment 15 Eric Botcazou 2003-10-18 07:27:19 UTC
See http://gcc.gnu.org/ml/gcc-patches/2003-10/msg01497.html
Comment 16 CVS Commits 2003-10-19 17:53:19 UTC
Subject: Bug 8178

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2003-10-19 17:53:12

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

Log message:
	PR optimization/8178
	* config/i386/i386.md (*movsi_zero): Delete.
	(*ffs_no_cmove): Use ix86_expand_clear to zero the third operand.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1477&r2=2.1478
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.md.diff?cvsroot=gcc&r1=1.485&r2=1.486