OSDN Git Service

PR preprocessor/6521
[pf3gnuchains/gcc-fork.git] / gcc / reload1.c
index 9a90e1e..3974e99 100644 (file)
@@ -1,6 +1,6 @@
 /* Reload pseudo regs into hard regs for insns that require hard regs.
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -41,6 +41,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "real.h"
 #include "toplev.h"
 #include "except.h"
+#include "tree.h"
 
 /* This file contains the reload pass of the compiler, which is
    run after register allocation has been done.  It checks that
@@ -323,10 +324,10 @@ static struct elim_table *reg_eliminate = 0;
 
 /* This is an intermediate structure to initialize the table.  It has
    exactly the members provided by ELIMINABLE_REGS.  */
-static struct elim_table_1
+static const struct elim_table_1
 {
-  int from;
-  int to;
+  const int from;
+  const int to;
 } reg_eliminate_1[] =
 
 /* If a set of eliminable registers was specified, define the table from it.
@@ -366,9 +367,9 @@ static int (*offsets_at)[NUM_ELIMINABLE_REGS];
 
 static int num_labels;
 \f
-static void replace_pseudos_in_call_usage      PARAMS((rtx *,
-                                                       enum machine_mode,
-                                                       rtx));
+static void replace_pseudos_in_call_usage      PARAMS ((rtx *,
+                                                        enum machine_mode,
+                                                        rtx));
 static void maybe_fix_stack_asms       PARAMS ((void));
 static void copy_reloads               PARAMS ((struct insn_chain *));
 static void calculate_needs_all_insns  PARAMS ((int));
@@ -459,7 +460,7 @@ static void failed_reload           PARAMS ((rtx, int));
 static int set_reload_reg              PARAMS ((int, int));
 static void reload_cse_delete_noop_set PARAMS ((rtx, rtx));
 static void reload_cse_simplify                PARAMS ((rtx));
-static void fixup_abnormal_edges       PARAMS ((void));
+void fixup_abnormal_edges              PARAMS ((void));
 extern void dump_needs                 PARAMS ((struct insn_chain *));
 \f
 /* Initialize the reload pass once per compilation.  */
