OSDN Git Service

* lib/target-supports.exp (check_effective_target_vect_condition):
[pf3gnuchains/gcc-fork.git] / gcc / reload.c
index 5f48ae7..8420c80 100644 (file)
@@ -256,7 +256,6 @@ static int push_secondary_reload (int, rtx, int, int, enum reg_class,
                                  enum insn_code *, secondary_reload_info *);
 static enum reg_class find_valid_class (enum machine_mode, enum machine_mode,
                                        int, unsigned int);
-static int reload_inner_reg_of_subreg (rtx, enum machine_mode, int);
 static void push_replacement (rtx *, int, enum machine_mode);
 static void dup_replacements (rtx *, rtx *);
 static void combine_reloads (void);
@@ -278,7 +277,7 @@ static int find_reloads_address (enum machine_mode, rtx *, rtx, rtx *,
 static rtx subst_reg_equivs (rtx, rtx);
 static rtx subst_indexed_address (rtx);
 static void update_auto_inc_notes (rtx, int, int);
-static int find_reloads_address_1 (enum machine_mode, rtx, int,
+static int find_reloads_address_1 (enum machine_mode, addr_space_t, rtx, int,
                                   enum rtx_code, enum rtx_code, rtx *,
                                   int, enum reload_type,int, rtx);
 static void find_reloads_address_part (rtx, rtx *, enum reg_class,
@@ -791,39 +790,39 @@ find_reusable_reload (rtx *p_in, rtx out, enum reg_class rclass,
   return n_reloads;
 }
 
-/* Return nonzero if X is a SUBREG which will require reloading of its
-   SUBREG_REG expression.  */
+/* Return true if X is a SUBREG that will need reloading of its SUBREG_REG
+   expression.  MODE is the mode that X will be used in.  OUTPUT is true if
+   the function is invoked for the output part of an enclosing reload.  */
 
-static int
-reload_inner_reg_of_subreg (rtx x, enum machine_mode mode, int output)
+static bool
+reload_inner_reg_of_subreg (rtx x, enum machine_mode mode, bool output)
 {
   rtx inner;
 
   /* Only SUBREGs are problematical.  */
   if (GET_CODE (x) != SUBREG)
-    return 0;
+    return false;
 
   inner = SUBREG_REG (x);
 
-  /* If INNER is a constant or PLUS, then INNER must be reloaded.  */
+  /* If INNER is a constant or PLUS, then INNER will need reloading.  */
   if (CONSTANT_P (inner) || GET_CODE (inner) == PLUS)
-    return 1;
+    return true;
 
-  /* If INNER is not a hard register, then INNER will not need to
-     be reloaded.  */
-  if (!REG_P (inner)
-      || REGNO (inner) >= FIRST_PSEUDO_REGISTER)
-    return 0;
+  /* If INNER is not a hard register, then INNER will not need reloading.  */
+  if (!(REG_P (inner) && HARD_REGISTER_P (inner)))
+    return false;
 
   /* If INNER is not ok for MODE, then INNER will need reloading.  */
-  if (! HARD_REGNO_MODE_OK (subreg_regno (x), mode))
-    return 1;
-
-  /* If the outer part is a word or smaller, INNER larger than a
-     word and the number of regs for INNER is not the same as the
-     number of words in INNER, then INNER will need reloading.  */
-  return (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
-         && output
+  if (!HARD_REGNO_MODE_OK (subreg_regno (x), mode))
+    return true;
+
+  /* If this is for an output, and the outer part is a word or smaller,
+     INNER is larger than a word and the number of registers in INNER is
+     not the same as the number of words in INNER, then INNER will need
+     reloading (with an in-out reload).  */
+  return (output
+         && GET_MODE_SIZE (mode) <= UNITS_PER_WORD
          && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD
          && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD)
              != (int) hard_regno_nregs[REGNO (inner)][GET_MODE (inner)]));
@@ -990,9 +989,9 @@ push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
      For machines that extend byte loads, do this for any SUBREG of a pseudo
      where both M1 and M2 are a word or smaller, M1 is wider than M2, and
      M2 is an integral mode that gets extended when loaded.
-     Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
-     either M1 is not valid for R or M2 is wider than a word but we only
-     need one word to store an M2-sized quantity in R.
+     Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R
+     where either M1 is not valid for R or M2 is wider than a word but we
+     only need one register to store an M2-sized quantity in R.
      (However, if OUT is nonzero, we need to reload the reg *and*
      the subreg, so do nothing here, and let following statement handle it.)
 
@@ -1082,17 +1081,16 @@ push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
       inmode = GET_MODE (in);
     }
 
-  /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
-     either M1 is not valid for R or M2 is wider than a word but we only
-     need one word to store an M2-sized quantity in R.
+  /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R
+     where M1 is not valid for R if it was not handled by the code above.
+
+     Similar issue for (SUBREG constant ...) if it was not handled by the
+     code above.  This can happen if SUBREG_BYTE != 0.
 
      However, we must reload the inner reg *as well as* the subreg in
      that case.  */
 
-  /* Similar issue for (SUBREG constant ...) if it was not handled by the
-     code above.  This can happen if SUBREG_BYTE != 0.  */
-
-  if (in != 0 && reload_inner_reg_of_subreg (in, inmode, 0))
+  if (in != 0 && reload_inner_reg_of_subreg (in, inmode, false))
     {
       enum reg_class in_class = rclass;
 
@@ -1117,10 +1115,10 @@ push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
 
   /* Similarly for paradoxical and problematical SUBREGs on the output.
      Note that there is no reason we need worry about the previous value
-     of SUBREG_REG (out); even if wider than out,
-     storing in a subreg is entitled to clobber it all
-     (except in the case of STRICT_LOW_PART,
-     and in that case the constraint should label it input-output.)  */
+     of SUBREG_REG (out); even if wider than out, storing in a subreg is
+     entitled to clobber it all (except in the case of a word mode subreg
+     or of a STRICT_LOW_PART, in that latter case the constraint should
+     label it input-output.)  */
   if (out != 0 && GET_CODE (out) == SUBREG
       && (subreg_lowpart_p (out) || strict_low)
 #ifdef CANNOT_CHANGE_MODE_CLASS
@@ -1144,14 +1142,12 @@ push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
                  ))
          || (REG_P (SUBREG_REG (out))
              && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
-             && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
-                  && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
-                      > UNITS_PER_WORD)
-                  && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
-                       / UNITS_PER_WORD)
-                      != (int) hard_regno_nregs[REGNO (SUBREG_REG (out))]
-                                               [GET_MODE (SUBREG_REG (out))]))
-                 || ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode)))
+             /* The case of a word mode subreg
+                is handled differently in the following statement.  */
+             && ! (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
+                   && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
+                       > UNITS_PER_WORD))
+             && ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode))
          || (secondary_reload_class (0, rclass, outmode, out) != NO_REGS
              && (secondary_reload_class (0, rclass, GET_MODE (SUBREG_REG (out)),
                                          SUBREG_REG (out))
@@ -1178,31 +1174,32 @@ push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
       outmode = GET_MODE (out);
     }
 
-  /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
-     either M1 is not valid for R or M2 is wider than a word but we only
-     need one word to store an M2-sized quantity in R.
+  /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R
+     where either M1 is not valid for R or M2 is wider than a word but we
+     only need one register to store an M2-sized quantity in R.
 
      However, we must reload the inner reg *as well as* the subreg in
-     that case.  In this case, the inner reg is an in-out reload.  */
+     that case and the inner reg is an in-out reload.  */
 
-  if (out != 0 && reload_inner_reg_of_subreg (out, outmode, 1))
+  if (out != 0 && reload_inner_reg_of_subreg (out, outmode, true))
     {
+      enum reg_class in_out_class
+       = find_valid_class (outmode, GET_MODE (SUBREG_REG (out)),
+                           subreg_regno_offset (REGNO (SUBREG_REG (out)),
+                                                GET_MODE (SUBREG_REG (out)),
+                                                SUBREG_BYTE (out),
+                                                GET_MODE (out)),
+                           REGNO (SUBREG_REG (out)));
+
       /* This relies on the fact that emit_reload_insns outputs the
         instructions for output reloads of type RELOAD_OTHER in reverse
         order of the reloads.  Thus if the outer reload is also of type
         RELOAD_OTHER, we are guaranteed that this inner reload will be
         output after the outer reload.  */
-      dont_remove_subreg = 1;
       push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
-                  &SUBREG_REG (out),
-                  find_valid_class (outmode, GET_MODE (SUBREG_REG (out)),
-                                    subreg_regno_offset (REGNO (SUBREG_REG (out)),
-                                                         GET_MODE (SUBREG_REG (out)),
-                                                         SUBREG_BYTE (out),
-                                                         GET_MODE (out)),
-                                    REGNO (SUBREG_REG (out))),
-                  VOIDmode, VOIDmode, 0, 0,
-                  opnum, RELOAD_OTHER);
+                  &SUBREG_REG (out), in_out_class, VOIDmode, VOIDmode,
+                  0, 0, opnum, RELOAD_OTHER);
+      dont_remove_subreg = 1;
     }
 
   /* If IN appears in OUT, we can't share any input-only reload for IN.  */
