Bug 36780 - [4.3/4.4 Regression] Wrong reload generated for subreg address on SH
Summary: [4.3/4.4 Regression] Wrong reload generated for subreg address on SH
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.0
: P4 major
Target Milestone: 4.3.2
Assignee: Not yet assigned to anyone
URL:
Keywords: build, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2008-07-10 01:20 UTC by Kazumoto Kojima
Modified: 2008-07-19 22:05 UTC (History)
3 users (show)

See Also:
Host:
Target: sh-*-*
Build:
Known to work: 4.3.1
Known to fail: 4.3.2 4.4.0
Last reconfirmed:


Attachments
A reduced test case for -O0 (2.06 KB, text/plain)
2008-07-10 01:27 UTC, Kazumoto Kojima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kazumoto Kojima 2008-07-10 01:20:14 UTC
For trunk and 4.3-branch, bootstrapping on SH fails during building
libstdc++-v3

/exp/ldroot/dodes/xsh-gcc-orig/sh4-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.tcc:559: error: insn does not satisfy its constraints:
(insn 2055 2054 716 106 /exp/ldroot/dodes/xsh-gcc-orig/sh4-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.tcc:473 (set (reg:SI 2 r2)
        (plus:SI (reg:SI 3 r3)
            (const_int 40 [0x28]))) 35 {*addsi3_compact} (nil))
/exp/ldroot/dodes/xsh-gcc-orig/sh4-unknown-linux-gnu/libstdc++-v3/include/bits/locale_facets.tcc:559: internal compiler error: in reload_cse_simplify_operands, at postreload.c:395

It starts to fail after the patch

r137639 | jsm28 | 2008-07-09 05:23:56 +0900 (Wed, 09 Jul 2008) | 3 lines

        * reload.c (find_reloads_subreg_address): Do not require validity
        of address in original mode before reloading address.

is applied.
Comment 1 Kazumoto Kojima 2008-07-10 01:27:23 UTC
Created attachment 15882 [details]
A reduced test case for -O0

Before r137639, the insn in problem was

(insn 200 330 331 20 yyy.cc:181 (set (mem/c:SI (plus:SI (reg:SI 6 r6)
                (const_int 0 [0x0])) [0 D.2244+4 S8 A32])
        (reg:SI 1 r1 [261])) 175 {movsi_ie} (nil))

and now the memory address is reloaded like as

(insn 331 330 200 20 xxx.cc:181 (set (reg:SI 2 r2)
        (plus:SI (reg:SI 6 r6)
            (const_int 0 [0x0]))) 35 {*addsi3_compact} (nil))

(insn 200 331 332 20 xxx.cc:181 (set (mem/c:SI (reg:SI 2 r2) [0 D.2244+4 S8 A32])
        (reg:SI 1 r1 [261])) 175 {movsi_ie} (nil))

but SH has no add instruction whose destination and source differs.
Comment 2 Kazumoto Kojima 2008-07-10 23:25:47 UTC
First I've modified addsi3 pattern and added a splitter

(define_split
  [(set (match_operand:SI 0 "arith_reg_dest" "")
       (plus:SI (match_operand:SI 1 "arith_operand" "")
                (match_operand:SI 2 "arith_operand" "")))]
  "TARGET_SH1 && reload_completed && !rtx_equal_p (operands[0], operands[1])"
  [(set (match_dup 0) (match_dup 2))
   (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))]
  "")

This fixes the build failure but there are many regressions
at -O0.  It seems that the reload in problem makes very complex
reloads on this backend and some another latent problems are
revealed.  I've tried to see what is going on for these cases
for a while and then given up.
When looking into these complex reloads, I've noticed that
the address having the type (plus (plus reg const_int) const_int)
is cared about specially in LEGITIMIZE_RELOAD_ADDRESS in this
backend.  I've tried to add the corresponding code in
GO_IF_LEGITIMATE_ADDRESS so that strict_memory_address_p can
recognize the above address expression when reloading.
It fixes the build failure and there are no major regressions
with it.  Although this is clearly a workaround and the issue
should be looking more deeply, I guess this will be ok at this
point, especially for the 4.3-branch which will schedule
the 4.3.2 release in a month.
Now I'm testing the patch below for 4.3/4.4 in native environments:

