diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bf23d0fe43fc72b08bcbe1a387bc4f7405180d39..38654fbbbe0bdb257aff0a10bde7a875ecdd682f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2002-05-16  Nick Clifton  <nickc@cambridge.redhat.com>
+
+	* config/arm/arm.c (arm_rtx_costs): Check for RTX being a
+	SYMBOL_REF before calling CONSTANT_POOL_ADDRESS_P.
+	(arm_adjust_cost): Check for RTX being a SYMBOL_REF before
+	calling CONSTANT_POOL_ADDRESS_P.
+	* config/arm/arm.h (TARGET_CPU_CPP_BUILTINS): Fix typo in code
+	to decide whether to define __arm__ or __thumb.
+        (THUMB_GO_IF_LEGITIMATE_ADDRESS): Check for RTX being a
+	SYMBOL_REF before calling CONSTANT_POOL_ADDRESS_P.
+
 2002-05-16  Neil Booth  <neil@daikokuya.demon.co.uk>
 
 	* config/arc/arc.h (CPP_PREDEFINES): Remove.
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index ba5eb055e67bb63a99a9414af6e487b4edc115f2..a1543f885334ec20e3d645a71ce5427d965efb9b 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -2549,7 +2549,8 @@ arm_rtx_costs (x, code, outer)
 	  /* Memory costs quite a lot for the first word, but subsequent words
 	     load at the equivalent of a single insn each.  */
 	  return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
-		  + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
+		  + ((GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
+		     ? 4 : 0));
 
 	case IF_THEN_ELSE:
 	  /* XXX a guess. */
@@ -2597,7 +2598,8 @@ arm_rtx_costs (x, code, outer)
       /* Memory costs quite a lot for the first word, but subsequent words
 	 load at the equivalent of a single insn each.  */
       return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
-	      + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
+	      + (GET_CODE (x) == SYMBOL_REF
+		 && CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
 
     case DIV:
     case MOD:
@@ -2905,16 +2907,16 @@ arm_adjust_cost (insn, link, dep, cost)
       && (d_pat = single_set (dep)) != NULL
       && GET_CODE (SET_DEST (d_pat)) == MEM)
     {
+      rtx src_mem = XEXP (SET_SRC (i_pat), 0);
       /* This is a load after a store, there is no conflict if the load reads
 	 from a cached area.  Assume that loads from the stack, and from the
 	 constant pool are cached, and that others will miss.  This is a 
 	 hack.  */
       
-      if (CONSTANT_POOL_ADDRESS_P (XEXP (SET_SRC (i_pat), 0))
-	  || reg_mentioned_p (stack_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
-	  || reg_mentioned_p (frame_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
-	  || reg_mentioned_p (hard_frame_pointer_rtx, 
-			      XEXP (SET_SRC (i_pat), 0)))
+      if ((GET_CODE (src_mem) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (src_mem))
+	  || reg_mentioned_p (stack_pointer_rtx, src_mem)
+	  || reg_mentioned_p (frame_pointer_rtx, src_mem)
+	  || reg_mentioned_p (hard_frame_pointer_rtx, src_mem))
 	return 1;
     }
 
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index b5a848aae131244110fba241b90be27491a256cf..fcb2c1f4a6747ca6b1d30f20a57afb179135c036 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -30,7 +30,7 @@ Boston, MA 02111-1307, USA.  */
 #define TARGET_CPU_CPP_BUILTINS()			\
   do							\
     {							\
-	if (TARGET_THUMB)				\
+	if (TARGET_ARM)					\
 	  builtin_define ("__arm__");			\
 	else						\
 	  builtin_define ("__thumb__");			\
@@ -2134,7 +2134,8 @@ typedef struct
     goto WIN;								\
   /* This is PC relative data before MACHINE_DEPENDENT_REORG runs.  */	\
   else if (GET_MODE_SIZE (MODE) >= 4 && CONSTANT_P (X)			\
-	   && CONSTANT_POOL_ADDRESS_P (X) && ! flag_pic)		\
+	   && GET_CODE (X) == SYMBOL_REF 				\
+           && CONSTANT_POOL_ADDRESS_P (X) && ! flag_pic)		\
     goto WIN;								\
   /* This is PC relative data after MACHINE_DEPENDENT_REORG runs.  */	\
   else if (GET_MODE_SIZE (MODE) >= 4 && reload_completed		\