@@ -1767,9 +1764,9 @@ combine_reloads (void)
        && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
        && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
        && rld[i].when_needed != RELOAD_OTHER
-       && (CLASS_MAX_NREGS (rld[i].rclass, rld[i].inmode)
-           == CLASS_MAX_NREGS (rld[output_reload].rclass,
-                               rld[output_reload].outmode))
+       && (ira_reg_class_max_nregs [(int)rld[i].rclass][(int) rld[i].inmode]
+           == ira_reg_class_max_nregs [(int) rld[output_reload].rclass]
+                                      [(int) rld[output_reload].outmode])
        && rld[i].inc == 0
        && rld[i].reg_rtx == 0
 #ifdef SECONDARY_MEMORY_NEEDED
@@ -2825,6 +2822,13 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known,
          /* Address operands are reloaded in their existing mode,
             no matter what is specified in the machine description.  */
          operand_mode[i] = GET_MODE (recog_data.operand[i]);
+
+         /* If the address is a single CONST_INT pick address mode
+            instead otherwise we will later not know in which mode
+            the reload should be performed.  */
+         if (operand_mode[i] == VOIDmode)
+           operand_mode[i] = Pmode;
+
        }
       else if (code == MEM)
        {
@@ -3235,8 +3239,9 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known,
              case 'p':
                /* All necessary reloads for an address_operand
                   were handled in find_reloads_address.  */
-               this_alternative[i] = base_reg_class (VOIDmode, ADDRESS,
-                                                     SCRATCH);
+               this_alternative[i]
+                 = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
+                                   ADDRESS, SCRATCH);
                win = 1;
                badop = 0;
                break;
