Bug 40710 - [4.3 Regression] Linux kernel miscompiled for sh4-linux
Summary: [4.3 Regression] Linux kernel miscompiled for sh4-linux
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.3.4
: P4 major
Target Milestone: 4.3.4
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc/2009-07/msg...
Keywords: wrong-code
Depends on:
Blocks: 40105
  Show dependency treegraph
 
Reported: 2009-07-10 09:55 UTC by sugioka
Modified: 2009-07-18 11:31 UTC (History)
5 users (show)

See Also:
Host:
Target: sh-unknown-linux-gnu
Build:
Known to work: 4.3.3 4.3.4
Known to fail: 4.3.4
Last reconfirmed: 2009-07-11 13:14:17


Attachments
preprocessed source (93.26 KB, text/plain)
2009-07-10 09:57 UTC, sugioka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sugioka 2009-07-10 09:55:26 UTC
gcc-4.3.4 miscompiles kernel-2.6.30 for sh4-linux.
Reproduce: sh-linux-gcc -O2 -m4a-nofpu -ml -fomit-frame-pointer -S balloc.i
attached code is compiled as follows.

ext3_get_group_desc:
	mov.w	.L10,r1
	sts.l	pr,@-r15
	add	r4,r1
	mov.l	@(28,r1),r2
	mov.l	@(36,r2),r3
	cmp/hi	r5,r3
	bf/s	.L8                 !!!
	add	#-4,r15             !!!
	mov.l	@(28,r1),r1
	mov.l	@(56,r2),r3
	mov	r1,r2
	add	#64,r2
	mov.l	@(32,r1),r7
	mov.l	@(20,r2),r1
	mov	r5,r2
	add	#-1,r7
	neg	r1,r1
	shld	r1,r2
	mov	r2,r0
	shll2	r0
	mov.l	@(r0,r3),r1
	tst	r1,r1
	bt/s	.L9
	and	r5,r7
	tst	r6,r6
	bt/s	.L5
	mov.l	@(20,r1),r2
	mov.l	r1,@r6
.L5:
	mov	#5,r1
	mov	r7,r0
	shld	r1,r0
	add	r2,r0
.L3:
	lds.l	@r15+,pr
	rts	
	nop
	.align 5
.L8:
	mov.l	.L14,r1
	mov	r5,r7
	mov.l	.L15,r5
	mov.l	.L13,r6
	jsr	@r1
	mov.l	r3,@r15
	mov	#0,r0
	bra	.L3
	add	#4,r15
	.align 5
.L9:
	mov.l	.L14,r1
	add	#-8,r15
	mov.l	r7,@(4,r15)
	mov	r5,r7
	mov.l	.L15,r5
	mov.l	.L16,r6
	jsr	@r1
	mov.l	r2,@r15
	mov	#0,r0
	bra	.L3
	add	#8,r15

I found that reverting patch for pr40105 http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147781 fixes this.
The difference between this code and working code which is generated by r147781-reverted gcc follows.
--- balloc.s	2009-07-10 17:00:27.000000000 +0900
+++ balloc.s.revert-pr40105	2009-07-10 17:00:20.000000000 +0900
@@ -23,8 +23,7 @@
 	mov.l	@(28,r1),r2
 	mov.l	@(36,r2),r3
 	cmp/hi	r5,r3
-	bf/s	.L8
-	add	#-4,r15
+	bf	.L8
 	mov.l	@(28,r1),r1
 	mov.l	@(56,r2),r3
 	mov	r1,r2
@@ -57,6 +56,7 @@
 	.align 5
 .L8:
 	mov.l	.L14,r1
+	add	#-4,r15
 	mov	r5,r7
 	mov.l	.L15,r5
 	mov.l	.L13,r6
Comment 1 sugioka 2009-07-10 09:57:59 UTC
Created attachment 18171 [details]
preprocessed source

preprocessed source
Comment 2 Kazumoto Kojima 2009-07-11 13:14:16 UTC
I've tried to see what is going on.   fill_slots_from_thread
fills wrongly the delay slot of a conditional jmp insn with
"add #-4,r15" where r15 is the stack pointer register for SH.
fill_slots_from_thread computes the resource set for
the follow-through block with

mark_target_live_regs (get_insns (), opposite_thread, &opposite_needed);

and mark_target_live_regs uses df_get_live_in to get live regs
for the basic block including the opposite_thread insn which is

the first insn of the follow-through block:

(insn 32 46 35 fs/ext3/balloc.c:66 (parallel [
            (asm_operands/v ("") ("") 0 []
                 [] 2935777)
            (clobber (mem:BLK (scratch) [0 A8]))
        ]) -1 (nil))

The resulting opssite_needed is

$1 = {memory = 0x1, unch_memory = 0x0, volatil = 0x0, cc = 0x0,
      regs = {0xf6,  0x0, 0x0, 0x0, 0x40000}}

i.e. it seems that df_get_live_in doesn't count r15 as an live
register and fill_slots_from_thread picks "add #-4,r15" up as
an eligible insn to fill that delayed slot.
Comment 3 Richard Biener 2009-07-14 12:32:53 UTC
If 4.3.3 worked please add that release in the known-to-work field.
Comment 4 Kazumoto Kojima 2009-07-15 21:32:58 UTC
Subject: Bug 40710

Author: kkojima
Date: Wed Jul 15 21:32:46 2009
New Revision: 149696

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149696
Log:
	PR rtl-optimization/40710
	* resource.c (mark_target_live_regs): Reset DF problem to LR.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/resource.c

Comment 5 Kazumoto Kojima 2009-07-18 06:47:39 UTC
Subject: Bug 40710

Author: kkojima
Date: Sat Jul 18 06:47:22 2009
New Revision: 149764

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149764
Log:
	PR rtl-optimization/40710
	* resource.c (mark_target_live_regs): Reset DF problem to LR.


Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/resource.c

Comment 6 Richard Biener 2009-07-18 11:31:33 UTC
Fixed.
Comment 7 Kazumoto Kojima 2009-07-22 23:22:44 UTC
Subject: Bug 40710

Author: kkojima
Date: Wed Jul 22 23:22:24 2009
New Revision: 149965

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149965
Log:
	Backport from mainline:
	2009-07-15  Eric Botcazou  <ebotcazou@adacore.com>

	PR rtl-optimization/40710
	* resource.c (mark_target_live_regs): Reset DF problem to LR.


Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/resource.c