Index: gcc/config/mcore/mcore.c
===================================================================
--- gcc/config/mcore/mcore.c	(revision 227044)
+++ gcc/config/mcore/mcore.c	(working copy)
@@ -156,6 +156,8 @@
  static bool       mcore_warn_func_return        (tree);
  static void       mcore_option_override		(void);
  static bool       mcore_legitimate_constant_p   (machine_mode, rtx);
+static bool	  mcore_legitimate_address_p	(machine_mode, rtx, bool,
+						 addr_space_t);
  
  /* MCore specific attributes.  */

@@ -243,6 +245,8 @@

  #undef TARGET_LEGITIMATE_CONSTANT_P
  #define TARGET_LEGITIMATE_CONSTANT_P mcore_legitimate_constant_p
+#undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
+#define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P mcore_legitimate_address_p

  #undef TARGET_WARN_FUNC_RETURN
  #define TARGET_WARN_FUNC_RETURN mcore_warn_func_return
@@ -3196,3 +3200,74 @@
  {
    return GET_CODE (x) != CONST_DOUBLE;
  }
+
+/* Helper function for `mcore_legitimate_address_p'.  */
+
+static bool
+mcore_reg_ok_for_base_p (const_rtx reg, bool strict_p)
+{
+  if (strict_p)
+    return REGNO_OK_FOR_BASE_P (REGNO (reg));
+  else
+    return (REGNO (reg) <= 16 || !HARD_REGISTER_P (reg));
+}
+
+static bool
+mcore_base_register_rtx_p (const_rtx x, bool strict_p)
+{
+  return REG_P(x) && mcore_reg_ok_for_base_p (x, strict_p);
+}
+
+/*  A legitimate index for a QI is 0..15, for HI is 0..30, for SI is 0..60,
+    and for DI is 0..56 because we use two SI loads, etc.  */
+
+static bool
+mcore_legitimate_index_p (machine_mode mode, const_rtx op)
+{
+  if (CONST_INT_P (op))
+    {
+      if (GET_MODE_SIZE (mode) >= 4
+	  && (((unsigned HOST_WIDE_INT) INTVAL (op)) % 4) == 0
+	  &&  ((unsigned HOST_WIDE_INT) INTVAL (op))
+	      <= (unsigned HOST_WIDE_INT) 64 - GET_MODE_SIZE (mode))
+	return true;
+      if (GET_MODE_SIZE (mode) == 2
+	  && (((unsigned HOST_WIDE_INT) INTVAL (op)) % 2) == 0
+	  &&  ((unsigned HOST_WIDE_INT) INTVAL (op)) <= 30)
+	return true;
+      if (GET_MODE_SIZE (mode) == 1
+	  && ((unsigned HOST_WIDE_INT) INTVAL (op)) <= 15)
+	return true;
+  }								
+  return false;
+}
+
+
+/* Worker function for TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P.
+
+   Allow  REG
+	  REG + disp  */
+
+static bool
+mcore_legitimate_address_p (machine_mode mode, rtx x, bool strict_p,
+			    addr_space_t as)
+{
+  gcc_assert (ADDR_SPACE_GENERIC_P (as));
+
+  if (mcore_base_register_rtx_p (x, strict_p))
+    return true;
+  else if (GET_CODE (x) == PLUS || GET_CODE (x) == LO_SUM)
+    {
+      rtx xop0 = XEXP (x, 0);
+      rtx xop1 = XEXP (x, 1);
+      if (mcore_base_register_rtx_p (xop0, strict_p)
+	  && mcore_legitimate_index_p (mode, xop1))
+	return true;
+      if (mcore_base_register_rtx_p (xop1, strict_p)
+ 	  && mcore_legitimate_index_p (mode, xop0))
+	return true;
+    }
+
+  return false;
+}
+
Index: gcc/config/mcore/mcore.h
===================================================================
--- gcc/config/mcore/mcore.h	(revision 227044)
+++ gcc/config/mcore/mcore.h	(working copy)
@@ -529,91 +529,6 @@
  /* Recognize any constant value that is a valid address.  */
  #define CONSTANT_ADDRESS_P(X) 	 (GET_CODE (X) == LABEL_REF)

