NetBSD Problem Report #46677
From www@NetBSD.org Mon Jul 9 15:41:47 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
by www.NetBSD.org (Postfix) with ESMTP id BA55163B8E6
for <gnats-bugs@gnats.NetBSD.org>; Mon, 9 Jul 2012 15:41:46 +0000 (UTC)
Message-Id: <20120709154146.220EC63B882@www.NetBSD.org>
Date: Mon, 9 Jul 2012 15:41:46 +0000 (UTC)
From: ragge@ludd.ltu.se
Reply-To: ragge@ludd.ltu.se
To: gnats-bugs@NetBSD.org
Subject: gcc bug with builtin ffs on vax.
X-Send-Pr-Version: www-1.0
>Number: 46677
>Category: port-vax
>Synopsis: gcc bug with builtin ffs on vax.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-vax-maintainer
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jul 09 15:45:00 +0000 2012
>Closed-Date: Wed Jul 11 13:41:36 +0000 2012
>Last-Modified: Thu Jul 12 18:30:09 +0000 2012
>Originator: Anders Magnusson
>Release: 6.0 beta2
>Organization:
>Environment:
NetBSD vs4090.tethuvudet.se 6.0_BETA2 NetBSD 6.0_BETA2 (GENERIC) #10: Mon Jul 9 17:02:03 CEST 2012 ragge@bakfull:/local/home/ragge/vaxsrc/60beta/sys/arch/vax/compile/obj/GENERIC vax
>Description:
The builtin ffs function fails in some situations for gcc both 4.1 or 4.5, and both native and cross-compiled.
>How-To-Repeat:
The code example below shows that the second ffs gets optimized away.
vs4090:/home/ragge >cat x.c
struct foo { long __bits[4]; };
int
firstsig(struct foo *ss)
{
int sig;
sig = ffs(ss->__bits[0]);
if (sig != 0)
return (sig);
sig = ffs(ss->__bits[1]);
if (sig != 0)
return (sig + 32);
return (0);
}
vs4090:/home/ragge >gcc -S -O2 x.c
vs4090:/home/ragge >cat x.s
#NO_APP
.file "x.c"
.text
.align 1
.globl firstsig
.type firstsig, @function
firstsig:
.word 0x0
subl2 $4,%sp
ffs $0,$32,*4(%ap),%r0
jneq .L2
mnegl $1,%r0
.L2:
incl %r0
ret
.size firstsig, .-firstsig
.ident "GCC: (GNU) 4.1.3 20080704 prerelease (NetBSD nb3 20111107)"
>Fix:
>Release-Note:
>Audit-Trail:
From: <Paul_Koning@Dell.com>
To: <gnats-bugs@NetBSD.org>
Cc: <port-vax-maintainer@netbsd.org>, <gnats-admin@netbsd.org>,
<netbsd-bugs@netbsd.org>
Subject: Re: port-vax/46677: gcc bug with builtin ffs on vax.
Date: Tue, 10 Jul 2012 21:30:05 +0000
This seems to help.
Index: gnu/dist/gcc4/gcc/config/vax/builtins.md
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- gnu/dist/gcc4/gcc/config/vax/builtins.md (revision 254596)
+++ gnu/dist/gcc4/gcc/config/vax/builtins.md (working copy)
@@ -25,7 +25,7 @@
"
{
rtx label =3D gen_label_rtx ();
- emit_insn (gen_ffssi2_internal (operands[0], operands[1], operands[0]));
+ emit_insn (gen_ffssi2_internal (operands[0], operands[1], operands[1]));
emit_jump_insn (gen_bne (label));
emit_insn (gen_negsi2 (operands[0], const1_rtx));
emit_label (label);
@@ -36,6 +36,6 @@
(define_insn "ffssi2_internal"
[(set (match_operand:SI 0 "nonimmediate_operand" "=3Dg")
(ffs:SI (match_operand:SI 1 "general_operand" "nrQ")))
- (set (cc0) (match_operand:SI 2 "nonimmediate_operand" "0"))]
+ (set (cc0) (ffs:SI (match_operand:SI 2 "general_operand" "1")))]
""
"ffs $0,$32,%1,%0")
The reason is that, according to the GCC internals documentation, "parallel=
" means the operations are done in parallel, i.e., first all the inputs are=
computed and then all the outputs are set. So the original code (which se=
ts cc0 based on the output operand of the FFS) would set cc0 based on the p=
revious value, NOT based on the result of the ffs. The changed code says t=
hat the condition code is set based on the ffs answer.
It looks like it works correctly, judging by the generated assembly code.
paul
From: "Anders Magnusson" <ragge@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/46677 CVS commit: src/gnu/dist/gcc4/gcc/config/vax
Date: Wed, 11 Jul 2012 13:34:45 +0000
Module Name: src
Committed By: ragge
Date: Wed Jul 11 13:34:45 UTC 2012
Modified Files:
src/gnu/dist/gcc4/gcc/config/vax: builtins.md
Log Message:
Bugfix builtin ffs, fixes PR port-vax/46677, fix from Paul Koning.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/gnu/dist/gcc4/gcc/config/vax/builtins.md
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: ragge@NetBSD.org
State-Changed-When: Wed, 11 Jul 2012 13:41:36 +0000
State-Changed-Why:
Recompiled system, tested and the bug had gone. Great, thanks!
From: "Jeff Rizzo" <riz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/46677 CVS commit: [netbsd-6] src/gnu/dist/gcc4/gcc/config/vax
Date: Thu, 12 Jul 2012 18:29:57 +0000
Module Name: src
Committed By: riz
Date: Thu Jul 12 18:29:57 UTC 2012
Modified Files:
src/gnu/dist/gcc4/gcc/config/vax [netbsd-6]: builtins.md
Log Message:
Pull up following revision(s) (requested by ragge in ticket #411):
gnu/dist/gcc4/gcc/config/vax/builtins.md: revision 1.3
Bugfix builtin ffs, fixes PR port-vax/46677, fix from Paul Koning.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.40.1 src/gnu/dist/gcc4/gcc/config/vax/builtins.md
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.