OSDN Git Service

* doc/install.texi (avr): Update required binutils version.
[pf3gnuchains/gcc-fork.git] / gcc / combine.c
index 7a5604f..ce97adf 100644 (file)
@@ -192,8 +192,8 @@ static HARD_REG_SET newpat_used_regs;
 
 static rtx added_links_insn;
 
-/* Basic block number of the block in which we are performing combines.  */
-static int this_basic_block;
+/* Basic block in which we are performing combines.  */
+static basic_block this_basic_block;
 
 /* A bitmap indicating which blocks had registers go dead at entry.
    After combine, we'll need to re-do global life analysis with
@@ -221,7 +221,7 @@ static int need_refresh;
                                register was assigned
    reg_last_set_table_tick     records the value of label_tick when a
                                value using the register is assigned
-   reg_last_set_invalid                set to non-zero when it is not valid
+   reg_last_set_invalid                set to nonzero when it is not valid
                                to use the value of this register in some
                                register's value
 
@@ -230,7 +230,7 @@ static int need_refresh;
    and the register being validly contained in some other expression in the
    table.
 
-   Entry I in reg_last_set_value is valid if it is non-zero, and either
+   Entry I in reg_last_set_value is valid if it is nonzero, and either
    reg_n_sets[i] is 1 or reg_last_set_label[i] == label_tick.
 
    Register I may validly appear in any expression returned for the value
@@ -242,7 +242,7 @@ static int need_refresh;
    not validly appear in an expression, the register is replaced by
    something that won't match, (clobber (const_int 0)).
 
-   reg_last_set_invalid[i] is set non-zero when register I is being assigned
+   reg_last_set_invalid[i] is set nonzero when register I is being assigned
    to and reg_last_set_table_tick[i] == label_tick.  */
 
 /* Record last value assigned to (hard or pseudo) register n.  */
@@ -259,7 +259,7 @@ static int *reg_last_set_label;
 
 static int *reg_last_set_table_tick;
 
-/* Set non-zero if references to register n in expressions should not be
+/* Set nonzero if references to register n in expressions should not be
    used.  */
 
 static char *reg_last_set_invalid;
@@ -314,8 +314,8 @@ struct undo
 {
   struct undo *next;
   int is_int;
-  union {rtx r; unsigned int i;} old_contents;
-  union {rtx *r; unsigned int *i;} where;
+  union {rtx r; int i;} old_contents;
+  union {rtx *r; int *i;} where;
 };
 
 /* Record a bunch of changes to be undone, up to MAX_UNDO of them.
@@ -339,8 +339,7 @@ static struct undobuf undobuf;
 static int n_occurrences;
 
 static void do_SUBST                   PARAMS ((rtx *, rtx));
-static void do_SUBST_INT               PARAMS ((unsigned int *,
-                                                unsigned int));
+static void do_SUBST_INT               PARAMS ((int *, int));
 static void init_reg_last_arrays       PARAMS ((void));
 static void setup_incoming_promotions   PARAMS ((void));
 static void set_nonzero_bits_and_sign_copies  PARAMS ((rtx, rtx, void *));
@@ -472,10 +471,10 @@ do_SUBST (into, newval)
 
 static void
 do_SUBST_INT (into, newval)
-     unsigned int *into, newval;
+     int *into, newval;
 {
   struct undo *buf;
-  unsigned int oldval = *into;
+  int oldval = *into;
 
   if (oldval == newval)
     return;
@@ -498,7 +497,7 @@ do_SUBST_INT (into, newval)
 /* Main entry point for combiner.  F is the first insn of the function.
    NREGS is the first unused pseudo-reg number.
 
-   Return non-zero if the combiner has turned an indirect jump
+   Return nonzero if the combiner has turned an indirect jump
    instruction into a direct jump.  */
 int
 combine_instructions (f, nregs)
@@ -578,7 +577,7 @@ combine_instructions (f, nregs)
 
   setup_incoming_promotions ();
 
-  refresh_blocks = sbitmap_alloc (n_basic_blocks);
+  refresh_blocks = sbitmap_alloc (last_basic_block);
   sbitmap_zero (refresh_blocks);
   need_refresh = 0;
 
@@ -610,139 +609,138 @@ combine_instructions (f, nregs)
 
   /* Now scan all the insns in forward order.  */
 
-  this_basic_block = -1;
   label_tick = 1;
   last_call_cuid = 0;
   mem_last_set = 0;
   init_reg_last_arrays ();
   setup_incoming_promotions ();
 
-  for (insn = f; insn; insn = next ? next : NEXT_INSN (insn))
+  FOR_EACH_BB (this_basic_block)
     {
-      next = 0;
-
-      /* If INSN starts a new basic block, update our basic block number.  */
-      if (this_basic_block + 1 < n_basic_blocks
-         && BLOCK_HEAD (this_basic_block + 1) == insn)
-       this_basic_block++;
-
-      if (GET_CODE (insn) == CODE_LABEL)
-       label_tick++;
-
-      else if (INSN_P (insn))
+      for (insn = this_basic_block->head;
+           insn != NEXT_INSN (this_basic_block->end);
+          insn = next ? next : NEXT_INSN (insn))
        {
-         /* See if we know about function return values before this
-            insn based upon SUBREG flags.  */
-         check_promoted_subreg (insn, PATTERN (insn));
-
-         /* Try this insn with each insn it links back to.  */
+         next = 0;
 
-         for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
-           if ((next = try_combine (insn, XEXP (links, 0),
-                                    NULL_RTX, &new_direct_jump_p)) != 0)
-             goto retry;
+         if (GET_CODE (insn) == CODE_LABEL)
+           label_tick++;
 
-         /* Try each sequence of three linked insns ending with this one.  */
-
-         for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
+         else if (INSN_P (insn))
            {
-             rtx link = XEXP (links, 0);
+             /* See if we know about function return values before this
+                insn based upon SUBREG flags.  */
+             check_promoted_subreg (insn, PATTERN (insn));
 
-             /* If the linked insn has been replaced by a note, then there
-                is no point in pursuing this chain any further.  */
-             if (GET_CODE (link) == NOTE)
-               continue;
+             /* Try this insn with each insn it links back to.  */
 
-             for (nextlinks = LOG_LINKS (link);
-                  nextlinks;
-                  nextlinks = XEXP (nextlinks, 1))
-               if ((next = try_combine (insn, link,
-                                        XEXP (nextlinks, 0),
-                                        &new_direct_jump_p)) != 0)
+             for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
+               if ((next = try_combine (insn, XEXP (links, 0),
+                                        NULL_RTX, &new_direct_jump_p)) != 0)
                  goto retry;
-           }
+
+             /* Try each sequence of three linked insns ending with this one.  */
+
+             for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
+               {
+                 rtx link = XEXP (links, 0);
+
+                 /* If the linked insn has been replaced by a note, then there
+                    is no point in pursuing this chain any further.  */
+                 if (GET_CODE (link) == NOTE)
+                   continue;
+
+                 for (nextlinks = LOG_LINKS (link);
+                      nextlinks;
+                      nextlinks = XEXP (nextlinks, 1))
+                   if ((next = try_combine (insn, link,
+                                            XEXP (nextlinks, 0),
+                                            &new_direct_jump_p)) != 0)
+                     goto retry;
+               }
 
 #ifdef HAVE_cc0
-         /* Try to combine a jump insn that uses CC0
-            with a preceding insn that sets CC0, and maybe with its
-            logical predecessor as well.
-            This is how we make decrement-and-branch insns.
-            We need this special code because data flow connections
-            via CC0 do not get entered in LOG_LINKS.  */
-
-         if (GET_CODE (insn) == JUMP_INSN
-             && (prev = prev_nonnote_insn (insn)) != 0
-             && GET_CODE (prev) == INSN
-             && sets_cc0_p (PATTERN (prev)))
-           {
-             if ((next = try_combine (insn, prev,
-                                      NULL_RTX, &new_direct_jump_p)) != 0)
-               goto retry;
-
-             for (nextlinks = LOG_LINKS (prev); nextlinks;
-                  nextlinks = XEXP (nextlinks, 1))
-               if ((next = try_combine (insn, prev,
-                                        XEXP (nextlinks, 0),
-                                        &new_direct_jump_p)) != 0)
-                 goto retry;
-           }
+             /* Try to combine a jump insn that uses CC0
+                with a preceding insn that sets CC0, and maybe with its
+                logical predecessor as well.
+                This is how we make decrement-and-branch insns.
+                We need this special code because data flow connections
+                via CC0 do not get entered in LOG_LINKS.  */
+
+             if (GET_CODE (insn) == JUMP_INSN
+                 && (prev = prev_nonnote_insn (insn)) != 0
+                 && GET_CODE (prev) == INSN
+                 && sets_cc0_p (PATTERN (prev)))
+               {
+                 if ((next = try_combine (insn, prev,
+                                          NULL_RTX, &new_direct_jump_p)) != 0)
+                   goto retry;
+
+                 for (nextlinks = LOG_LINKS (prev); nextlinks;
+                      nextlinks = XEXP (nextlinks, 1))
+                   if ((next = try_combine (insn, prev,
+                                            XEXP (nextlinks, 0),
+                                            &new_direct_jump_p)) != 0)
+                     goto retry;
+               }
 
-         /* Do the same for an insn that explicitly references CC0.  */
-         if (GET_CODE (insn) == INSN
-             && (prev = prev_nonnote_insn (insn)) != 0
-             && GET_CODE (prev) == INSN
-             && sets_cc0_p (PATTERN (prev))
-             && GET_CODE (PATTERN (insn)) == SET
-             && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (insn))))
-           {
-             if ((next = try_combine (insn, prev,
-                                      NULL_RTX, &new_direct_jump_p)) != 0)
-               goto retry;
+             /* Do the same for an insn that explicitly references CC0.  */
+             if (GET_CODE (insn) == INSN
+                 && (prev = prev_nonnote_insn (insn)) != 0
+                 && GET_CODE (prev) == INSN
+                 && sets_cc0_p (PATTERN (prev))
+                 && GET_CODE (PATTERN (insn)) == SET
+                 && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (insn))))
+               {
+                 if ((next = try_combine (insn, prev,
+                                          NULL_RTX, &new_direct_jump_p)) != 0)
+                   goto retry;
+
+                 for (nextlinks = LOG_LINKS (prev); nextlinks;
+                      nextlinks = XEXP (nextlinks, 1))
+                   if ((next = try_combine (insn, prev,
+                                            XEXP (nextlinks, 0),
+                                            &new_direct_jump_p)) != 0)
+                     goto retry;
+               }
 