@@ -3441,9 +3446,9 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known,
 
                        /* If we didn't already win, we can reload
                           the address into a base register.  */
-                       this_alternative[i] = base_reg_class (VOIDmode,
-                                                             ADDRESS,
-                                                             SCRATCH);
+                       this_alternative[i]
+                         = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
+                                           ADDRESS, SCRATCH);
                        badop = 0;
                        break;
                      }
@@ -3973,18 +3978,16 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known,
            /* If the address to be reloaded is a VOIDmode constant,
               use the default address mode as mode of the reload register,
               as would have been done by find_reloads_address.  */
+           addr_space_t as = MEM_ADDR_SPACE (recog_data.operand[i]);
            enum machine_mode address_mode;
            address_mode = GET_MODE (XEXP (recog_data.operand[i], 0));
            if (address_mode == VOIDmode)
-             {
-               addr_space_t as = MEM_ADDR_SPACE (recog_data.operand[i]);
-               address_mode = targetm.addr_space.address_mode (as);
-             }
+             address_mode = targetm.addr_space.address_mode (as);
 
            operand_reloadnum[i]
              = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
                             &XEXP (recog_data.operand[i], 0), (rtx*) 0,
-                            base_reg_class (VOIDmode, MEM, SCRATCH),
+                            base_reg_class (VOIDmode, as, MEM, SCRATCH),
                             address_mode,
                             VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
            rld[operand_reloadnum[i]].inc