--- ORIG/trunk/gcc/config/sh/sh.h	2008-07-06 09:31:18.000000000 +0900
+++ LOCAL/trunk/gcc/config/sh/sh.h	2008-07-10 13:58:40.000000000 +0900
@@ -2501,6 +2501,18 @@ struct sh_args {
 	    goto LABEL;							\
 	}								\
     }									\
+  /* When reload in progress, find_reloads_subreg_address tries to	\
+     make a new reload for some types of address.  Unfortunately it	\
+     generates wrong code on SH.  See PR36780.  The following is to	\
+     avoid this issue.  */						\
+  if (!TARGET_SHMEDIA && reload_in_progress				\
+      && GET_CODE (X) == PLUS						\
+      && (GET_MODE_SIZE (MODE) == 4 || GET_MODE_SIZE (MODE) == 8)	\
+      && GET_CODE (XEXP ((X), 0)) == PLUS				\
+      && GET_CODE (XEXP (XEXP ((X), 0), 1)) == CONST_INT		\
+      && BASE_REGISTER_RTX_P (XEXP (XEXP ((X), 0), 0))			\
+      && GET_CODE (XEXP ((X), 1)) == CONST_INT)				\
+    goto LABEL;								\
 }
 
 /* Try machine-dependent ways of modifying an illegitimate address

Comment 3 Kazumoto Kojima 2008-07-15 13:07:17 UTC
Subject: Bug 36780

Author: kkojima
Date: Tue Jul 15 13:06:32 2008
New Revision: 137838

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137838
Log:
	PR target/36780
	* config/sh/sh.h (GO_IF_LEGITIMATE_ADDRESS): Allow
	(plus (plus (reg) (const_int)) (const_int)) when reload_in_progress.


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

Comment 4 Kazumoto Kojima 2008-07-15 13:18:24 UTC
Subject: Bug 36780

Author: kkojima
Date: Tue Jul 15 13:17:39 2008
New Revision: 137839

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137839
Log:
	Backport from mainline:
	PR target/36780
	* config/sh/sh.h (GO_IF_LEGITIMATE_ADDRESS): Allow
	(plus (plus (reg) (const_int)) (const_int)) when reload_in_progress.


Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/config/sh/sh.h

Comment 5 Joseph S. Myers 2008-07-19 11:15:03 UTC
Subject: Bug 36780

Author: jsm28
Date: Sat Jul 19 11:14:13 2008
New Revision: 137976

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137976
Log:
	PR target/36780
	PR target/36827
	* reload.c (find_reloads_subreg_address): Only reload address if
	reloaded == 0, not for reloaded != 1.

	Revert:
	2008-07-16  Joseph Myers  <joseph@codesourcery.com>
	* config/m32c/m32c.c (BIG_FB_ADJ): Move definition earlier.
	(m32c_legitimate_address_p): Handle "++rii" addresses created by
	m32c_legitimize_reload_address.

	2008-07-15  Kaz Kojima  <kkojima@gcc.gnu.org>
	* config/sh/sh.h (GO_IF_LEGITIMATE_ADDRESS): Allow
	(plus (plus (reg) (const_int)) (const_int)) when reload_in_progress.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/m32c/m32c.c
    trunk/gcc/config/sh/sh.h
    trunk/gcc/reload.c

Comment 6 Joseph S. Myers 2008-07-19 11:16:16 UTC
Subject: Bug 36780

Author: jsm28
Date: Sat Jul 19 11:15:29 2008
New Revision: 137977

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137977
Log:
	PR target/36780
	PR target/36827
	* reload.c (find_reloads_subreg_address): Only reload address if
	reloaded == 0, not for reloaded != 1.

	Revert:
	2008-07-16  Joseph Myers  <joseph@codesourcery.com>
	* config/m32c/m32c.c (BIG_FB_ADJ): Move definition earlier.
	(m32c_legitimate_address_p): Handle "++rii" addresses created by
	m32c_legitimize_reload_address.

	2008-07-15  Kaz Kojima  <kkojima@gcc.gnu.org>
	* config/sh/sh.h (GO_IF_LEGITIMATE_ADDRESS): Allow
	(plus (plus (reg) (const_int)) (const_int)) when reload_in_progress.

Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/config/m32c/m32c.c
    branches/gcc-4_3-branch/gcc/config/sh/sh.h
    branches/gcc-4_3-branch/gcc/reload.c

Comment 7 Kazumoto Kojima 2008-07-19 22:05:49 UTC
Thanks for your patch, Joseph!  Fixed.