-             for (nextlinks = LOG_LINKS (prev); nextlinks;
-                  nextlinks = XEXP (nextlinks, 1))
-               if ((next = try_combine (insn, prev,
-                                        XEXP (nextlinks, 0),
-                                        &new_direct_jump_p)) != 0)
+             /* Finally, see if any of the insns that this insn links to
+                explicitly references CC0.  If so, try this insn, that insn,
+                and its predecessor if it sets CC0.  */
+             for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
+               if (GET_CODE (XEXP (links, 0)) == INSN
+                   && GET_CODE (PATTERN (XEXP (links, 0))) == SET
+                   && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (XEXP (links, 0))))
+                   && (prev = prev_nonnote_insn (XEXP (links, 0))) != 0
+                   && GET_CODE (prev) == INSN
+                   && sets_cc0_p (PATTERN (prev))
+                   && (next = try_combine (insn, XEXP (links, 0),
+                                           prev, &new_direct_jump_p)) != 0)
                  goto retry;
-           }
-
-         /* Finally, see if any of the insns that this insn links to
-            explicitly references CC0.  If so, try this insn, that insn,
-            and its predecessor if it sets CC0.  */
-         for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
-           if (GET_CODE (XEXP (links, 0)) == INSN
-               && GET_CODE (PATTERN (XEXP (links, 0))) == SET
-               && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (XEXP (links, 0))))
-               && (prev = prev_nonnote_insn (XEXP (links, 0))) != 0
-               && GET_CODE (prev) == INSN
-               && sets_cc0_p (PATTERN (prev))
-               && (next = try_combine (insn, XEXP (links, 0),
-                                       prev, &new_direct_jump_p)) != 0)
-             goto retry;
 #endif
 
-         /* Try combining an insn with two different insns whose results it
-            uses.  */
-         for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
-           for (nextlinks = XEXP (links, 1); nextlinks;
-                nextlinks = XEXP (nextlinks, 1))
-             if ((next = try_combine (insn, XEXP (links, 0),
-                                      XEXP (nextlinks, 0),
-                                      &new_direct_jump_p)) != 0)
-               goto retry;
+             /* Try combining an insn with two different insns whose results it
+                uses.  */
+             for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
+               for (nextlinks = XEXP (links, 1); nextlinks;
+                    nextlinks = XEXP (nextlinks, 1))
+                 if ((next = try_combine (insn, XEXP (links, 0),
+                                          XEXP (nextlinks, 0),
+                                          &new_direct_jump_p)) != 0)
+                   goto retry;
 
-         if (GET_CODE (insn) != NOTE)
-           record_dead_and_set_regs (insn);
+             if (GET_CODE (insn) != NOTE)
+               record_dead_and_set_regs (insn);
 
-       retry:
-         ;
+           retry:
+             ;
+           }
        }
     }
   clear_bb_flags ();
 
-  EXECUTE_IF_SET_IN_SBITMAP (refresh_blocks, 0, this_basic_block,
-                            BASIC_BLOCK (this_basic_block)->flags |= BB_DIRTY);
+  EXECUTE_IF_SET_IN_SBITMAP (refresh_blocks, 0, i,
+                            BASIC_BLOCK (i)->flags |= BB_DIRTY);
   new_direct_jump_p |= purge_all_dead_edges (0);
   delete_noop_moves (f);
 
@@ -860,7 +858,7 @@ set_nonzero_bits_and_sign_copies (x, set, data)
       && REGNO (x) >= FIRST_PSEUDO_REGISTER
       /* If this register is undefined at the start of the file, we can't
         say what its contents were.  */
-      && ! REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start, REGNO (x))
+      && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR->next_bb->global_live_at_start, REGNO (x))
       && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT)
     {
       if (set == 0 || GET_CODE (set) == CLOBBER)
@@ -1287,13 +1285,13 @@ sets_function_arg_p (pat)
    case, we would be getting the wrong value of I2DEST into I3, so we
    must reject the combination.  This case occurs when I2 and I1 both
    feed into I3, rather than when I1 feeds into I2, which feeds into I3.
-   If I1_NOT_IN_SRC is non-zero, it means that finding I1 in the source
+   If I1_NOT_IN_SRC is nonzero, it means that finding I1 in the source
    of a SET must prevent combination from occurring.
 
    Before doing the above check, we first try to expand a field assignment
    into a set of logical operations.
 
-   If PI3_DEST_KILLED is non-zero, it is a pointer to a location in which
+   If PI3_DEST_KILLED is nonzero, it is a pointer to a location in which
    we place a register that is both set and used within I3.  If more than one
    such register is detected, we fail.
 
@@ -1460,10 +1458,10 @@ cant_combine_insn_p (insn)
   if (! INSN_P (insn))
     return 1;
 
-  /* Never combine loads and stores involving hard regs that are likely
-     to be spilled.  The register allocator can usually handle such
-     reg-reg moves by tying.  If we allow the combiner to make 
-     substitutions of likely-spilled regs, we may abort in reload.
+  /* Never combine loads and stores involving hard regs.  The register
+     allocator can usually handle such reg-reg moves by tying.  If we allow
+     the combiner to make substitutions of hard regs, we risk aborting in
+     reload on machines that have SMALL_REGISTER_CLASSES.
      As an exception, we allow combinations involving fixed regs; these are
      not available to the register allocator so there's no risk involved.  */
 
@@ -1478,11 +1476,9 @@ cant_combine_insn_p (insn)
     dest = SUBREG_REG (dest);
   if (REG_P (src) && REG_P (dest)
       && ((REGNO (src) < FIRST_PSEUDO_REGISTER
-          && ! fixed_regs[REGNO (src)]
-          && CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (REGNO (src))))
+          && ! fixed_regs[REGNO (src)])
          || (REGNO (dest) < FIRST_PSEUDO_REGISTER
-             && ! fixed_regs[REGNO (dest)]
-             && CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (REGNO (dest))))))
+             && ! fixed_regs[REGNO (dest)])))
     return 1;
 
   return 0;