@@ -4205,7 +4208,12 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known,
              && (!JUMP_P (insn)
                  || !label_is_jump_target_p (XEXP (substitution, 0),
                                              insn)))
-           add_reg_note (insn, REG_LABEL_OPERAND, XEXP (substitution, 0));
+           {
+             add_reg_note (insn, REG_LABEL_OPERAND, XEXP (substitution, 0));
+             if (LABEL_P (XEXP (substitution, 0)))
+               ++LABEL_NUSES (XEXP (substitution, 0));
+           }
+
        }
       else
        retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
@@ -4542,7 +4550,7 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known,
               > GET_MODE_SIZE (rld[i].inmode)))
          ? rld[i].outmode : rld[i].inmode;
 
-      rld[i].nregs = CLASS_MAX_NREGS (rld[i].rclass, rld[i].mode);
+      rld[i].nregs = ira_reg_class_max_nregs [rld[i].rclass][rld[i].mode];
     }
 
   /* Special case a simple move with an input reload and a
@@ -4881,7 +4889,7 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
       if (reg_equiv_constant (regno) != 0)
        {
          find_reloads_address_part (reg_equiv_constant (regno), loc,
-                                    base_reg_class (mode, MEM, SCRATCH),
+                                    base_reg_class (mode, as, MEM, SCRATCH),
                                     GET_MODE (ad), opnum, type, ind_levels);
          return 1;
        }
@@ -4944,12 +4952,13 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
         subject of a CLOBBER in this insn.  */
 
       else if (regno < FIRST_PSEUDO_REGISTER
-              && regno_ok_for_base_p (regno, mode, MEM, SCRATCH)
+              && regno_ok_for_base_p (regno, mode, as, MEM, SCRATCH)
               && ! regno_clobbered_p (regno, this_insn, mode, 0))
        return 0;
 
       /* If we do not have one of the cases above, we must do the reload.  */