@@ -790,7 +791,12 @@ reload (first, global)
              i = REGNO (SET_DEST (set));
              if (i > LAST_VIRTUAL_REGISTER)
                {
-                 if (GET_CODE (x) == MEM)
+                 /* It can happen that a REG_EQUIV note contains a MEM
+                    that is not a legitimate memory operand.  As later
+                    stages of reload assume that all addresses found
+                    in the reg_equiv_* arrays were originally legitimate,
+                    we ignore such REG_EQUIV notes.  */
+                 if (memory_operand (x, VOIDmode))
                    {
                      /* Always unshare the equivalence, so we can
                         substitute into this insn without touching the
@@ -1071,9 +1077,16 @@ reload (first, global)
          for (list = reg_equiv_init[i]; list; list = XEXP (list, 1))
            {
              rtx equiv_insn = XEXP (list, 0);
-             if (GET_CODE (equiv_insn) == NOTE)
-               continue;
-             if (reg_set_p (regno_reg_rtx[i], PATTERN (equiv_insn)))
+
+             /* If we already deleted the insn or if it may trap, we can't
+                delete it.  The latter case shouldn't happen, but can
+                if an insn has a variable address, gets a REG_EH_REGION
+                note added to it, and then gets converted into an load
+                from a constant address.  */
+             if (GET_CODE (equiv_insn) == NOTE
+                 || can_throw_internal (equiv_insn))
+               ;
+             else if (reg_set_p (regno_reg_rtx[i], PATTERN (equiv_insn)))
                delete_dead_insn (equiv_insn);
              else
                {
@@ -1147,9 +1160,9 @@ reload (first, global)
            {
              rtx reg = regno_reg_rtx[i];
 
+             REG_USERVAR_P (reg) = 0;
              PUT_CODE (reg, MEM);
              XEXP (reg, 0) = addr;
-             REG_USERVAR_P (reg) = 0;
              if (reg_equiv_memory_loc[i])
                MEM_COPY_ATTRIBUTES (reg, reg_equiv_memory_loc[i]);
              else
@@ -1271,6 +1284,11 @@ reload (first, global)
   unused_insn_chains = 0;
   fixup_abnormal_edges ();
 
+  /* Replacing pseudos with their memory equivalents might have
+     created shared rtx.  Subsequent passes would get confused
+     by this, so unshare everything here.  */
+  unshare_all_rtl_again (first);
+
   return failure;
 }
 
@@ -1356,7 +1374,8 @@ maybe_fix_stack_asms ()
                  break;
 
                case 'p':
-                 cls = (int) reg_class_subunion[cls][(int) BASE_REG_CLASS];
+                 cls = (int) reg_class_subunion[cls]
+                   [(int) MODE_BASE_REG_CLASS (VOIDmode)];
                  break;
 
                case 'g':
@@ -1881,13 +1900,13 @@ spill_failure (insn, class)
 {
   static const char *const reg_class_names[] = REG_CLASS_NAMES;
   if (asm_noperands (PATTERN (insn)) >= 0)
-    error_for_asm (insn, "Can't find a register in class `%s' while reloading `asm'.",
+    error_for_asm (insn, "can't find a register in class `%s' while reloading `asm'",
                   reg_class_names[class]);
   else
     {
-      error ("Unable to find a register to spill in class `%s'.",
+      error ("unable to find a register to spill in class `%s'",
             reg_class_names[class]);
-      fatal_insn ("This is the insn:", insn);
+      fatal_insn ("this is the insn:", insn);
     }
 }
 \f
@@ -2043,8 +2062,26 @@ alter_reg (i, from_reg)
 
       /* If we have any adjustment to make, or if the stack slot is the
         wrong mode, make a new stack slot.  */
-      if (adjust != 0 || GET_MODE (x) != GET_MODE (regno_reg_rtx[i]))
-       x = adjust_address_nv (x, GET_MODE (regno_reg_rtx[i]), adjust);
+      x = adjust_address_nv (x, GET_MODE (regno_reg_rtx[i]), adjust);
+
+      /* If we have a decl for the original register, set it for the
+        memory.  If this is a shared MEM, make a copy.  */
+      if (REGNO_DECL (i))
+       {
+         rtx decl = DECL_RTL_IF_SET (REGNO_DECL (i));
+
+         /* We can do this only for the DECLs home pseudo, not for
+            any copies of it, since otherwise when the stack slot
+            is reused, nonoverlapping_memrefs_p might think they
+            cannot overlap.  */
+         if (decl && GET_CODE (decl) == REG && REGNO (decl) == (unsigned) i)
+           {
+             if (from_reg != -1 && spill_stack_slot[from_reg] == x)
+               x = copy_rtx (x);
+
+             set_mem_expr (x, REGNO_DECL (i));
+           }
+       }
 
       /* Save the stack slot for later.  */
       reg_equiv_memory_loc[i] = x;
@@ -2265,6 +2302,7 @@ eliminate_regs (x, mem_mode, insn)
     {
     case CONST_INT:
     case CONST_DOUBLE:
+    case CONST_VECTOR:
     case CONST:
     case SYMBOL_REF:
     case CODE_LABEL:
@@ -2298,8 +2336,8 @@ eliminate_regs (x, mem_mode, insn)
              return plus_constant (ep->to_rtx, ep->previous_offset);
 
        }
-      else if (reg_renumber[regno] < 0 && reg_equiv_constant
-              && reg_equiv_constant[regno]
+      else if (reg_renumber && reg_renumber[regno] < 0
+              && reg_equiv_constant && reg_equiv_constant[regno]
               && ! CONSTANT_P (reg_equiv_constant[regno]))
        return eliminate_regs (copy_rtx (reg_equiv_constant[regno]),
                               mem_mode, insn);
@@ -2365,7 +2403,7 @@ eliminate_regs (x, mem_mode, insn)
        rtx new0 = eliminate_regs (XEXP (x, 0), mem_mode, insn);
        rtx new1 = eliminate_regs (XEXP (x, 1), mem_mode, insn);
 
-       if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
+       if (reg_renumber && (new0 != XEXP (x, 0) || new1 != XEXP (x, 1)))
          {
            /* If one side is a PLUS and the other side is a pseudo that
               didn't get a hard register but has a reg_equiv_constant,
@@ -2473,7 +2511,8 @@ eliminate_regs (x, mem_mode, insn)
        {
          new = eliminate_regs (XEXP (x, 1), mem_mode, insn);
          if (new != XEXP (x, 1))
-           return gen_rtx_fmt_ee (GET_CODE (x), GET_MODE (x), XEXP (x, 0), new);
+           return
+             gen_rtx_fmt_ee (GET_CODE (x), GET_MODE (x), XEXP (x, 0), new);
        }
       return x;
 
@@ -2534,14 +2573,7 @@ eliminate_regs (x, mem_mode, insn)
                   )
                  || x_size == new_size)
              )
-           {
-             int offset = SUBREG_BYTE (x);
-             enum machine_mode mode = GET_MODE (x);
-
-             PUT_MODE (new, mode);
-             XEXP (new, 0) = plus_constant (XEXP (new, 0), offset);
-             return new;
-           }
+           return adjust_address_nv (new, GET_MODE (x), SUBREG_BYTE (x));
          else
            return gen_rtx_SUBREG (GET_MODE (x), new, SUBREG_BYTE (x));
        }
@@ -2649,6 +2681,7 @@ elimination_effects (x, mem_mode)
     {
     case CONST_INT:
     case CONST_DOUBLE:
+    case CONST_VECTOR:
     case CONST:
     case SYMBOL_REF:
     case CODE_LABEL:
@@ -2682,7 +2715,7 @@ elimination_effects (x, mem_mode)
        }
       else if (reg_renumber[regno] < 0 && reg_equiv_constant
               && reg_equiv_constant[regno]
-              && ! CONSTANT_P (reg_equiv_constant[regno]))
+              && ! function_invariant_p (reg_equiv_constant[regno]))
        elimination_effects (reg_equiv_constant[regno], mem_mode);
       return;
 
@@ -2921,38 +2954,32 @@ eliminate_regs_in_insn (insn, replace)
            if (ep->from == FRAME_POINTER_REGNUM
                && ep->to == HARD_FRAME_POINTER_REGNUM)
              {
-               rtx src = SET_SRC (old_set);
-               int offset = 0, ok = 0;
-               rtx prev_insn, prev_set;
-
-               if (src == ep->to_rtx)
-                 offset = 0, ok = 1;
-               else if (GET_CODE (src) == PLUS
-                        && GET_CODE (XEXP (src, 0)) == CONST_INT
-                        && XEXP (src, 1) == ep->to_rtx)
-                 offset = INTVAL (XEXP (src, 0)), ok = 1;
-               else if (GET_CODE (src) == PLUS
-                        && GET_CODE (XEXP (src, 1)) == CONST_INT
-                        && XEXP (src, 0) == ep->to_rtx)
-                 offset = INTVAL (XEXP (src, 1)), ok = 1;
-               else if ((prev_insn = prev_nonnote_insn (insn)) != 0
-                        && (prev_set = single_set (prev_insn)) != 0
-                        && rtx_equal_p (SET_DEST (prev_set), src))
+               rtx base = SET_SRC (old_set);
+               rtx base_insn = insn;
+               int offset = 0;
+
+               while (base != ep->to_rtx)
                  {
-                   src = SET_SRC (prev_set);
-                   if (src == ep->to_rtx)
-                     offset = 0, ok = 1;
-                   else if (GET_CODE (src) == PLUS
-                            && GET_CODE (XEXP (src, 0)) == CONST_INT
-                            && XEXP (src, 1) == ep->to_rtx)
-                     offset = INTVAL (XEXP (src, 0)), ok = 1;
-                   else if (GET_CODE (src) == PLUS
-                            && GET_CODE (XEXP (src, 1)) == CONST_INT
-                            && XEXP (src, 0) == ep->to_rtx)
-                     offset = INTVAL (XEXP (src, 1)), ok = 1;
+                   rtx prev_insn, prev_set;
+
+                   if (GET_CODE (base) == PLUS
+                       && GET_CODE (XEXP (base, 1)) == CONST_INT)
+                     {
+                       offset += INTVAL (XEXP (base, 1));
+                       base = XEXP (base, 0);
+                     }
+                   else if ((prev_insn = prev_nonnote_insn (base_insn)) != 0
+                            && (prev_set = single_set (prev_insn)) != 0
+                            && rtx_equal_p (SET_DEST (prev_set), base))
+                     {
+                       base = SET_SRC (prev_set);
+                       base_insn = prev_insn;
+                     }
+                   else
+                     break;
                  }
 
-               if (ok)
+               if (base == ep->to_rtx)
                  {
                    rtx src
                      = plus_constant (ep->to_rtx, offset - ep->offset);
@@ -3468,7 +3495,7 @@ init_elim_table ()
 {
   struct elim_table *ep;
 #ifdef ELIMINABLE_REGS
-  struct elim_table_1 *ep1;
+  const struct elim_table_1 *ep1;
 #endif
 
   if (!reg_eliminate)
@@ -3744,6 +3771,7 @@ scan_paradoxical_subregs (x)
     case SYMBOL_REF:
     case LABEL_REF:
     case CONST_DOUBLE:
+    case CONST_VECTOR: /* shouldn't happen, but just in case.  */
     case CC0:
     case PC:
     case USE:
@@ -4047,7 +4075,7 @@ reload_as_needed (live_known)
       /* Don't assume a reload reg is still good after a call insn
         if it is a call-used reg.  */
       else if (GET_CODE (insn) == CALL_INSN)
-       AND_COMPL_HARD_REG_SET(reg_reloaded_valid, call_used_reg_set);
+       AND_COMPL_HARD_REG_SET (reg_reloaded_valid, call_used_reg_set);
     }
 
   /* Clean up.  */
@@ -4302,7 +4330,7 @@ clear_reload_reg_in_use (regno, opnum, type, mode)
      excluding the intervals of of reload registers by them from the
      interval of freed reload registers.  Since we only keep track of
      one set of interval bounds, we might have to exclude somewhat
-     more then what would be necessary if we used a HARD_REG_SET here.
+     more than what would be necessary if we used a HARD_REG_SET here.
      But this should only happen very infrequently, so there should
      be no reason to worry about it.  */
 
@@ -4824,7 +4852,7 @@ reload_reg_free_for_value_p (start_regno, regno, opnum, type, value, out,
       rtx reg = rld[i].reg_rtx;
       if (reg && GET_CODE (reg) == REG
          && ((unsigned) regno - true_regnum (reg)
-             <= HARD_REGNO_NREGS (REGNO (reg), GET_MODE (reg)) - (unsigned)1)
+             <= HARD_REGNO_NREGS (REGNO (reg), GET_MODE (reg)) - (unsigned) 1)
          && i != reloadnum)
        {
          rtx other_input = rld[i].in;
@@ -5019,7 +5047,7 @@ failed_reload (insn, r)
 {
   if (asm_noperands (PATTERN (insn)) < 0)
     /* It's the compiler's fault.  */
-    fatal_insn ("Could not find a spill register", insn);
+    fatal_insn ("could not find a spill register", insn);
 
   /* It's the user's fault; the operand's mode and constraint
      don't match.  Disable this reload so we don't crash in final.  */
@@ -5306,7 +5334,7 @@ choose_reload_regs (chain)
        {
          max_group_size = MAX (rld[j].nregs, max_group_size);
          group_class
-           = reg_class_superunion[(int) rld[j].class][(int)group_class];
+           = reg_class_superunion[(int) rld[j].class][(int) group_class];
        }
 
       save_reload_reg_rtx[j] = rld[j].reg_rtx;
@@ -5547,6 +5575,7 @@ choose_reload_regs (chain)
                                  && ! TEST_HARD_REG_BIT (reg_reloaded_dead, i))
                              /* Don't clobber the frame pointer.  */
                              || (i == HARD_FRAME_POINTER_REGNUM
+                                 && frame_pointer_needed
                                  && rld[r].out)
                              /* Don't really use the inherited spill reg
                                 if we need it wider than we've got it.  */
@@ -5717,7 +5746,9 @@ choose_reload_regs (chain)
 
              /* If we found an equivalent reg, say no code need be generated
                 to load it, and use it as our reload reg.  */
-             if (equiv != 0 && regno != HARD_FRAME_POINTER_REGNUM)
+             if (equiv != 0 
+                 && (regno != HARD_FRAME_POINTER_REGNUM 
+                     || !frame_pointer_needed))
                {
                  int nr = HARD_REGNO_NREGS (regno, rld[r].mode);
                  int k;
@@ -5883,7 +5914,7 @@ choose_reload_regs (chain)
             A special case are auto_inc expressions; even if the input is
             inherited, we still need the address for the output.  We can
             recognize them because they have RELOAD_OUT set to RELOAD_IN.
-            If we suceeded removing some reload and we are doing a preliminary
+            If we succeeded removing some reload and we are doing a preliminary
             pass just to remove such reloads, make another pass, since the
             removal of one reload might allow us to inherit another one.  */
          else if (rld[r].in
@@ -7526,9 +7557,8 @@ gen_reload (out, in, opnum, type)
   return last ? NEXT_INSN (last) : get_insns ();
 }
 \f
-/* Delete a previously made output-reload
-   whose result we now believe is not needed.
-   First we double-check.
+/* Delete a previously made output-reload whose result we now believe
+   is not needed.  First we double-check.
 
    INSN is the insn now being processed.
    LAST_RELOAD_REG is the hard register number for which we want to delete
@@ -7622,15 +7652,21 @@ delete_output_reload (insn, j, last_reload_reg)
        }
     }
 
+  /* We will be deleting the insn.  Remove the spill reg information.  */
+  for (k = HARD_REGNO_NREGS (last_reload_reg, GET_MODE (reg)); k-- > 0; )
+    {
+      spill_reg_store[last_reload_reg + k] = 0;
+      spill_reg_stored_to[last_reload_reg + k] = 0;
+    }
+
   /* The caller has already checked that REG dies or is set in INSN.
-     It has also checked that we are optimizing, and thus some inaccurancies
-     in the debugging information are acceptable.
-     So we could just delete output_reload_insn.
-     But in some cases we can improve the debugging information without
-     sacrificing optimization - maybe even improving the code:
-     See if the pseudo reg has been completely replaced
-     with reload regs.  If so, delete the store insn
-     and forget we had a stack slot for the pseudo.  */
+     It has also checked that we are optimizing, and thus some
+     inaccurancies in the debugging information are acceptable.
+     So we could just delete output_reload_insn.  But in some cases
+     we can improve the debugging information without sacrificing
+     optimization - maybe even improving the code: See if the pseudo
+     reg has been completely replaced with reload regs.  If so, delete
+     the store insn and forget we had a stack slot for the pseudo.  */
   if (rld[j].out != rld[j].in
       && REG_N_DEATHS (REGNO (reg)) == 1
       && REG_N_SETS (REGNO (reg)) == 1
@@ -7639,11 +7675,10 @@ delete_output_reload (insn, j, last_reload_reg)
     {
       rtx i2;
 
-      /* We know that it was used only between here
-        and the beginning of the current basic block.
-        (We also know that the last use before INSN was
-        the output reload we are thinking of deleting, but never mind that.)
-        Search that range; see if any ref remains.  */
+      /* We know that it was used only between here and the beginning of
+        the current basic block.  (We also know that the last use before
+        INSN was the output reload we are thinking of deleting, but never
+        mind that.)  Search that range; see if any ref remains.  */
       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
        {
          rtx set = single_set (i2);
@@ -7666,7 +7701,8 @@ delete_output_reload (insn, j, last_reload_reg)
            }
        }
 
-      /* Delete the now-dead stores into this pseudo.  */
+      /* Delete the now-dead stores into this pseudo.  Note that this
+        loop also takes care of deleting output_reload_insn.  */
       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
        {
          rtx set = single_set (i2);
@@ -7674,8 +7710,6 @@ delete_output_reload (insn, j, last_reload_reg)
          if (set != 0 && SET_DEST (set) == reg)
            {
              delete_address_reloads (i2, insn);
-             /* This might be a basic block head,
-                thus don't use delete_insn.  */
              delete_insn (i2);
            }
          if (GET_CODE (i2) == CODE_LABEL
@@ -7683,14 +7717,15 @@ delete_output_reload (insn, j, last_reload_reg)
            break;
        }
 
-      /* For the debugging info,
-        say the pseudo lives in this reload reg.  */
+      /* For the debugging info, say the pseudo lives in this reload reg.  */
       reg_renumber[REGNO (reg)] = REGNO (rld[j].reg_rtx);
       alter_reg (REGNO (reg), -1);
     }
-  delete_address_reloads (output_reload_insn, insn);
-  delete_insn (output_reload_insn);
-
+  else
+    {
+      delete_address_reloads (output_reload_insn, insn);
+      delete_insn (output_reload_insn);
+    }
 }
 
 /* We are going to delete DEAD_INSN.  Recursively delete loads of
@@ -8002,6 +8037,7 @@ static void
 reload_cse_delete_noop_set (insn, value)
      rtx insn, value;
 {
+  bool purge = BLOCK_FOR_INSN (insn)->end == insn;
   if (value)
     {
       PATTERN (insn) = gen_rtx_USE (VOIDmode, value);
@@ -8010,6 +8046,8 @@ reload_cse_delete_noop_set (insn, value)
     }
   else
     delete_insn (insn);
+  if (purge)
+    purge_dead_edges (BLOCK_FOR_INSN (insn));
 }
 
 /* See whether a single set SET is a noop.  */
@@ -8041,7 +8079,8 @@ reload_cse_simplify (insn)
       if (!count && reload_cse_noop_set_p (body))
        {
          rtx value = SET_DEST (body);
-         if (! REG_FUNCTION_VALUE_P (SET_DEST (body)))
+         if (GET_CODE (body) == REG
+             && ! REG_FUNCTION_VALUE_P (SET_DEST (body)))
            value = 0;
          reload_cse_delete_noop_set (insn, value);
          return;
@@ -8332,8 +8371,8 @@ reload_cse_simplify_operands (insn)
   alternative_reject = (int *) alloca (recog_data.n_alternatives * sizeof (int));
   alternative_nregs = (int *) alloca (recog_data.n_alternatives * sizeof (int));
   alternative_order = (int *) alloca (recog_data.n_alternatives * sizeof (int));
-  memset ((char *)alternative_reject, 0, recog_data.n_alternatives * sizeof (int));
-  memset ((char *)alternative_nregs, 0, recog_data.n_alternatives * sizeof (int));
+  memset ((char *) alternative_reject, 0, recog_data.n_alternatives * sizeof (int));
+  memset ((char *) alternative_nregs, 0, recog_data.n_alternatives * sizeof (int));
 
   /* For each operand, find out which regs are equivalent.  */
   for (i = 0; i < recog_data.n_operands; i++)
@@ -8436,7 +8475,7 @@ reload_cse_simplify_operands (insn)
 
                default:
                  class
-                   = reg_class_subunion[(int) class][(int) REG_CLASS_FROM_LETTER ((unsigned char)c)];
+                   = reg_class_subunion[(int) class][(int) REG_CLASS_FROM_LETTER ((unsigned char) c)];
                  break;
 
                case ',': case '\0':
@@ -8580,7 +8619,7 @@ reload_combine ()
   int min_labelno, n_labels;
   HARD_REG_SET ever_live_at_start, *label_live;
 
-  /* If reg+reg can be used in offsetable memory adresses, the main chunk of
+  /* If reg+reg can be used in offsetable memory addresses, the main chunk of
      reload has already used it where appropriate, so there is no use in
      trying to generate it now.  */
   if (double_reg_address_ok && INDEX_REG_CLASS != NO_REGS)
@@ -8754,7 +8793,9 @@ reload_combine ()
                   i < RELOAD_COMBINE_MAX_USES; i++)
                validate_change (reg_state[regno].reg_use[i].insn,
                                 reg_state[regno].reg_use[i].usep,
-                                reg_sum, 1);
+                                /* Each change must have its own
+                                   replacement.  */
+                                copy_rtx (reg_sum), 1);
 
              if (apply_change_group ())
                {
@@ -9446,7 +9487,7 @@ copy_eh_notes (insn, x)
    proper call and fix the damage.
  
    Similar handle instructions throwing exceptions internally.  */
-static void
+void
 fixup_abnormal_edges ()
 {
   int i;
@@ -9490,8 +9531,19 @@ fixup_abnormal_edges ()
              next = NEXT_INSN (insn);
              if (INSN_P (insn))
                {
-                 insert_insn_on_edge (PATTERN (insn), e);
+                 rtx seq;
+
                  delete_insn (insn);
+
+                 /* We're not deleting it, we're moving it.  */
+                 INSN_DELETED_P (insn) = 0;
+
+                 /* Emit a sequence, rather than scarfing the pattern, so
+                    that we don't lose REG_NOTES etc.  */
+                 /* ??? Could copy the test from gen_sequence, but don't
+                    think it's worth the bother.  */
+                 seq = gen_rtx_SEQUENCE (VOIDmode, gen_rtvec (1, insn));
+                 insert_insn_on_edge (seq, e);
                }
              insn = next;
            }