@@ -1501,7 +1497,7 @@ cant_combine_insn_p (insn)
    If we did the combination, return the insn at which combine should
    resume scanning.
 
-   Set NEW_DIRECT_JUMP_P to a non-zero value if try_combine creates a
+   Set NEW_DIRECT_JUMP_P to a nonzero value if try_combine creates a
    new direct jump instruction.  */
 
 static rtx
@@ -1758,6 +1754,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 
          subst_prev_insn = i1
            = gen_rtx_INSN (VOIDmode, INSN_UID (i2), NULL_RTX, i2,
+                           BLOCK_FOR_INSN (i2), INSN_SCOPE (i2),
                            XVECEXP (PATTERN (i2), 0, 1), -1, NULL_RTX,
                            NULL_RTX);
 
@@ -2169,30 +2166,23 @@ try_combine (i3, i2, i1, new_direct_jump_p)
            }
        }
 
-      /* If we've split a jump pattern, we'll wind up with a sequence even
-        with one instruction.  We can handle that below, so extract it.  */
-      if (m_split && GET_CODE (m_split) == SEQUENCE
-         && XVECLEN (m_split, 0) == 1)
-       m_split = PATTERN (XVECEXP (m_split, 0, 0));
-
-      if (m_split && GET_CODE (m_split) != SEQUENCE)
+      if (m_split && NEXT_INSN (m_split) == NULL_RTX)
        {
+         m_split = PATTERN (m_split);
          insn_code_number = recog_for_combine (&m_split, i3, &new_i3_notes);
          if (insn_code_number >= 0)
            newpat = m_split;
        }
-      else if (m_split && GET_CODE (m_split) == SEQUENCE
-              && XVECLEN (m_split, 0) == 2
+      else if (m_split && NEXT_INSN (NEXT_INSN (m_split)) == NULL_RTX
               && (next_real_insn (i2) == i3
-                  || ! use_crosses_set_p (PATTERN (XVECEXP (m_split, 0, 0)),
-                                          INSN_CUID (i2))))
+                  || ! use_crosses_set_p (PATTERN (m_split), INSN_CUID (i2))))
        {
          rtx i2set, i3set;
-         rtx newi3pat = PATTERN (XVECEXP (m_split, 0, 1));
-         newi2pat = PATTERN (XVECEXP (m_split, 0, 0));
+         rtx newi3pat = PATTERN (NEXT_INSN (m_split));
+         newi2pat = PATTERN (m_split);
 
-         i3set = single_set (XVECEXP (m_split, 0, 1));
-         i2set = single_set (XVECEXP (m_split, 0, 0));
+         i3set = single_set (NEXT_INSN (m_split));
+         i2set = single_set (m_split);
 
          /* In case we changed the mode of I2DEST, replace it in the
             pseudo-register table here.  We can't do it above in case this
@@ -2293,8 +2283,19 @@ try_combine (i3, i2, i1, new_direct_jump_p)
          /* If *SPLIT is a paradoxical SUBREG, when we split it, it should
             be written as a ZERO_EXTEND.  */
          if (split_code == SUBREG && GET_CODE (SUBREG_REG (*split)) == MEM)
-           SUBST (*split, gen_rtx_ZERO_EXTEND  (split_mode,
-                                                SUBREG_REG (*split)));
+           {
+#ifdef LOAD_EXTEND_OP
+             /* Or as a SIGN_EXTEND if LOAD_EXTEND_OP says that that's
+                what it really is.  */
+             if (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (*split)))
+                 == SIGN_EXTEND)
+               SUBST (*split, gen_rtx_SIGN_EXTEND (split_mode,
+                                                   SUBREG_REG (*split)));
+             else
+#endif
+               SUBST (*split, gen_rtx_ZERO_EXTEND (split_mode,
+                                                   SUBREG_REG (*split)));
+           }
 #endif
 
          newi2pat = gen_rtx_SET (VOIDmode, newdest, *split);
@@ -2315,6 +2316,10 @@ try_combine (i3, i2, i1, new_direct_jump_p)
      copy.  This saves at least one insn, more if register allocation can
      eliminate the copy.
 
+     We cannot do this if the destination of the first assignment is a
+     condition code register or cc0.  We eliminate this case by making sure
+     the SET_DEST and SET_SRC have the same mode.
+
      We cannot do this if the destination of the second assignment is
      a register that we have already assumed is zero-extended.  Similarly
      for a SUBREG of such a register.  */
@@ -2324,6 +2329,8 @@ try_combine (i3, i2, i1, new_direct_jump_p)
           && XVECLEN (newpat, 0) == 2
           && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
           && GET_CODE (SET_SRC (XVECEXP (newpat, 0, 0))) == SIGN_EXTEND
+          && (GET_MODE (SET_DEST (XVECEXP (newpat, 0, 0)))
+              == GET_MODE (SET_SRC (XVECEXP (newpat, 0, 0))))
           && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
           && rtx_equal_p (SET_SRC (XVECEXP (newpat, 0, 1)),
                           XEXP (SET_SRC (XVECEXP (newpat, 0, 0)), 0))
@@ -2390,8 +2397,8 @@ try_combine (i3, i2, i1, new_direct_jump_p)
             which we know will be a NOTE.  */
 
          for (insn = NEXT_INSN (i3);
-              insn && (this_basic_block == n_basic_blocks - 1
-                       || insn != BLOCK_HEAD (this_basic_block + 1));
+              insn && (this_basic_block->next_bb == EXIT_BLOCK_PTR
+                       || insn != this_basic_block->next_bb->head);
               insn = NEXT_INSN (insn))
            {
              if (INSN_P (insn) && reg_referenced_p (ni2dest, PATTERN (insn)))
@@ -2608,8 +2615,8 @@ try_combine (i3, i2, i1, new_direct_jump_p)
              && ! find_reg_note (i2, REG_UNUSED,
                                  SET_DEST (XVECEXP (PATTERN (i2), 0, i))))
            for (temp = NEXT_INSN (i2);
-                temp && (this_basic_block == n_basic_blocks - 1
-                         || BLOCK_HEAD (this_basic_block) != temp);
+                temp && (this_basic_block->next_bb == EXIT_BLOCK_PTR
+                         || this_basic_block->head != temp);
                 temp = NEXT_INSN (temp))
              if (temp != i3 && INSN_P (temp))
                for (link = LOG_LINKS (temp); link; link = XEXP (link, 1))
@@ -2822,7 +2829,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
        BARRIER following it since it may have initially been a
        conditional jump.  It may also be the last nonnote insn.  */
 
-    if (GET_CODE (newpat) == RETURN || any_uncondjump_p (i3))
+    if (returnjump_p (i3) || any_uncondjump_p (i3))
       {
        *new_direct_jump_p = 1;
 
@@ -2830,6 +2837,18 @@ try_combine (i3, i2, i1, new_direct_jump_p)
            || GET_CODE (temp) != BARRIER)
          emit_barrier_after (i3);
       }
