Bug 8896 - '-mcpu=xscale -fno-strict-aliasing -O2' generates wrong code
|
Bug#:
8896
|
Product: gcc
|
Version: 3.2.1
|
|
Host: i386-redhat-linux
|
Target: arm-linux
|
Build: i386-redhat-linux
|
|
Status: RESOLVED
|
Severity: normal
|
Priority: P3
|
|
Resolution: FIXED
|
Assigned To: rearnsha@gcc.gnu.org
|
Reported By: enrico.scholz@informatik.tu-chemnitz.de
|
|
Component: rtl-optimization
|
Target Milestone: 3.4.0
|
|
Summary: '-mcpu=xscale -fno-strict-aliasing -O2' generates wrong code
|
|
Keywords: wrong-code
|
|
Opened: 2002-12-10 15:46
|
The arm-linux-gcc miscompiles XScale linux-kernels (the attached testcase is
derived from fs/binfmt_elf.c of linux-2.5.49 + various ARM patches).
Because of other environment-problems, I do not have a complete test-program,
but the miscompilation is visible in the disassembled .o-file. The interesting
code is:
---- objdump -d binfmt_elf.o
70: e3a04002 mov r4, #2 ; 0x2
7c: e0844004 add r4, r4, r4
84: e1a0e004 mov lr, r4
e0: e50be0b0 str lr, [fp, -#176]
These statements are the result of:
| 60 elf_info[ei_index++] = 3; ...
which is wrong. Other ELF-tags are incorrect too, but this is the most obvious
one.
Release:
gcc-3.2.1
Environment:
Reading specs from /usr/lib/gcc-lib/arm-linux/3.2.1/specs
Configured with: ../configure --host=i386-redhat-linux --target=arm-linux
--prefix=/usr --mandir=/usr/share/man --disable-checking
--with-cpu=strongarm1100 --enable-languages=c
Thread model: posix
gcc version 3.2.1
How-To-Repeat:
Compile the testprogram with
| arm-linux-gcc -O2 -fno-strict-aliasing -mcpu=xscale -c binfmt_elf.c
Watch the output with 'objdump -d binfmt_elf.o'
Fix:
The following change should fix the problem, but I'd be grateful if you
could test it for me, since I cannot execute your testcase.
--- reload1.c.orig Thu Oct 10 16:40:20 2002
+++ reload1.c Thu Dec 12 14:43:56 2002
@@ -8674,7 +8674,9 @@
... (MEM (PLUS (REGZ) (REGY)))... .
First, check that we have (set (REGX) (PLUS (REGX) (REGY)))
- and that we know all uses of REGX before it dies. */
+ and that we know all uses of REGX before it dies.
+ Also, explicitly check that REGX != REGY; our life information
+ does not yet show whether REGY changes in this insn. */
set = single_set (insn);
if (set != NULL_RTX
&& GET_CODE (SET_DEST (set)) == REG
@@ -8684,6 +8686,7 @@
&& GET_CODE (SET_SRC (set)) == PLUS
&& GET_CODE (XEXP (SET_SRC (set), 1)) == REG
&& rtx_equal_p (XEXP (SET_SRC (set), 0), SET_DEST (set))
+ && !rtx_equal_p (XEXP (SET_SRC (set), 1), SET_DEST (set))
&& last_label_ruid < reg_state[REGNO (SET_DEST (set))].use_ruid)
{
rtx reg = SET_DEST (set);
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. The same bug does not occur with the latest compiler, but I think that's because an earlier pass of the compiler has optimized the problem away before it trips the bug.
Initial investigation suggests this is a problem with reload_combine().
Responsible-Changed-From-To: unassigned->rearnsha
Responsible-Changed-Why: .
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed according to reporter. Richard Earnshaw posted a patch for this months ago -- apparently without mentioning the PR in the ChangeLog.
State-Changed-From-To: closed->analyzed
State-Changed-Why: The patch was never commited.
From: David Mentre <Mentre@tcl.ite.mee.com>
To: "'gcc-gnats@gcc.gnu.org'" <gcc-gnats@gcc.gnu.org>,
"'enrico.scholz@informatik.tu-chemnitz.de'"
<enrico.scholz@informatik.tu-chemnitz.de>,
"'gcc-bugs@gcc.gnu.org'"
<gcc-bugs@gcc.gnu.org>,
"'gcc-prs@gcc.gnu.org'" <gcc-prs@gcc.gnu.org>,
"'rearnsha@gcc.gnu.org'" <rearnsha@gcc.gnu.org>
Cc:
Subject: Re: optimization/8896: '-mcpu=xscale -fno-strict-aliasing -O2' ge
nerates wrong code
Date: Tue, 6 May 2003 15:03:23 +0200
Hello,
The patch describe in the below gnats entry has never been applied to
official gcc tree. However, this patch is systematically applied to =
each gcc
generated for arm-* target.=20
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=3Dview%20audit-trail&database=
=3Dgcc&p
r=3D8896
Is this patch really needed? If true, why isn't it applied to official =
gcc
tree? If not, then people using this patch should know that this patch =
is
not needed.
Best regards,
david
--=20
David Mentr=E9 <mentre@tcl.ite.mee.com> - Research engineer
Mitsubishi Electric ITE-TCL / European Telecommunication Research =
Laboratory
Phone: +33 2 23 45 58 29 / Fax: +33 2 23 45 58 59=20
http://www.mitsubishi-electric-itce.fr
From: Daniel Jacobowitz <drow@mvista.com>
To: Richard Earnshaw <rearnsha@arm.com>
Cc: gcc-gnats@gcc.gnu.org, enrico.scholz@informatik.tu-chemnitz.de,
gcc-bugs@gcc.gnu.org
Subject: Re: optimization/8896: '-mcpu=xscale -fno-strict-aliasing -O2' generates wrong code
Date: Thu, 15 May 2003 14:36:28 -0400
On Thu, Dec 12, 2002 at 03:14:52PM +0000, Richard Earnshaw wrote:
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8896
>
> I've attached what I believe to be the fix to the above PR. It would be
> helpful if you could give it a whirl.
I've added an updated testcase (produced after much labor by Russell
King) which shows the problem in 3.2.3. The testcase is extremely
delicate. It doesn't show the problem in 3.3 or HEAD, but I wouldn't
be at all surprised if the problem was still there. Making a
testcase to show it is beyond me though.
For the curious, here's a diff of the first differing dump with and
without Richard's patch, using the 3.2 CVS branch. It fails using
only "-march=armv4 -O2".
--- 32.s.22.postreload 2003-05-15 14:29:58.000000000 -0400
+++ 32p.s.22.postreload 2003-05-15 14:29:59.000000000 -0400
@@ -155,18 +155,25 @@
(note 79 843 95 NOTE_INSN_DELETED)
(insn 95 79 107 (set (reg/v:SI 11 fp [47])
- (const_int 2 [0x2])) 175 {*arm_movsi_insn} (insn_list:REG_DEP_ANTI 79 (nil))
- (nil))
+ (const_int 1 [0x1])) 175 {*arm_movsi_insn} (insn_list:REG_DEP_ANTI 79 (nil))
+ (expr_list:REG_EQUAL (const_int 1 [0x1])
+ (nil)))
+
+(note 107 95 117 NOTE_INSN_DELETED)
-(note 107 95 129 NOTE_INSN_DELETED)
+(insn 117 107 129 (set (reg/v:SI 11 fp [47])
+ (plus:SI (reg/v:SI 11 fp [47])
+ (reg/f:SI 11 fp))) 4 {*arm_addsi3} (insn_list:REG_DEP_ANTI 107 (insn_list 95 (nil)))
+ (expr_list:REG_EQUAL (const_int 2 [0x2])
+ (nil)))
-(note 129 107 135 NOTE_INSN_DELETED)
+(note 129 117 135 NOTE_INSN_DELETED)
(note 135 129 137 NOTE_INSN_DELETED)
(insn 137 135 141 (set (reg/v:SI 11 fp [47])
(plus:SI (reg/v:SI 11 fp [47])
- (reg/f:SI 11 fp))) 4 {*arm_addsi3} (insn_list:REG_DEP_ANTI 129 (insn_list 117 (nil)))
+ (const_int 1 [0x1]))) 4 {*arm_addsi3} (insn_list:REG_DEP_ANTI 129 (insn_list 117 (nil)))
(expr_list:REG_EQUAL (const_int 3 [0x3])
(nil)))
@@ -177,7 +184,7 @@
(insn 197 141 221 (set (reg/v:SI 11 fp [47])
(plus:SI (reg/v:SI 11 fp [47])
- (const_int 2 [0x2]))) 4 {*arm_addsi3} (insn_list:REG_DEP_ANTI 141 (insn_list:REG_DEP_OUTPUT 137 (insn_list 135 (nil))))
+ (const_int 3 [0x3]))) 4 {*arm_addsi3} (insn_list:REG_DEP_ANTI 141 (insn_list:REG_DEP_OUTPUT 137 (insn_list 135 (nil))))
(expr_list:REG_EQUAL (const_int 6 [0x6])
(nil)))
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
Patch applied to trunk. The 3.2 branch is dead, and this problem hasn't been
reproduced on the 3.3 branch.