Bug 15886 - [3.3/3.4/4.0 Regression] SH: Miscompilation with -O2 -fPIC
Summary: [3.3/3.4/4.0 Regression] SH: Miscompilation with -O2 -fPIC
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.1
: P2 normal
Target Milestone: 3.4.3
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Reported: 2004-06-09 03:24 UTC by sugioka
Modified: 2004-09-13 14:15 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: sh-unknown-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.2.3 3.4.3
Known to fail: 3.4.0
Last reconfirmed: 2004-06-11 05:58:22

testcase (44.27 KB, application/x-gzip-compressed)
2004-06-09 03:26 UTC, sugioka

Note You need to log in before you can comment on or make changes to this bug.
Description sugioka 2004-06-09 03:24:38 UTC
Gcc-3.4.1 generates wrong code when compiling attached code with '-O2 -fPIC'.
Adding -fno-regmove fixes this.

  $ sh-linux-gcc -O2 -fPIC -S dl-open.i

Miscompiled source code:
  args.caller_dl_open = __builtin_extract_return_addr (__builtin_return_address 

Generated wrong code:
  mov    r4,r11
  sts    pr,r0
  mov.l  r11,@(12,r14)       --- original pr should be stored to @(12,r14)

Correct code (-O2 -fPIC -fno-regmove):
  sts    pr,r10
  mov.l  r10,@(12,r14)
Comment 1 sugioka 2004-06-09 03:26:38 UTC
Created attachment 6496 [details]
Comment 2 Kazumoto Kojima 2004-06-11 02:12:26 UTC
FYI, I could find a reduced testcase and analyze it. See
Comment 3 Andrew Pinski 2004-06-11 05:58:21 UTC
Kazumoto Kojima confirmed and analyzed it already.
Comment 4 Giovanni Bajo 2004-06-11 13:07:36 UTC
KK, is this a regression? In your message you say that mainline and 3.4 exhibit 
the bug, but can you test it also on an older version?
Comment 5 Kazumoto Kojima 2004-06-11 14:11:38 UTC
Yep.  I've confirmed that 3.3.4 has the same problem and 3.2.3 doesn't.
So this is a regression from 3.2.
Comment 6 CVS Commits 2004-06-11 18:15:40 UTC
Subject: Bug 15886

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amylaar@gcc.gnu.org	2004-06-11 18:15:38

Modified files:
	gcc            : ChangeLog 

Log message:
	Add PR number in:
	PR 15886:
	* sh.h (ALLOCATE_INITIAL_VALUE): Use return_address_pointer_rtx.


Comment 7 Mark Mitchell 2004-08-23 20:58:46 UTC
Postponed until GCC 3.4.3.
Comment 8 CVS Commits 2004-09-09 02:18:24 UTC
Subject: Bug 15886

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	kkojima@gcc.gnu.org	2004-09-09 02:18:15

Modified files:
	gcc            : ChangeLog 
	gcc/config/sh  : sh.h 

Log message:
	PR 15886
	Backport from mainline:
	2004-06-11  J"orn Rennecke <joern.rennecke@superh.com>
	* sh.h (ALLOCATE_INITIAL_VALUE): Use return_address_pointer_rtx.


Comment 9 Andrew Pinski 2004-09-09 02:33:41 UTC
Fixed in 3.4.3.