+
+    if (undobuf.other_insn != NULL_RTX
+       && (returnjump_p (undobuf.other_insn)
+           || any_uncondjump_p (undobuf.other_insn)))
+      {
+       *new_direct_jump_p = 1;
+
+       if ((temp = next_nonnote_insn (undobuf.other_insn)) == NULL_RTX
+           || GET_CODE (temp) != BARRIER)
+         emit_barrier_after (undobuf.other_insn);
+      }
+       
     /* An NOOP jump does not need barrier, but it does need cleaning up
        of CFG.  */
     if (GET_CODE (newpat) == SET
@@ -2962,20 +2981,22 @@ find_split_point (loc, insn)
             we can make put both sources together and make a split point
             in the middle.  */
 
-         if (seq && XVECLEN (seq, 0) == 2
-             && GET_CODE (XVECEXP (seq, 0, 0)) == INSN
-             && GET_CODE (PATTERN (XVECEXP (seq, 0, 0))) == SET
-             && SET_DEST (PATTERN (XVECEXP (seq, 0, 0))) == reg
+         if (seq
+             && NEXT_INSN (seq) != NULL_RTX
+             && NEXT_INSN (NEXT_INSN (seq)) == NULL_RTX
+             && GET_CODE (seq) == INSN
+             && GET_CODE (PATTERN (seq)) == SET
+             && SET_DEST (PATTERN (seq)) == reg
              && ! reg_mentioned_p (reg,
-                                   SET_SRC (PATTERN (XVECEXP (seq, 0, 0))))
-             && GET_CODE (XVECEXP (seq, 0, 1)) == INSN
-             && GET_CODE (PATTERN (XVECEXP (seq, 0, 1))) == SET
-             && SET_DEST (PATTERN (XVECEXP (seq, 0, 1))) == reg
+                                   SET_SRC (PATTERN (seq)))
+             && GET_CODE (NEXT_INSN (seq)) == INSN
+             && GET_CODE (PATTERN (NEXT_INSN (seq))) == SET
+             && SET_DEST (PATTERN (NEXT_INSN (seq))) == reg
              && memory_address_p (GET_MODE (x),
-                                  SET_SRC (PATTERN (XVECEXP (seq, 0, 1)))))
+                                  SET_SRC (PATTERN (NEXT_INSN (seq)))))
            {
-             rtx src1 = SET_SRC (PATTERN (XVECEXP (seq, 0, 0)));
-             rtx src2 = SET_SRC (PATTERN (XVECEXP (seq, 0, 1)));
+             rtx src1 = SET_SRC (PATTERN (seq));
+             rtx src2 = SET_SRC (PATTERN (NEXT_INSN (seq)));
 
              /* Replace the placeholder in SRC2 with SRC1.  If we can
                 find where in SRC2 it was placed, that can become our
@@ -3086,7 +3107,7 @@ find_split_point (loc, insn)
        case AND:
          /* If we are AND'ing with a large constant that is only a single
             bit and the result is only being used in a context where we
-            need to know if it is zero or non-zero, replace it with a bit
+            need to know if it is zero or nonzero, replace it with a bit
             extraction.  This will avoid the large constant, which might
             have taken more than one insn to make.  If the constant were
             not a valid argument to the AND but took only one insn to make,
@@ -3314,10 +3335,10 @@ find_split_point (loc, insn)
 
    `n_occurrences' is incremented each time FROM is replaced.
 
-   IN_DEST is non-zero if we are processing the SET_DEST of a SET.
+   IN_DEST is nonzero if we are processing the SET_DEST of a SET.
 
-   UNIQUE_COPY is non-zero if each substitution must be unique.  We do this
-   by copying if `n_occurrences' is non-zero.  */
+   UNIQUE_COPY is nonzero if each substitution must be unique.  We do this
+   by copying if `n_occurrences' is nonzero.  */
 
 static rtx
 subst (x, from, to, in_dest, unique_copy)
@@ -3540,14 +3561,13 @@ subst (x, from, to, in_dest, unique_copy)
 
              if (GET_CODE (new) == CONST_INT && GET_CODE (x) == SUBREG)
                {
-                 if (VECTOR_MODE_P (GET_MODE (x)))
-                   return gen_rtx_CLOBBER (VOIDmode, const0_rtx);
+                 enum machine_mode mode = GET_MODE (x);
 
                  x = simplify_subreg (GET_MODE (x), new,
                                       GET_MODE (SUBREG_REG (x)),
                                       SUBREG_BYTE (x));
                  if (! x)
-                   abort ();
+                   x = gen_rtx_CLOBBER (mode, const0_rtx);
                }
              else if (GET_CODE (new) == CONST_INT
                       && GET_CODE (x) == ZERO_EXTEND)
@@ -3868,7 +3888,12 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 
       /* simplify_subreg can't use gen_lowpart_for_combine.  */
       if (CONSTANT_P (SUBREG_REG (x))
-         && subreg_lowpart_offset (mode, op0_mode) == SUBREG_BYTE (x))
+         && subreg_lowpart_offset (mode, op0_mode) == SUBREG_BYTE (x)
+            /* Don't call gen_lowpart_for_combine if the inner mode
+               is VOIDmode and we cannot simplify it, as SUBREG without
+               inner mode is invalid.  */
+         && (GET_MODE (SUBREG_REG (x)) != VOIDmode
+             || gen_lowpart_common (mode, SUBREG_REG (x))))
        return gen_lowpart_for_combine (mode, SUBREG_REG (x));
 
       if (GET_MODE_CLASS (GET_MODE (SUBREG_REG (x))) == MODE_CC)
@@ -4108,7 +4133,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
       if (TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
                                 GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))))
          && num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0)))
-            >= GET_MODE_BITSIZE (mode) + 1
+            >= (unsigned int) (GET_MODE_BITSIZE (mode) + 1)
          && ! (GET_CODE (XEXP (x, 0)) == LSHIFTRT
                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT))
        return gen_lowpart_for_combine (mode, XEXP (x, 0));
@@ -4586,7 +4611,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 #ifdef SHIFT_COUNT_TRUNCATED
       else if (SHIFT_COUNT_TRUNCATED && GET_CODE (XEXP (x, 1)) != REG)
        SUBST (XEXP (x, 1),
-              force_to_mode (XEXP (x, 1), GET_MODE (x),
+              force_to_mode (XEXP (x, 1), GET_MODE (XEXP (x, 1)),
                              ((HOST_WIDE_INT) 1
                               << exact_log2 (GET_MODE_BITSIZE (GET_MODE (x))))
                              - 1,
@@ -4768,12 +4793,12 @@ simplify_if_then_else (x)
 
   /* Convert a == b ? b : a to "a".  */
   if (true_code == EQ && ! side_effects_p (cond)
-      && (! FLOAT_MODE_P (mode) || flag_unsafe_math_optimizations)
+      && !HONOR_NANS (mode)
       && rtx_equal_p (XEXP (cond, 0), false_rtx)
       && rtx_equal_p (XEXP (cond, 1), true_rtx))
     return false_rtx;
   else if (true_code == NE && ! side_effects_p (cond)
-          && (! FLOAT_MODE_P (mode) || flag_unsafe_math_optimizations)
+          && !HONOR_NANS (mode)
           && rtx_equal_p (XEXP (cond, 0), true_rtx)
           && rtx_equal_p (XEXP (cond, 1), false_rtx))
     return true_rtx;
@@ -4869,7 +4894,8 @@ simplify_if_then_else (x)
               && subreg_lowpart_p (XEXP (XEXP (t, 0), 0))
               && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 0)), f)
               && (num_sign_bit_copies (f, GET_MODE (f))
-                  > (GET_MODE_BITSIZE (mode)
+                  > (unsigned int)
+                    (GET_MODE_BITSIZE (mode)
                      - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 0))))))
        {
          c1 = XEXP (XEXP (t, 0), 1); z = f; op = GET_CODE (XEXP (t, 0));
@@ -4884,7 +4910,8 @@ simplify_if_then_else (x)
               && subreg_lowpart_p (XEXP (XEXP (t, 0), 1))
               && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 1)), f)
               && (num_sign_bit_copies (f, GET_MODE (f))
-                  > (GET_MODE_BITSIZE (mode)
+                  > (unsigned int)
+                    (GET_MODE_BITSIZE (mode)
                      - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 1))))))
        {
          c1 = XEXP (XEXP (t, 0), 0); z = f; op = GET_CODE (XEXP (t, 0));
@@ -4984,7 +5011,8 @@ simplify_set (x)
      simplify the expression for the object knowing that we only need the
      low-order bits.  */
 
-  if (GET_MODE_CLASS (mode) == MODE_INT)
+  if (GET_MODE_CLASS (mode) == MODE_INT
+      && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
     {
       src = force_to_mode (src, mode, ~(HOST_WIDE_INT) 0, NULL_RTX, 0);
       SUBST (SET_SRC (x), src);
@@ -4993,11 +5021,9 @@ simplify_set (x)
   /* If we are setting CC0 or if the source is a COMPARE, look for the use of
      the comparison result and try to simplify it unless we already have used
      undobuf.other_insn.  */
-  if ((GET_CODE (src) == COMPARE
-#ifdef HAVE_cc0
-       || dest == cc0_rtx
-#endif
-       )
+  if ((GET_MODE_CLASS (mode) == MODE_CC
+       || GET_CODE (src) == COMPARE
+       || CC0_P (dest))
       && (cc_use = find_single_use (dest, subst_insn, &other_insn)) != 0
       && (undobuf.other_insn == 0 || other_insn == undobuf.other_insn)
       && GET_RTX_CLASS (GET_CODE (*cc_use)) == '<'
@@ -5005,15 +5031,44 @@ simplify_set (x)
     {
       enum rtx_code old_code = GET_CODE (*cc_use);
       enum rtx_code new_code;
-      rtx op0, op1;
+      rtx op0, op1, tmp;
       int other_changed = 0;
       enum machine_mode compare_mode = GET_MODE (dest);
+      enum machine_mode tmp_mode;
 
       if (GET_CODE (src) == COMPARE)
        op0 = XEXP (src, 0), op1 = XEXP (src, 1);
       else
        op0 = src, op1 = const0_rtx;
 
+      /* Check whether the comparison is known at compile time.  */
+      if (GET_MODE (op0) != VOIDmode)
+       tmp_mode = GET_MODE (op0);
+      else if (GET_MODE (op1) != VOIDmode)
+       tmp_mode = GET_MODE (op1);
+      else
+       tmp_mode = compare_mode;
+      tmp = simplify_relational_operation (old_code, tmp_mode, op0, op1);
+      if (tmp != NULL_RTX)
+       {
+         rtx pat = PATTERN (other_insn);
+         undobuf.other_insn = other_insn;
+         SUBST (*cc_use, tmp);
+
+         /* Attempt to simplify CC user.  */
+         if (GET_CODE (pat) == SET)
+           {
+             rtx new = simplify_rtx (SET_SRC (pat));
+             if (new != NULL_RTX)
+               SUBST (SET_SRC (pat), new);
+           }
+
+         /* Convert X into a no-op move.  */
+         SUBST (SET_DEST (x), pc_rtx);
+         SUBST (SET_SRC (x), pc_rtx);
+         return x;
+       }
+
       /* Simplify our comparison, if possible.  */
       new_code = simplify_comparison (old_code, &op0, &op1);
 
@@ -5163,6 +5218,30 @@ simplify_set (x)
       src = SET_SRC (x), dest = SET_DEST (x);
     }
 
+#ifdef HAVE_cc0
+  /* If we have (set (cc0) (subreg ...)), we try to remove the subreg
+     in SRC.  */
+  if (dest == cc0_rtx
+      && GET_CODE (src) == SUBREG
+      && subreg_lowpart_p (src)
+      && (GET_MODE_BITSIZE (GET_MODE (src))
+         < GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (src)))))
+    {
+      rtx inner = SUBREG_REG (src);
+      enum machine_mode inner_mode = GET_MODE (inner);
+
+      /* Here we make sure that we don't have a sign bit on.  */
+      if (GET_MODE_BITSIZE (inner_mode) <= HOST_BITS_PER_WIDE_INT
+         && (nonzero_bits (inner, inner_mode)
+             < ((unsigned HOST_WIDE_INT) 1
+                << (GET_MODE_BITSIZE (GET_MODE (src)) - 1))))
+       {
+         SUBST (SET_SRC (x), inner);
+         src = SET_SRC (x);
+       }
+    }
+#endif
+
 #ifdef LOAD_EXTEND_OP
   /* If we have (set FOO (subreg:M (mem:N BAR) 0)) with M wider than N, this
      would require a paradoxical subreg.  Replace the subreg with a
@@ -5601,6 +5680,12 @@ expand_compound_operation (x)
       if (GET_MODE_SIZE (GET_MODE (XEXP (x, 0))) > UNITS_PER_WORD)
        return x;
 
+      /* Reject MODEs that aren't scalar integers because turning vector
+        or complex modes into shifts causes problems.  */
+
+      if (! SCALAR_INT_MODE_P (GET_MODE (XEXP (x, 0))))
+       return x;
+
       len = GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)));
       /* If the inner object has VOIDmode (the only way this can happen
         is if it is an ASM_OPERANDS), we can't do anything since we don't
@@ -5622,6 +5707,12 @@ expand_compound_operation (x)
          || GET_MODE (XEXP (x, 0)) == VOIDmode)
        return x;
 
+      /* Reject MODEs that aren't scalar integers because turning vector
+        or complex modes into shifts causes problems.  */
+
+      if (! SCALAR_INT_MODE_P (GET_MODE (XEXP (x, 0))))
+       return x;
+
       len = INTVAL (XEXP (x, 1));
       pos = INTVAL (XEXP (x, 2));
 
@@ -5829,12 +5920,12 @@ expand_field_assignment (x)
 
       compute_mode = GET_MODE (inner);
 
-      /* Don't attempt bitwise arithmetic on non-integral modes.  */
-      if (! INTEGRAL_MODE_P (compute_mode))
+      /* Don't attempt bitwise arithmetic on non scalar integer modes.  */
+      if (! SCALAR_INT_MODE_P (compute_mode))
        {
          enum machine_mode imode;
 
-         /* Something is probably seriously wrong if this matches.  */
+         /* Don't do anything for vector or complex integral types.  */
          if (! FLOAT_MODE_P (compute_mode))
            break;
 
@@ -5888,15 +5979,15 @@ expand_field_assignment (x)
    code that understands the USE is this routine.  If it is not removed,
    it will cause the resulting insn not to match.
 
-   UNSIGNEDP is non-zero for an unsigned reference and zero for a
+   UNSIGNEDP is nonzero for an unsigned reference and zero for a
    signed reference.
 
-   IN_DEST is non-zero if this is a reference in the destination of a
-   SET.  This is used when a ZERO_ or SIGN_EXTRACT isn't needed.  If non-zero,
+   IN_DEST is nonzero if this is a reference in the destination of a
+   SET.  This is used when a ZERO_ or SIGN_EXTRACT isn't needed.  If nonzero,
    a STRICT_LOW_PART will be used, if zero, ZERO_EXTEND or SIGN_EXTEND will
    be used.
 
-   IN_COMPARE is non-zero if we are in a COMPARE.  This means that a
+   IN_COMPARE is nonzero if we are in a COMPARE.  This means that a
    ZERO_EXTRACT should be built even for bits starting at bit 0.
 
    MODE is the desired mode of the result (if IN_DEST == 0).
@@ -5947,6 +6038,21 @@ make_extraction (mode, inner, pos, pos_rtx, len,
        is_mode = GET_MODE (SUBREG_REG (inner));
       inner = SUBREG_REG (inner);
     }
+  else if (GET_CODE (inner) == ASHIFT
+          && GET_CODE (XEXP (inner, 1)) == CONST_INT
+          && pos_rtx == 0 && pos == 0
+          && len > (unsigned HOST_WIDE_INT) INTVAL (XEXP (inner, 1)))
+    {
+      /* We're extracting the least significant bits of an rtx
+        (ashift X (const_int C)), where LEN > C.  Extract the
+        least significant (LEN - C) bits of X, giving an rtx
+        whose mode is MODE, then shift it left C times.  */
+      new = make_extraction (mode, XEXP (inner, 0),
+                            0, 0, len - INTVAL (XEXP (inner, 1)),
+                            unsignedp, in_dest, in_compare);
+      if (new != 0)
+       return gen_rtx_ASHIFT (mode, new, XEXP (inner, 1));
+    }
 
   inner_mode = GET_MODE (inner);
 
@@ -6023,6 +6129,11 @@ make_extraction (mode, inner, pos, pos_rtx, len,
                final_word += (GET_MODE_SIZE (inner_mode)
                               - GET_MODE_SIZE (tmode)) % UNITS_PER_WORD;
 
+             /* Avoid creating invalid subregs, for example when
+                simplifying (x>>32)&255.  */
+             if (final_word >= GET_MODE_SIZE (inner_mode))
+               return NULL_RTX;
+
              new = gen_rtx_SUBREG (tmode, inner, final_word);
            }
          else
@@ -6364,7 +6475,7 @@ make_compound_operation (x, in_code)
               : in_code == COMPARE ? SET : in_code);
 
   /* Process depending on the code of this operation.  If NEW is set
-     non-zero, it will be returned.  */
+     nonzero, it will be returned.  */
 
   switch (code)
     {
@@ -6569,7 +6680,11 @@ make_compound_operation (x, in_code)
          if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (tem))
              || (GET_MODE_SIZE (mode) >
                  GET_MODE_SIZE (GET_MODE (XEXP (tem, 0)))))
-           tem = gen_rtx_fmt_e (GET_CODE (tem), mode, XEXP (tem, 0));
+           {
+             if (! INTEGRAL_MODE_P (mode))
+               break;
+             tem = gen_rtx_fmt_e (GET_CODE (tem), mode, XEXP (tem, 0));
+           }
          else
            tem = gen_lowpart_for_combine (mode, XEXP (tem, 0));
          return tem;
@@ -6637,7 +6752,7 @@ get_pos_from_mask (m, plen)
    Return a possibly simplified expression, but always convert X to
    MODE.  If X is a CONST_INT, AND the CONST_INT with MASK.
 
-   Also, if REG is non-zero and X is a register equal in value to REG,
+   Also, if REG is nonzero and X is a register equal in value to REG,
    replace X with REG.
 
    If JUST_SELECT is nonzero, don't optimize by noticing that bits in MASK
@@ -6700,22 +6815,19 @@ force_to_mode (x, mode, mask, reg, just_select)
 
   /* If none of the bits in X are needed, return a zero.  */
   if (! just_select && (nonzero & mask) == 0)
-    return const0_rtx;
+    x = const0_rtx;
 
   /* If X is a CONST_INT, return a new one.  Do this here since the
      test below will fail.  */
   if (GET_CODE (x) == CONST_INT)
     {
-      HOST_WIDE_INT cval = INTVAL (x) & mask;
-      int width = GET_MODE_BITSIZE (mode);
-
-      /* If MODE is narrower that HOST_WIDE_INT and CVAL is a negative
-        number, sign extend it.  */
-      if (width > 0 && width < HOST_BITS_PER_WIDE_INT
-         && (cval & ((HOST_WIDE_INT) 1 << (width - 1))) != 0)
-       cval |= (HOST_WIDE_INT) -1 << width;
-
-      return GEN_INT (cval);
+      if (SCALAR_INT_MODE_P (mode))
+        return gen_int_mode (INTVAL (x) & mask, mode);
+      else
+       {
+         x = GEN_INT (INTVAL (x) & mask);
+         return gen_lowpart_common (mode, x);
+       }
     }
 
   /* If X is narrower than MODE and we want all the bits in X's mode, just
@@ -6789,7 +6901,7 @@ force_to_mode (x, mode, mask, reg, just_select)
 
          if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT
              && ((INTVAL (XEXP (x, 1)) & GET_MODE_MASK (GET_MODE (x)))
-                 == (HOST_WIDE_INT) mask))
+                 == mask))
            x = XEXP (x, 0);
 
          /* If it remains an AND, try making another AND with the bits
@@ -6922,14 +7034,6 @@ force_to_mode (x, mode, mask, reg, just_select)
                                     force_to_mode (XEXP (x, 1), mode, mask,
                                                    reg, next_select));
 
-      /* If OP1 is a CONST_INT and X is an IOR or XOR, clear bits outside
-        MASK since OP1 might have been sign-extended but we never want
-        to turn on extra bits, since combine might have previously relied
-        on them being off.  */
-      if (GET_CODE (op1) == CONST_INT && (code == IOR || code == XOR)
-         && (INTVAL (op1) & mask) != 0)
-       op1 = GEN_INT (INTVAL (op1) & mask);
-
       if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
        x = gen_binary (code, op_mode, op0, op1);
       break;
@@ -7266,7 +7370,7 @@ if_then_else_cond (x, ptrue, pfalse)
        }
 
       /* See if we have PLUS, IOR, XOR, MINUS or UMAX, where one of the
-        operands is zero when the other is non-zero, and vice-versa,
+        operands is zero when the other is nonzero, and vice-versa,
         and STORE_FLAG_VALUE is 1 or -1.  */
 
       if ((STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
@@ -7970,7 +8074,7 @@ simplify_and_const_int (x, mode, varop, constop)
    this.  This macro avoids accidental uses of num_sign_bit_copies.  */
 #define num_sign_bit_copies()
 
-/* Given an expression, X, compute which bits in X can be non-zero.
+/* Given an expression, X, compute which bits in X can be nonzero.
    We don't care about bits outside of those defined in MODE.
 
    For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
@@ -8070,7 +8174,7 @@ nonzero_bits (x, mode)
          && (reg_last_set_label[REGNO (x)] == label_tick
              || (REGNO (x) >= FIRST_PSEUDO_REGISTER
                  && REG_N_SETS (REGNO (x)) == 1
-                 && ! REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start,
+                 && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR->next_bb->global_live_at_start,
                                        REGNO (x))))
          && INSN_CUID (reg_last_set[REGNO (x)]) < subst_low_cuid)
        return reg_last_set_nonzero_bits[REGNO (x)] & nonzero;
@@ -8186,7 +8290,7 @@ nonzero_bits (x, mode)
     case SIGN_EXTEND:
       /* If the sign bit is known clear, this is the same as ZERO_EXTEND.
         Otherwise, show all the bits in the outer mode but not the inner
-        may be non-zero.  */
+        may be nonzero.  */
       inner_nz = nonzero_bits (XEXP (x, 0), mode);
       if (GET_MODE (XEXP (x, 0)) != VOIDmode)
        {
@@ -8224,7 +8328,7 @@ nonzero_bits (x, mode)
     case MOD:   case UMOD:
       /* We can apply the rules of arithmetic to compute the number of
         high- and low-order zero bits of these operations.  We start by
-        computing the width (position of the highest-order non-zero bit)
+        computing the width (position of the highest-order nonzero bit)
         and the number of low-order zero bits for each value.  */
       {
        unsigned HOST_WIDE_INT nz0 = nonzero_bits (XEXP (x, 0), mode);
@@ -8326,12 +8430,13 @@ nonzero_bits (x, mode)
 #if defined (WORD_REGISTER_OPERATIONS) && defined (LOAD_EXTEND_OP)
          /* If this is a typical RISC machine, we only have to worry
             about the way loads are extended.  */
-         if (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) == SIGN_EXTEND
-             ? (((nonzero
-                  & (((unsigned HOST_WIDE_INT) 1
-                      << (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) - 1))))
-                 != 0))
-             : LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) != ZERO_EXTEND)
+         if ((LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) == SIGN_EXTEND
+              ? (((nonzero
+                   & (((unsigned HOST_WIDE_INT) 1
+                       << (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) - 1))))
+                  != 0))
+              : LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) != ZERO_EXTEND)
+             || GET_CODE (SUBREG_REG (x)) != MEM)
 #endif
            {
              /* On many CISC machines, accessing an object in a wider mode
@@ -8485,7 +8590,7 @@ num_sign_bit_copies (x, mode)
          && (reg_last_set_label[REGNO (x)] == label_tick
              || (REGNO (x) >= FIRST_PSEUDO_REGISTER
                  && REG_N_SETS (REGNO (x)) == 1
-                 && ! REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start,
+                 && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR->next_bb->global_live_at_start,
                                        REGNO (x))))
          && INSN_CUID (reg_last_set[REGNO (x)]) < subst_low_cuid)
        return reg_last_set_sign_bit_copies[REGNO (x)];
@@ -8554,7 +8659,8 @@ num_sign_bit_copies (x, mode)
 
       if ((GET_MODE_SIZE (GET_MODE (x))
           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
-         && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) == SIGN_EXTEND)
+         && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) == SIGN_EXTEND
+         && GET_CODE (SUBREG_REG (x)) == MEM)
        return num_sign_bit_copies (SUBREG_REG (x), mode);
 #endif
 #endif
@@ -8788,8 +8894,8 @@ extended_count (x, mode, unsignedp)
 
   return (unsignedp
          ? (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
-            ? (GET_MODE_BITSIZE (mode) - 1
-               - floor_log2 (nonzero_bits (x, mode)))
+            ? (unsigned int) (GET_MODE_BITSIZE (mode) - 1
+                              - floor_log2 (nonzero_bits (x, mode)))
             : 0)
          : num_sign_bit_copies (x, mode) - 1);
 }
@@ -8932,7 +9038,7 @@ merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
 }
 \f
 /* Simplify a shift of VAROP by COUNT bits.  CODE says what kind of shift.
-   The result of the shift is RESULT_MODE.  X, if non-zero, is an expression
+   The result of the shift is RESULT_MODE.  X, if nonzero, is an expression
    that we started with.
 
    The shift is normally computed in the widest mode we find in VAROP, as
@@ -8999,7 +9105,14 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
 
       /* Convert ROTATERT to ROTATE.  */
       if (code == ROTATERT)
-       code = ROTATE, count = GET_MODE_BITSIZE (result_mode) - count;
+       {
+         unsigned int bitsize = GET_MODE_BITSIZE (result_mode);;
+         code = ROTATE;
+         if (VECTOR_MODE_P (result_mode))
+           count = bitsize / GET_MODE_NUNITS (result_mode) - count;
+         else
+           count = bitsize - count;
+       }
 
       /* We need to determine what mode we will do the shift in.  If the
         shift is a right shift or a ROTATE, we must always do it in the mode
@@ -9019,7 +9132,7 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
         multiple operations, each of which are defined, we know what the
         result is supposed to be.  */
 
-      if (count > GET_MODE_BITSIZE (shift_mode) - 1)
+      if (count > (unsigned int) (GET_MODE_BITSIZE (shift_mode) - 1))
        {
          if (code == ASHIFTRT)
            count = GET_MODE_BITSIZE (shift_mode) - 1;
@@ -9135,9 +9248,9 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
          if (subreg_lowpart_p (varop)
              && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
                  > GET_MODE_SIZE (GET_MODE (varop)))
-             && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
-                   + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
-                 == mode_words))
+             && (unsigned int) ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
+                                 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
+                == mode_words)
            {
              varop = SUBREG_REG (varop);
              if (GET_MODE_SIZE (GET_MODE (varop)) > GET_MODE_SIZE (mode))
@@ -9178,7 +9291,8 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
             bit of a wider mode may be different from what would be
             interpreted as the sign bit in a narrower mode, so, if
             the result is narrower, don't discard the shift.  */
-         if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
+         if (code == LSHIFTRT
+             && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
              && (GET_MODE_BITSIZE (result_mode)
                  >= GET_MODE_BITSIZE (GET_MODE (varop))))
            {
@@ -9212,8 +9326,9 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
                 (ashiftrt:M1 (ashift:M1 (and:M1 (subreg:M1 FOO 0 C2) C3) C1).
                 This simplifies certain SIGN_EXTEND operations.  */
              if (code == ASHIFT && first_code == ASHIFTRT
-                 && (GET_MODE_BITSIZE (result_mode)
-                     - GET_MODE_BITSIZE (GET_MODE (varop))) == count)
+                 && count == (unsigned int)
+                             (GET_MODE_BITSIZE (result_mode)
+                              - GET_MODE_BITSIZE (GET_MODE (varop))))
                {
                  /* C3 has the low-order C1 bits zero.  */
 
@@ -9369,7 +9484,8 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
              && XEXP (XEXP (varop, 0), 1) == constm1_rtx
              && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
              && (code == LSHIFTRT || code == ASHIFTRT)
-             && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
+             && count == (unsigned int)
+                         (GET_MODE_BITSIZE (GET_MODE (varop)) - 1)
              && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
            {
              count = 0;
@@ -9424,7 +9540,7 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
          if (code == LSHIFTRT
              && XEXP (varop, 1) == const0_rtx
              && GET_MODE (XEXP (varop, 0)) == result_mode
-             && count == GET_MODE_BITSIZE (result_mode) - 1
+             && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
              && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
              && ((STORE_FLAG_VALUE
                   & ((HOST_WIDE_INT) 1
@@ -9443,7 +9559,8 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
        case NEG:
          /* (lshiftrt (neg A) C) where A is either 0 or 1 and C is one less
             than the number of bits in the mode is equivalent to A.  */
-         if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
+         if (code == LSHIFTRT
+             && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
              && nonzero_bits (XEXP (varop, 0), result_mode) == 1)
            {
              varop = XEXP (varop, 0);
@@ -9467,7 +9584,8 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
          /* (lshiftrt (plus A -1) C) where A is either 0 or 1 and C
             is one less than the number of bits in the mode is
             equivalent to (xor A 1).  */
-         if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
+         if (code == LSHIFTRT
+             && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
              && XEXP (varop, 1) == constm1_rtx
              && nonzero_bits (XEXP (varop, 0), result_mode) == 1
              && merge_outer_ops (&outer_op, &outer_const, XOR,
@@ -9532,10 +9650,12 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
 
          if ((STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
              && GET_CODE (XEXP (varop, 0)) == ASHIFTRT
-             && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
+             && count == (unsigned int)
+                         (GET_MODE_BITSIZE (GET_MODE (varop)) - 1)
              && (code == LSHIFTRT || code == ASHIFTRT)
              && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
-             && INTVAL (XEXP (XEXP (varop, 0), 1)) == count
+             && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (varop, 0), 1))
+                == count
              && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
            {
              count = 0;
@@ -9599,7 +9719,7 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
 
   if (x && GET_RTX_CLASS (GET_CODE (x)) == '2'
       && GET_CODE (XEXP (x, 1)) == CONST_INT
-      && INTVAL (XEXP (x, 1)) == count)
+      && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) == count)
     const_rtx = XEXP (x, 1);
   else
     const_rtx = GEN_INT (count);
@@ -9806,12 +9926,6 @@ gen_lowpart_for_combine (mode, x)
            || GET_MODE_SIZE (GET_MODE (x)) == GET_MODE_SIZE (mode)))
     return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
 
-  /* simplify_gen_subreg does not know how to handle the case where we try
-     to convert an integer constant to a vector.
-     ??? We could try to teach it to generate CONST_VECTORs.  */
-  if (GET_MODE (x) == VOIDmode && VECTOR_MODE_P (mode))
-    return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
-
   /* X might be a paradoxical (subreg (mem)).  In that case, gen_lowpart
      won't know what to do.  So we will strip off the SUBREG here and
      process normally.  */
@@ -9878,9 +9992,15 @@ gen_lowpart_for_combine (mode, x)
     {
       int offset = 0;
       rtx res;
+      enum machine_mode sub_mode = GET_MODE (x);
 
-      offset = subreg_lowpart_offset (mode, GET_MODE (x));
-      res = simplify_gen_subreg (mode, x, GET_MODE (x), offset);
+      offset = subreg_lowpart_offset (mode, sub_mode);
+      if (sub_mode == VOIDmode)
+       {
+         sub_mode = int_mode_for_mode (mode);
+         x = gen_lowpart_common (sub_mode, x);
+       }
+      res = simplify_gen_subreg (mode, x, sub_mode, offset);
       if (res)
        return res;
       return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
@@ -10139,7 +10259,9 @@ simplify_comparison (code, pop0, pop1)
 
       /* Get the constant we are comparing against and turn off all bits
         not on in our mode.  */
-      const_op = trunc_int_for_mode (INTVAL (op1), mode);
+      const_op = INTVAL (op1);
+      if (mode != VOIDmode)
+       const_op = trunc_int_for_mode (const_op, mode);
       op1 = GEN_INT (const_op);
 
       /* If we are comparing against a constant power of two and the value
@@ -10511,7 +10633,8 @@ simplify_comparison (code, pop0, pop1)
                        & ~GET_MODE_MASK (mode))
                  || (num_sign_bit_copies (XEXP (SUBREG_REG (op0), 0),
                                           GET_MODE (SUBREG_REG (op0)))
-                     > (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
+                     > (unsigned int)
+                       (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
                         - GET_MODE_BITSIZE (mode)))))
            {
              op0 = SUBREG_REG (op0);
@@ -10595,7 +10718,8 @@ simplify_comparison (code, pop0, pop1)
             of bits in X minus 1, is one iff X > 0.  */
          if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == ASHIFTRT
              && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
-             && INTVAL (XEXP (XEXP (op0, 0), 1)) == mode_width - 1
+             && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (op0, 0), 1))
+                == mode_width - 1
              && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)))
            {
              op0 = XEXP (op0, 1);
@@ -10664,7 +10788,7 @@ simplify_comparison (code, pop0, pop1)
          break;
 
        case IOR:
-         /* The sign bit of (ior (plus X (const_int -1)) X) is non-zero
+         /* The sign bit of (ior (plus X (const_int -1)) X) is nonzero
             iff X <= 0.  */
          if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == PLUS
              && XEXP (XEXP (op0, 0), 1) == constm1_rtx
@@ -10853,7 +10977,8 @@ simplify_comparison (code, pop0, pop1)
             low-order bit.  */
          if (const_op == 0 && equality_comparison_p
              && GET_CODE (XEXP (op0, 1)) == CONST_INT
-             && INTVAL (XEXP (op0, 1)) == mode_width - 1)
+             && (unsigned HOST_WIDE_INT) INTVAL (XEXP (op0, 1))
+                == mode_width - 1)
            {
              op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
                                            (HOST_WIDE_INT) 1);
@@ -10950,7 +11075,8 @@ simplify_comparison (code, pop0, pop1)
          if (const_op == 0
              && (equality_comparison_p || sign_bit_comparison_p)
              && GET_CODE (XEXP (op0, 1)) == CONST_INT
-             && INTVAL (XEXP (op0, 1)) == mode_width - 1)
+             && (unsigned HOST_WIDE_INT) INTVAL (XEXP (op0, 1))
+                == mode_width - 1)
            {
              op0 = XEXP (op0, 0);
              code = (code == NE || code == GT ? LT : GE);
@@ -11051,9 +11177,11 @@ simplify_comparison (code, pop0, pop1)
 
          if (zero_extended
              || ((num_sign_bit_copies (op0, tmode)
-                  > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))
+                  > (unsigned int) (GET_MODE_BITSIZE (tmode)
+                                    - GET_MODE_BITSIZE (mode)))
                  && (num_sign_bit_copies (op1, tmode)
-                     > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))))
+                     > (unsigned int) (GET_MODE_BITSIZE (tmode)
+                                       - GET_MODE_BITSIZE (mode)))))
            {
              /* If OP0 is an AND and we don't have an AND in MODE either,
                 make a new AND in the proper mode.  */
@@ -11461,7 +11589,7 @@ check_promoted_subreg (insn, x)
    mentioned in *LOC are valid when *LOC was part of a value set when
    label_tick == TICK.  Return 0 if some are not.
 
-   If REPLACE is non-zero, replace the invalid reference with
+   If REPLACE is nonzero, replace the invalid reference with
    (clobber (const_int 0)) and return 1.  This replacement is useful because
    we often can get useful information about the form of a value (e.g., if
    it was produced by a shift that always produces -1 or 0) even though
@@ -11494,7 +11622,7 @@ get_last_value_validate (loc, insn, tick, replace)
            || (! (regno >= FIRST_PSEUDO_REGISTER
                   && REG_N_SETS (regno) == 1
                   && (! REGNO_REG_SET_P
-                      (BASIC_BLOCK (0)->global_live_at_start, regno)))
+                      (ENTRY_BLOCK_PTR->next_bb->global_live_at_start, regno)))
                && reg_last_set_label[j] > tick))
          {
            if (replace)
@@ -11568,7 +11696,7 @@ get_last_value (x)
          && (regno < FIRST_PSEUDO_REGISTER
              || REG_N_SETS (regno) != 1
              || (REGNO_REG_SET_P
-                 (BASIC_BLOCK (0)->global_live_at_start, regno)))))
+                 (ENTRY_BLOCK_PTR->next_bb->global_live_at_start, regno)))))
     return 0;
 
   /* If the value was set in a later insn than the ones we are processing,
@@ -11674,7 +11802,7 @@ reg_dead_at_p_1 (dest, x, data)
     reg_dead_flag = (GET_CODE (x) == CLOBBER) ? 1 : -1;
 }
 
-/* Return non-zero if REG is known to be dead at INSN.
+/* Return nonzero if REG is known to be dead at INSN.
 
    We scan backwards from INSN.  If we hit a REG_DEAD note or a CLOBBER
    referencing REG, it is dead.  If we hit a SET referencing REG, it is
@@ -11687,7 +11815,7 @@ reg_dead_at_p (reg, insn)
      rtx reg;
      rtx insn;
 {
-  int block;
+  basic_block block;
   unsigned int i;
 
   /* Set variables for reg_dead_at_p_1.  */
@@ -11720,21 +11848,21 @@ reg_dead_at_p (reg, insn)
        return 1;
     }
 
-  /* Get the basic block number that we were in.  */
+  /* Get the basic block that we were in.  */
   if (insn == 0)
-    block = 0;
+    block = ENTRY_BLOCK_PTR->next_bb;
   else
     {
-      for (block = 0; block < n_basic_blocks; block++)
-       if (insn == BLOCK_HEAD (block))
+      FOR_EACH_BB (block)
+       if (insn == block->head)
          break;
 
-      if (block == n_basic_blocks)
+      if (block == EXIT_BLOCK_PTR)
        return 0;
     }
 
   for (i = reg_dead_regno; i < reg_dead_endregno; i++)
-    if (REGNO_REG_SET_P (BASIC_BLOCK (block)->global_live_at_start, i))
+    if (REGNO_REG_SET_P (block->global_live_at_start, i))
       return 0;
 
   return 1;
@@ -11941,7 +12069,7 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
                if (i < regno || i >= ourend)
                  REG_NOTES (where_dead)
                    = gen_rtx_EXPR_LIST (REG_DEAD,
-                                        gen_rtx_REG (reg_raw_mode[i], i),
+                                        regno_reg_rtx[i],
                                         REG_NOTES (where_dead));
            }
 
@@ -11968,7 +12096,7 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
                offset = 1;
 
              for (i = regno + offset; i < ourend; i++)
-               move_deaths (gen_rtx_REG (reg_raw_mode[i], i),
+               move_deaths (regno_reg_rtx[i],
                             maybe_kill_insn, from_cuid, to_insn, &oldnotes);
            }
 
@@ -12348,7 +12476,7 @@ distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
 
        case REG_DEAD:
          /* If the register is used as an input in I3, it dies there.
-            Similarly for I2, if it is non-zero and adjacent to I3.
+            Similarly for I2, if it is nonzero and adjacent to I3.
 
             If the register is not used as an input in either I3 or I2
             and it is not one of the registers we were supposed to eliminate,
@@ -12377,7 +12505,7 @@ distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
 
          if (place == 0)
            {
-             basic_block bb = BASIC_BLOCK (this_basic_block);
+             basic_block bb = this_basic_block;
 
              for (tem = PREV_INSN (i3); place == 0; tem = PREV_INSN (tem))
                {
@@ -12521,7 +12649,7 @@ distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
                  && REGNO_REG_SET_P (bb->global_live_at_start,
                                      REGNO (XEXP (note, 0))))
                {
-                 SET_BIT (refresh_blocks, this_basic_block);
+                 SET_BIT (refresh_blocks, this_basic_block->index);
                  need_refresh = 1;
                }
            }
@@ -12541,7 +12669,7 @@ distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
                 after we remove them in delete_noop_moves.  */
              if (noop_move_p (place))
                {
-                 SET_BIT (refresh_blocks, this_basic_block);
+                 SET_BIT (refresh_blocks, this_basic_block->index);
                  need_refresh = 1;
                }
 
@@ -12590,8 +12718,8 @@ distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
                      for (i = regno; i < endregno;
                           i += HARD_REGNO_NREGS (i, reg_raw_mode[i]))
                        {
-                         rtx piece = gen_rtx_REG (reg_raw_mode[i], i);
-                         basic_block bb = BASIC_BLOCK (this_basic_block);
+                         rtx piece = regno_reg_rtx[i];
+                         basic_block bb = this_basic_block;
 
                          if (! dead_or_set_p (place, piece)
                              && ! reg_bitfield_target_p (piece,
@@ -12614,7 +12742,7 @@ distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
                                    if (tem == bb->head)
                                      {
                                        SET_BIT (refresh_blocks,
-                                                this_basic_block);
+                                                this_basic_block->index);
                                        need_refresh = 1;
                                        break;
                                      }
@@ -12719,8 +12847,8 @@ distribute_links (links)
         since most links don't point very far away.  */
 
       for (insn = NEXT_INSN (XEXP (link, 0));
-          (insn && (this_basic_block == n_basic_blocks - 1
-                    || BLOCK_HEAD (this_basic_block + 1) != insn));
+          (insn && (this_basic_block->next_bb == EXIT_BLOCK_PTR
+                    || this_basic_block->next_bb->head != insn));
           insn = NEXT_INSN (insn))
        if (INSN_P (insn) && reg_overlap_mentioned_p (reg, PATTERN (insn)))
          {