-      push_reload (ad, NULL_RTX, loc, (rtx*) 0, base_reg_class (mode, MEM, SCRATCH),
+      push_reload (ad, NULL_RTX, loc, (rtx*) 0,
+                  base_reg_class (mode, as, MEM, SCRATCH),
                   GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
       return 1;
     }
@@ -5050,7 +5059,7 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
          /* Must use TEM here, not AD, since it is the one that will
             have any subexpressions reloaded, if needed.  */
          push_reload (tem, NULL_RTX, loc, (rtx*) 0,
-                      base_reg_class (mode, MEM, SCRATCH), GET_MODE (tem),
+                      base_reg_class (mode, as, MEM, SCRATCH), GET_MODE (tem),
                       VOIDmode, 0,
                       0, opnum, type);
          return ! removed_and;
@@ -5068,7 +5077,7 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
           && REG_P (XEXP (ad, 0))
           && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
           && CONST_INT_P (XEXP (ad, 1))
-          && (regno_ok_for_base_p (REGNO (XEXP (ad, 0)), mode, PLUS,
+          && (regno_ok_for_base_p (REGNO (XEXP (ad, 0)), mode, as, PLUS,
                                    CONST_INT)
               /* Similarly, if we were to reload the base register and the
                  mem+offset address is still invalid, then we want to reload
@@ -5087,7 +5096,7 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
        }
 
       if (double_reg_address_ok
-         && regno_ok_for_base_p (REGNO (XEXP (ad, 0)), mode,
+         && regno_ok_for_base_p (REGNO (XEXP (ad, 0)), mode, as,
                                  PLUS, CONST_INT))
        {
          /* Unshare the sum as well.  */
@@ -5106,7 +5115,7 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
             reload the sum into a base reg.
             That will at least work.  */
          find_reloads_address_part (ad, loc,
-                                    base_reg_class (mode, MEM, SCRATCH),
+                                    base_reg_class (mode, as, MEM, SCRATCH),
                                     GET_MODE (ad), opnum, type, ind_levels);
        }
       return ! removed_and;
@@ -5158,7 +5167,7 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
 
       addend = XEXP (XEXP (ad, 0), 1 - op_index);
 
-      if ((regno_ok_for_base_p (REGNO (operand), mode, inner_code,
+      if ((regno_ok_for_base_p (REGNO (operand), mode, as, inner_code,
                                GET_CODE (addend))
           || operand == frame_pointer_rtx
 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
@@ -5187,11 +5196,11 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
                                 op_index == 0 ? addend : offset_reg);
          *loc = ad;
 
-         cls = base_reg_class (mode, MEM, GET_CODE (addend));
+         cls = base_reg_class (mode, as, MEM, GET_CODE (addend));
          find_reloads_address_part (XEXP (ad, op_index),
                                     &XEXP (ad, op_index), cls,
                                     GET_MODE (ad), opnum, type, ind_levels);
-         find_reloads_address_1 (mode,
+         find_reloads_address_1 (mode, as,
                                  XEXP (ad, 1 - op_index), 1, GET_CODE (ad),
                                  GET_CODE (XEXP (ad, op_index)),
                                  &XEXP (ad, 1 - op_index), opnum,
@@ -5244,13 +5253,14 @@ find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
            loc = &XEXP (*loc, 0);
        }
 
-      find_reloads_address_part (ad, loc, base_reg_class (mode, MEM, SCRATCH),
+      find_reloads_address_part (ad, loc,
+                                base_reg_class (mode, as, MEM, SCRATCH),
                                 address_mode, opnum, type, ind_levels);
       return ! removed_and;
     }
 
-  return find_reloads_address_1 (mode, ad, 0, MEM, SCRATCH, loc, opnum, type,
-                                ind_levels, insn);
+  return find_reloads_address_1 (mode, as, ad, 0, MEM, SCRATCH, loc,
+                                opnum, type, ind_levels, insn);
 }
 \f
 /* Find all pseudo regs appearing in AD
@@ -5483,14 +5493,15 @@ update_auto_inc_notes (rtx insn ATTRIBUTE_UNUSED, int regno ATTRIBUTE_UNUSED,
    handles those cases gracefully.  */
 
 static int
-find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
+find_reloads_address_1 (enum machine_mode mode, addr_space_t as,
+                       rtx x, int context,
                        enum rtx_code outer_code, enum rtx_code index_code,
                        rtx *loc, int opnum, enum reload_type type,
                        int ind_levels, rtx insn)
 {
-#define REG_OK_FOR_CONTEXT(CONTEXT, REGNO, MODE, OUTER, INDEX)         \
+#define REG_OK_FOR_CONTEXT(CONTEXT, REGNO, MODE, AS, OUTER, INDEX)     \
   ((CONTEXT) == 0                                                      \
-   ? regno_ok_for_base_p (REGNO, MODE, OUTER, INDEX)                   \
+   ? regno_ok_for_base_p (REGNO, MODE, AS, OUTER, INDEX)               \
    : REGNO_OK_FOR_INDEX_P (REGNO))
 
   enum reg_class context_reg_class;
@@ -5499,7 +5510,7 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
   if (context == 1)
     context_reg_class = INDEX_REG_CLASS;
   else
-    context_reg_class = base_reg_class (mode, outer_code, index_code);
+    context_reg_class = base_reg_class (mode, as, outer_code, index_code);
 
   switch (code)
     {
@@ -5556,10 +5567,10 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
        if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
            || code0 == ZERO_EXTEND || code1 == MEM)
          {
-           find_reloads_address_1 (mode, orig_op0, 1, PLUS, SCRATCH,
+           find_reloads_address_1 (mode, as, orig_op0, 1, PLUS, SCRATCH,
                                    &XEXP (x, 0), opnum, type, ind_levels,
                                    insn);
-           find_reloads_address_1 (mode, orig_op1, 0, PLUS, code0,
+           find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, code0,
                                    &XEXP (x, 1), opnum, type, ind_levels,
                                    insn);
          }
@@ -5567,56 +5578,56 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
        else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
                 || code1 == ZERO_EXTEND || code0 == MEM)
          {
-           find_reloads_address_1 (mode, orig_op0, 0, PLUS, code1,
+           find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, code1,
                                    &XEXP (x, 0), opnum, type, ind_levels,
                                    insn);
-           find_reloads_address_1 (mode, orig_op1, 1, PLUS, SCRATCH,
+           find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
                                    &XEXP (x, 1), opnum, type, ind_levels,
                                    insn);
          }
 
        else if (code0 == CONST_INT || code0 == CONST
                 || code0 == SYMBOL_REF || code0 == LABEL_REF)
-         find_reloads_address_1 (mode, orig_op1, 0, PLUS, code0,
+         find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, code0,
                                  &XEXP (x, 1), opnum, type, ind_levels,
                                  insn);
 
        else if (code1 == CONST_INT || code1 == CONST
                 || code1 == SYMBOL_REF || code1 == LABEL_REF)
-         find_reloads_address_1 (mode, orig_op0, 0, PLUS, code1,
+         find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, code1,
                                  &XEXP (x, 0), opnum, type, ind_levels,
                                  insn);
 
        else if (code0 == REG && code1 == REG)
          {
            if (REGNO_OK_FOR_INDEX_P (REGNO (op1))
-               && regno_ok_for_base_p (REGNO (op0), mode, PLUS, REG))
+               && regno_ok_for_base_p (REGNO (op0), mode, as, PLUS, REG))
              return 0;
            else if (REGNO_OK_FOR_INDEX_P (REGNO (op0))
-                    && regno_ok_for_base_p (REGNO (op1), mode, PLUS, REG))
+                    && regno_ok_for_base_p (REGNO (op1), mode, as, PLUS, REG))
              return 0;
-           else if (regno_ok_for_base_p (REGNO (op0), mode, PLUS, REG))
-             find_reloads_address_1 (mode, orig_op1, 1, PLUS, SCRATCH,
+           else if (regno_ok_for_base_p (REGNO (op0), mode, as, PLUS, REG))
+             find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
                                      &XEXP (x, 1), opnum, type, ind_levels,
                                      insn);
            else if (REGNO_OK_FOR_INDEX_P (REGNO (op1)))
-             find_reloads_address_1 (mode, orig_op0, 0, PLUS, REG,
+             find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, REG,
                                      &XEXP (x, 0), opnum, type, ind_levels,
                                      insn);
-           else if (regno_ok_for_base_p (REGNO (op1), mode, PLUS, REG))
-             find_reloads_address_1 (mode, orig_op0, 1, PLUS, SCRATCH,
+           else if (regno_ok_for_base_p (REGNO (op1), mode, as, PLUS, REG))
+             find_reloads_address_1 (mode, as, orig_op0, 1, PLUS, SCRATCH,
                                      &XEXP (x, 0), opnum, type, ind_levels,
                                      insn);
            else if (REGNO_OK_FOR_INDEX_P (REGNO (op0)))
-             find_reloads_address_1 (mode, orig_op1, 0, PLUS, REG,
+             find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, REG,
                                      &XEXP (x, 1), opnum, type, ind_levels,
                                      insn);
            else
              {
-               find_reloads_address_1 (mode, orig_op0, 0, PLUS, REG,
+               find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, REG,
                                        &XEXP (x, 0), opnum, type, ind_levels,
                                        insn);
-               find_reloads_address_1 (mode, orig_op1, 1, PLUS, SCRATCH,
+               find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
                                        &XEXP (x, 1), opnum, type, ind_levels,
                                        insn);
              }
@@ -5624,20 +5635,20 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
 
        else if (code0 == REG)
          {
-           find_reloads_address_1 (mode, orig_op0, 1, PLUS, SCRATCH,
+           find_reloads_address_1 (mode, as, orig_op0, 1, PLUS, SCRATCH,
                                    &XEXP (x, 0), opnum, type, ind_levels,
                                    insn);
-           find_reloads_address_1 (mode, orig_op1, 0, PLUS, REG,
+           find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, REG,
                                    &XEXP (x, 1), opnum, type, ind_levels,
                                    insn);
          }
 
        else if (code1 == REG)
          {
-           find_reloads_address_1 (mode, orig_op1, 1, PLUS, SCRATCH,
+           find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
                                    &XEXP (x, 1), opnum, type, ind_levels,
                                    insn);
-           find_reloads_address_1 (mode, orig_op0, 0, PLUS, REG,
+           find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, REG,
                                    &XEXP (x, 0), opnum, type, ind_levels,
                                    insn);
          }
@@ -5679,7 +5690,7 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
        if ((REG_P (XEXP (op1, 1))
             && !REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1))))
            || GET_CODE (XEXP (op1, 1)) == PLUS)
-         find_reloads_address_1 (mode, XEXP (op1, 1), 1, code, SCRATCH,
+         find_reloads_address_1 (mode, as, XEXP (op1, 1), 1, code, SCRATCH,
                                  &XEXP (op1, 1), opnum, RELOAD_OTHER,
                                  ind_levels, insn);
 
@@ -5721,8 +5732,8 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
                   register.  */
                reloadnum = push_reload (tem, tem, &XEXP (x, 0),
                                         &XEXP (op1, 0),
-                                        base_reg_class (mode, code,
-                                                        index_code),
+                                        base_reg_class (mode, as,
+                                                        code, index_code),
                                         GET_MODE (x), GET_MODE (x), 0,
                                         0, opnum, RELOAD_OTHER);
 
@@ -5735,11 +5746,12 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
          regno = reg_renumber[regno];
 
        /* We require a base register here...  */
-       if (!regno_ok_for_base_p (regno, GET_MODE (x), code, index_code))
+       if (!regno_ok_for_base_p (regno, GET_MODE (x), as, code, index_code))
          {
            reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0),
                                     &XEXP (op1, 0), &XEXP (x, 0),
-                                    base_reg_class (mode, code, index_code),
+                                    base_reg_class (mode, as,
+                                                    code, index_code),
                                     GET_MODE (x), GET_MODE (x), 0, 0,
                                     opnum, RELOAD_OTHER);
 
@@ -5805,7 +5817,7 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
          if (reg_renumber[regno] >= 0)
            regno = reg_renumber[regno];
          if (regno >= FIRST_PSEUDO_REGISTER
-             || !REG_OK_FOR_CONTEXT (context, regno, mode, code,
+             || !REG_OK_FOR_CONTEXT (context, regno, mode, as, code,
                                      index_code))
            {
              int reloadnum;
@@ -5874,7 +5886,7 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
         reloaded.  Targets that are better off reloading just either part
         (or perhaps even a different part of an outer expression), should
         define LEGITIMIZE_RELOAD_ADDRESS.  */
-      find_reloads_address_1 (GET_MODE (XEXP (x, 0)), XEXP (x, 0),
+      find_reloads_address_1 (GET_MODE (XEXP (x, 0)), as, XEXP (x, 0),
                              context, code, SCRATCH, &XEXP (x, 0), opnum,
                              type, ind_levels, insn);
       push_reload (x, NULL_RTX, loc, (rtx*) 0,
@@ -5945,7 +5957,7 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
          regno = reg_renumber[regno];
 
        if (regno >= FIRST_PSEUDO_REGISTER
-           || !REG_OK_FOR_CONTEXT (context, regno, mode, outer_code,
+           || !REG_OK_FOR_CONTEXT (context, regno, mode, as, outer_code,
                                    index_code))
          {
            push_reload (x, NULL_RTX, loc, (rtx*) 0,
@@ -5978,7 +5990,7 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
            {
              int regno ATTRIBUTE_UNUSED = subreg_regno (x);
 
-             if (!REG_OK_FOR_CONTEXT (context, regno, mode, outer_code,
+             if (!REG_OK_FOR_CONTEXT (context, regno, mode, as, outer_code,
                                       index_code))
                {
                  push_reload (x, NULL_RTX, loc, (rtx*) 0,
@@ -5992,8 +6004,8 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
          else
            {
              enum reg_class rclass = context_reg_class;
-             if ((unsigned) CLASS_MAX_NREGS (rclass, GET_MODE (SUBREG_REG (x)))
-                 > reg_class_size[rclass])
+             if (ira_reg_class_max_nregs [rclass][GET_MODE (SUBREG_REG (x))]
+                 > reg_class_size[(int) rclass])
                {
                  x = find_reloads_subreg_address (x, 0, opnum,
                                                   ADDR_TYPE (type),
@@ -6019,8 +6031,9 @@ find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
        if (fmt[i] == 'e')
          /* Pass SCRATCH for INDEX_CODE, since CODE can never be a PLUS once
             we get here.  */
-         find_reloads_address_1 (mode, XEXP (x, i), context, code, SCRATCH,
-                                 &XEXP (x, i), opnum, type, ind_levels, insn);
+         find_reloads_address_1 (mode, as, XEXP (x, i), context,
+                                 code, SCRATCH, &XEXP (x, i),
+                                 opnum, type, ind_levels, insn);
       }
   }
 
@@ -6137,8 +6150,8 @@ find_reloads_subreg_address (rtx x, int force_replace, int opnum,
 
              XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
              PUT_MODE (tem, GET_MODE (x));
-             if (MEM_OFFSET (tem))
-               set_mem_offset (tem, plus_constant (MEM_OFFSET (tem), offset));
+             if (MEM_OFFSET_KNOWN_P (tem))
+               set_mem_offset (tem, MEM_OFFSET (tem) + offset);
              if (MEM_SIZE_KNOWN_P (tem)
                  && MEM_SIZE (tem) != (HOST_WIDE_INT) outer_size)
                set_mem_size (tem, outer_size);
@@ -6197,7 +6210,9 @@ find_reloads_subreg_address (rtx x, int force_replace, int opnum,
                         MEM_ADDR_SPACE (reg_equiv_mem (regno))))
                {
                  push_reload (XEXP (tem, 0), NULL_RTX, &XEXP (tem, 0), (rtx*) 0,
-                              base_reg_class (GET_MODE (tem), MEM, SCRATCH),
+                              base_reg_class (GET_MODE (tem),
+                                              MEM_ADDR_SPACE (tem),
+                                              MEM, SCRATCH),
                               GET_MODE (XEXP (tem, 0)), VOIDmode, 0, 0,
                               opnum, type);
                  reloaded = 1;
@@ -6216,8 +6231,8 @@ find_reloads_subreg_address (rtx x, int force_replace, int opnum,
            }
        }
     }
-  if (reloaded && address_reloaded)
-    *address_reloaded = 1;
+  if (address_reloaded)
+    *address_reloaded = reloaded;
 
   return x;
 }
@@ -7224,7 +7239,7 @@ regno_clobbered_p (unsigned int regno, rtx insn, enum machine_mode mode,
        {
          rtx elt = XVECEXP (PATTERN (insn), 0, i);
          if ((GET_CODE (elt) == CLOBBER
-              || (sets == 1 && GET_CODE (PATTERN (insn)) == SET))
+              || (sets == 1 && GET_CODE (elt) == SET))
              && REG_P (XEXP (elt, 0)))
            {
              unsigned int test = REGNO (XEXP (elt, 0));