-/* The macros REG_OK_FOR..._P assume that the arg is a REG rtx
-   and check its validity for a certain class.
-   We have two alternate definitions for each of them.
-   The usual definition accepts all pseudo regs; the other rejects
-   them unless they have been allocated suitable hard regs.
-   The symbol REG_OK_STRICT causes the latter definition to be used.  */
-#ifndef REG_OK_STRICT
-
-/* Nonzero if X is a hard reg that can be used as a base reg
-   or if it is a pseudo reg.  */
-#define REG_OK_FOR_BASE_P(X) \
-    	(REGNO (X) <= 16 || REGNO (X) >= FIRST_PSEUDO_REGISTER)
-
-/* Nonzero if X is a hard reg that can be used as an index
-   or if it is a pseudo reg.  */
-#define REG_OK_FOR_INDEX_P(X)	0
-
-#else
-
-/* Nonzero if X is a hard reg that can be used as a base reg.  */
-#define REG_OK_FOR_BASE_P(X)	\
-	REGNO_OK_FOR_BASE_P (REGNO (X))
-
-/* Nonzero if X is a hard reg that can be used as an index.  */
-#define REG_OK_FOR_INDEX_P(X)	0
-
-#endif
-/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
-   that is a valid memory address for an instruction.
-   The MODE argument is the machine mode for the MEM expression
-   that wants to use this address.
-
-   The other macros defined here are used only in GO_IF_LEGITIMATE_ADDRESS.  */
-#define BASE_REGISTER_RTX_P(X)  \
-  (GET_CODE (X) == REG && REG_OK_FOR_BASE_P (X))
-
-#define INDEX_REGISTER_RTX_P(X)  \
-  (GET_CODE (X) == REG && REG_OK_FOR_INDEX_P (X))
-
-
-/* Jump to LABEL if X is a valid address RTX.  This must also take
-   REG_OK_STRICT into account when deciding about valid registers, but it uses
-   the above macros so we are in luck.
-
-   Allow  REG
-	  REG+disp
-
-   A legitimate index for a QI is 0..15, for HI is 0..30, for SI is 0..60,
-   and for DI is 0..56 because we use two SI loads, etc.  */
-#define GO_IF_LEGITIMATE_INDEX(MODE, REGNO, OP, LABEL)			\
-  do									\
-    {									\
-      if (GET_CODE (OP) == CONST_INT) 					\
-        {								\
-	  if (GET_MODE_SIZE (MODE) >= 4					\
-	      && (((unsigned HOST_WIDE_INT) INTVAL (OP)) % 4) == 0	\
-	      &&  ((unsigned HOST_WIDE_INT) INTVAL (OP))		\
-	      <= (unsigned HOST_WIDE_INT) 64 - GET_MODE_SIZE (MODE))	\
-	    goto LABEL;							\
-	  if (GET_MODE_SIZE (MODE) == 2 				\
-	      && (((unsigned HOST_WIDE_INT) INTVAL (OP)) % 2) == 0	\
-	      &&  ((unsigned HOST_WIDE_INT) INTVAL (OP)) <= 30)		\
-	    goto LABEL;							\
-	  if (GET_MODE_SIZE (MODE) == 1 				\
-	      && ((unsigned HOST_WIDE_INT) INTVAL (OP)) <= 15)		\
-	    goto LABEL;							\
-        }								\
-    }									\
-  while (0)
-
-#define GO_IF_LEGITIMATE_ADDRESS(MODE, X, LABEL)                  \
-{ 								  \
-  if (BASE_REGISTER_RTX_P (X))					  \
-    goto LABEL;							  \
-  else if (GET_CODE (X) == PLUS || GET_CODE (X) == LO_SUM) 	  \
-    {								  \
-      rtx xop0 = XEXP (X,0);					  \
-      rtx xop1 = XEXP (X,1);					  \
-      if (BASE_REGISTER_RTX_P (xop0))				  \
-	GO_IF_LEGITIMATE_INDEX (MODE, REGNO (xop0), xop1, LABEL); \
-      if (BASE_REGISTER_RTX_P (xop1))				  \
-	GO_IF_LEGITIMATE_INDEX (MODE, REGNO (xop1), xop0, LABEL); \
-    }								  \
-}								
-
  /* Specify the machine mode that this machine uses
     for the index in the tablejump instruction.  */
  #define CASE_VECTOR_MODE SImode
