OSDN Git Service

More MIPS vector cleanup work.
[pf3gnuchains/gcc-fork.git] / gcc / combine.c
index c470655..44d8b29 100644 (file)
@@ -1,6 +1,6 @@
 /* Optimize by combining instructions for GNU compiler.
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -75,6 +75,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "coretypes.h"
 #include "tm.h"
 #include "rtl.h"
+#include "tree.h"
 #include "tm_p.h"
 #include "flags.h"
 #include "regs.h"
@@ -88,10 +89,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "recog.h"
 #include "real.h"
 #include "toplev.h"
-
-/* It is not safe to use ordinary gen_lowpart in combine.
-   Use gen_lowpart_for_combine instead.  See comments there.  */
-#define gen_lowpart dont_use_gen_lowpart_you_dummy
+#include "target.h"
+#include "rtlhooks-def.h"
+/* Include output.h for dump_file.  */
+#include "output.h"
 
 /* Number of attempts to combine instructions in this function.  */
 
@@ -135,23 +136,107 @@ static int max_uid_cuid;
 #define UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD(val) \
   (((unsigned HOST_WIDE_INT) (val) << (BITS_PER_WORD - 1)) << 1)
 
-#define nonzero_bits(X, M) \
-  cached_nonzero_bits (X, M, NULL_RTX, VOIDmode, 0)
-
-#define num_sign_bit_copies(X, M) \
-  cached_num_sign_bit_copies (X, M, NULL_RTX, VOIDmode, 0)
-
 /* Maximum register number, which is the size of the tables below.  */
 
 static unsigned int combine_max_regno;
 
-/* Record last point of death of (hard or pseudo) register n.  */
+struct reg_stat {
+  /* Record last point of death of (hard or pseudo) register n.  */
+  rtx                          last_death;
+
+  /* Record last point of modification of (hard or pseudo) register n.  */
+  rtx                          last_set;
+
+  /* The next group of fields allows the recording of the last value assigned
+     to (hard or pseudo) register n.  We use this information to see if an
+     operation being processed is redundant given a prior operation performed
+     on the register.  For example, an `and' with a constant is redundant if
+     all the zero bits are already known to be turned off.
+
+     We use an approach similar to that used by cse, but change it in the
+     following ways:
+
+     (1) We do not want to reinitialize at each label.
+     (2) It is useful, but not critical, to know the actual value assigned
+         to a register.  Often just its form is helpful.
+
+     Therefore, we maintain the following fields:
+
+     last_set_value            the last value assigned
+     last_set_label            records the value of label_tick when the
+                               register was assigned
+     last_set_table_tick       records the value of label_tick when a
+                               value using the register is assigned
+     last_set_invalid          set to nonzero when it is not valid
+                               to use the value of this register in some
+                               register's value
+
+     To understand the usage of these tables, it is important to understand
+     the distinction between the value in last_set_value being valid and
+     the register being validly contained in some other expression in the
+     table.
+
+     (The next two parameters are out of date).
+
+     reg_stat[i].last_set_value is valid if it is nonzero, and either
+     reg_n_sets[i] is 1 or reg_stat[i].last_set_label == label_tick.
+
+     Register I may validly appear in any expression returned for the value
+     of another register if reg_n_sets[i] is 1.  It may also appear in the
+     value for register J if reg_stat[j].last_set_invalid is zero, or
+     reg_stat[i].last_set_label < reg_stat[j].last_set_label.
+
+     If an expression is found in the table containing a register which may
+     not validly appear in an expression, the register is replaced by
+     something that won't match, (clobber (const_int 0)).  */
+
+  /* Record last value assigned to (hard or pseudo) register n.  */
+
+  rtx                          last_set_value;
+
+  /* Record the value of label_tick when an expression involving register n
+     is placed in last_set_value.  */
+
+  int                          last_set_table_tick;
+
+  /* Record the value of label_tick when the value for register n is placed in
+     last_set_value.  */
+
+  int                          last_set_label;
+
+  /* These fields are maintained in parallel with last_set_value and are
+     used to store the mode in which the register was last set, the bits
+     that were known to be zero when it was last set, and the number of
+     sign bits copies it was known to have when it was last set.  */
+
+  unsigned HOST_WIDE_INT       last_set_nonzero_bits;
+  char                         last_set_sign_bit_copies;
+  ENUM_BITFIELD(machine_mode)  last_set_mode : 8; 
+
+  /* Set nonzero if references to register n in expressions should not be
+     used.  last_set_invalid is set nonzero when this register is being
+     assigned to and last_set_table_tick == label_tick.  */
+
+  char                         last_set_invalid;
+
+  /* Some registers that are set more than once and used in more than one
+     basic block are nevertheless always set in similar ways.  For example,
+     a QImode register may be loaded from memory in two places on a machine
+     where byte loads zero extend.
+
+     We record in the following fields if a register has some leading bits
+     that are always equal to the sign bit, and what we know about the
+     nonzero bits of a register, specifically which bits are known to be
+     zero.
+
+     If an entry is zero, it means that we don't know anything special.  */
 
-static rtx *reg_last_death;
+  unsigned char                        sign_bit_copies;
 
-/* Record last point of modification of (hard or pseudo) register n.  */
+  unsigned HOST_WIDE_INT       nonzero_bits;
+};
 
-static rtx *reg_last_set;
+static struct reg_stat *reg_stat;
 
 /* Record the cuid of the last insn that invalidated memory
    (anything that writes memory, and subroutine calls, but not pushes).  */
@@ -199,110 +284,32 @@ static basic_block this_basic_block;
    those blocks as starting points.  */
 static sbitmap refresh_blocks;
 \f
-/* The next group of arrays allows the recording of the last value assigned
-   to (hard or pseudo) register n.  We use this information to see if an
-   operation being processed is redundant given a prior operation performed
-   on the register.  For example, an `and' with a constant is redundant if
-   all the zero bits are already known to be turned off.
-
-   We use an approach similar to that used by cse, but change it in the
-   following ways:
-
-   (1) We do not want to reinitialize at each label.
-   (2) It is useful, but not critical, to know the actual value assigned
-       to a register.  Often just its form is helpful.
-
-   Therefore, we maintain the following arrays:
-
-   reg_last_set_value          the last value assigned
-   reg_last_set_label          records the value of label_tick when the
-                               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 nonzero when it is not valid
-                               to use the value of this register in some
-                               register's value
-
-   To understand the usage of these tables, it is important to understand
-   the distinction between the value in reg_last_set_value being valid
-   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 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
-   of another register if reg_n_sets[i] is 1.  It may also appear in the
-   value for register J if reg_last_set_label[i] < reg_last_set_label[j] or
-   reg_last_set_invalid[j] is zero.
-
-   If an expression is found in the table containing a register which may
-   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 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.  */
-
-static rtx *reg_last_set_value;
+/* The following array records the insn_rtx_cost for every insn
+   in the instruction stream.  */
 
-/* Record the value of label_tick when the value for register n is placed in
-   reg_last_set_value[n].  */
+static int *uid_insn_cost;
 
-static int *reg_last_set_label;
+/* Length of the currently allocated uid_insn_cost array.  */
 
-/* Record the value of label_tick when an expression involving register n
-   is placed in reg_last_set_value.  */
-
-static int *reg_last_set_table_tick;
-
-/* Set nonzero if references to register n in expressions should not be
-   used.  */
-
-static char *reg_last_set_invalid;
+static int last_insn_cost;
 
 /* Incremented for each label.  */
 
 static int label_tick;
 
-/* Some registers that are set more than once and used in more than one
-   basic block are nevertheless always set in similar ways.  For example,
-   a QImode register may be loaded from memory in two places on a machine
-   where byte loads zero extend.
-
-   We record in the following array what we know about the nonzero
-   bits of a register, specifically which bits are known to be zero.
-
-   If an entry is zero, it means that we don't know anything special.  */
-
-static unsigned HOST_WIDE_INT *reg_nonzero_bits;
-
-/* Mode used to compute significance in reg_nonzero_bits.  It is the largest
-   integer mode that can fit in HOST_BITS_PER_WIDE_INT.  */
+/* Mode used to compute significance in reg_stat[].nonzero_bits.  It is the
+   largest integer mode that can fit in HOST_BITS_PER_WIDE_INT.  */
 
 static enum machine_mode nonzero_bits_mode;
 
-/* Nonzero if we know that a register has some leading bits that are always
-   equal to the sign bit.  */
-
-static unsigned char *reg_sign_bit_copies;
-
-/* Nonzero when reg_nonzero_bits and reg_sign_bit_copies can be safely used.
-   It is zero while computing them and after combine has completed.  This
-   former test prevents propagating values based on previously set values,
-   which can be incorrect if a variable is modified in a loop.  */
+/* Nonzero when reg_stat[].nonzero_bits and reg_stat[].sign_bit_copies can
+   be safely used.  It is zero while computing them and after combine has
+   completed.  This former test prevents propagating values based on
+   previously set values, which can be incorrect if a variable is modified
+   in a loop.  */
 
 static int nonzero_sign_valid;
 
-/* These arrays are maintained in parallel with reg_last_set_value
-   and are used to store the mode in which the register was last set,
-   the bits that were known to be zero when it was last set, and the
-   number of sign bits copies it was known to have when it was last set.  */
-
-static enum machine_mode *reg_last_set_mode;
-static unsigned HOST_WIDE_INT *reg_last_set_nonzero_bits;
-static char *reg_last_set_sign_bit_copies;
 \f
 /* Record one modification to rtl structure
    to be undone by storing old_contents into *where.
@@ -336,86 +343,92 @@ static struct undobuf undobuf;
 
 static int n_occurrences;
 
-static void do_SUBST                   PARAMS ((rtx *, rtx));
-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 *));
-static int cant_combine_insn_p PARAMS ((rtx));
-static int can_combine_p       PARAMS ((rtx, rtx, rtx, rtx, rtx *, rtx *));
-static int sets_function_arg_p PARAMS ((rtx));
-static int combinable_i3pat    PARAMS ((rtx, rtx *, rtx, rtx, int, rtx *));
-static int contains_muldiv     PARAMS ((rtx));
-static rtx try_combine         PARAMS ((rtx, rtx, rtx, int *));
-static void undo_all           PARAMS ((void));
-static void undo_commit                PARAMS ((void));
-static rtx *find_split_point   PARAMS ((rtx *, rtx));
-static rtx subst               PARAMS ((rtx, rtx, rtx, int, int));
-static rtx combine_simplify_rtx        PARAMS ((rtx, enum machine_mode, int, int));
-static rtx simplify_if_then_else  PARAMS ((rtx));
-static rtx simplify_set                PARAMS ((rtx));
-static rtx simplify_logical    PARAMS ((rtx, int));
-static rtx expand_compound_operation  PARAMS ((rtx));
-static rtx expand_field_assignment  PARAMS ((rtx));
-static rtx make_extraction     PARAMS ((enum machine_mode, rtx, HOST_WIDE_INT,
-                                        rtx, unsigned HOST_WIDE_INT, int,
-                                        int, int));
-static rtx extract_left_shift  PARAMS ((rtx, int));
-static rtx make_compound_operation  PARAMS ((rtx, enum rtx_code));
-static int get_pos_from_mask   PARAMS ((unsigned HOST_WIDE_INT,
-                                        unsigned HOST_WIDE_INT *));
-static rtx force_to_mode       PARAMS ((rtx, enum machine_mode,
-                                        unsigned HOST_WIDE_INT, rtx, int));
-static rtx if_then_else_cond   PARAMS ((rtx, rtx *, rtx *));
-static rtx known_cond          PARAMS ((rtx, enum rtx_code, rtx, rtx));
-static int rtx_equal_for_field_assignment_p PARAMS ((rtx, rtx));
-static rtx make_field_assignment  PARAMS ((rtx));
-static rtx apply_distributive_law  PARAMS ((rtx));
-static rtx simplify_and_const_int  PARAMS ((rtx, enum machine_mode, rtx,
-                                           unsigned HOST_WIDE_INT));
-static unsigned HOST_WIDE_INT cached_nonzero_bits
-                               PARAMS ((rtx, enum machine_mode, rtx,
+static rtx reg_nonzero_bits_for_combine (rtx, enum machine_mode, rtx,
                                         enum machine_mode,
-                                        unsigned HOST_WIDE_INT));
-static unsigned HOST_WIDE_INT nonzero_bits1
-                               PARAMS ((rtx, enum machine_mode, rtx,
-                                        enum machine_mode,
-                                        unsigned HOST_WIDE_INT));
-static unsigned int cached_num_sign_bit_copies
-                               PARAMS ((rtx, enum machine_mode, rtx,
-                                        enum machine_mode, unsigned int));
-static unsigned int num_sign_bit_copies1
-                               PARAMS ((rtx, enum machine_mode, rtx,
-                                        enum machine_mode, unsigned int));
-static int merge_outer_ops     PARAMS ((enum rtx_code *, HOST_WIDE_INT *,
-                                        enum rtx_code, HOST_WIDE_INT,
-                                        enum machine_mode, int *));
-static rtx simplify_shift_const        PARAMS ((rtx, enum rtx_code, enum machine_mode,
-                                        rtx, int));
-static int recog_for_combine   PARAMS ((rtx *, rtx, rtx *));
-static rtx gen_lowpart_for_combine  PARAMS ((enum machine_mode, rtx));
-static rtx gen_binary          PARAMS ((enum rtx_code, enum machine_mode,
-                                        rtx, rtx));
-static enum rtx_code simplify_comparison  PARAMS ((enum rtx_code, rtx *, rtx *));
-static void update_table_tick  PARAMS ((rtx));
-static void record_value_for_reg  PARAMS ((rtx, rtx, rtx));
-static void check_promoted_subreg PARAMS ((rtx, rtx));
-static void record_dead_and_set_regs_1  PARAMS ((rtx, rtx, void *));
-static void record_dead_and_set_regs  PARAMS ((rtx));
-static int get_last_value_validate  PARAMS ((rtx *, rtx, int, int));
-static rtx get_last_value      PARAMS ((rtx));
-static int use_crosses_set_p   PARAMS ((rtx, int));
-static void reg_dead_at_p_1    PARAMS ((rtx, rtx, void *));
-static int reg_dead_at_p       PARAMS ((rtx, rtx));
-static void move_deaths                PARAMS ((rtx, rtx, int, rtx, rtx *));
-static int reg_bitfield_target_p  PARAMS ((rtx, rtx));
-static void distribute_notes   PARAMS ((rtx, rtx, rtx, rtx));
-static void distribute_links   PARAMS ((rtx));
-static void mark_used_regs_combine PARAMS ((rtx));
-static int insn_cuid           PARAMS ((rtx));
-static void record_promoted_value PARAMS ((rtx, rtx));
-static rtx reversed_comparison  PARAMS ((rtx, enum machine_mode, rtx, rtx));
-static enum rtx_code combine_reversed_comparison_code PARAMS ((rtx));
+                                        unsigned HOST_WIDE_INT,
+                                        unsigned HOST_WIDE_INT *);
+static rtx reg_num_sign_bit_copies_for_combine (rtx, enum machine_mode, rtx,
+                                               enum machine_mode,
+                                               unsigned int, unsigned int *);
+static void do_SUBST (rtx *, rtx);
+static void do_SUBST_INT (int *, int);
+static void init_reg_last (void);
+static void setup_incoming_promotions (void);
+static void set_nonzero_bits_and_sign_copies (rtx, rtx, void *);
+static int cant_combine_insn_p (rtx);
+static int can_combine_p (rtx, rtx, rtx, rtx, rtx *, rtx *);
+static int combinable_i3pat (rtx, rtx *, rtx, rtx, int, rtx *);
+static int contains_muldiv (rtx);
+static rtx try_combine (rtx, rtx, rtx, int *);
+static void undo_all (void);
+static void undo_commit (void);
+static rtx *find_split_point (rtx *, rtx);
+static rtx subst (rtx, rtx, rtx, int, int);
+static rtx combine_simplify_rtx (rtx, enum machine_mode, int);
+static rtx simplify_if_then_else (rtx);
+static rtx simplify_set (rtx);
+static rtx simplify_logical (rtx);
+static rtx expand_compound_operation (rtx);
+static rtx expand_field_assignment (rtx);
+static rtx make_extraction (enum machine_mode, rtx, HOST_WIDE_INT,
+                           rtx, unsigned HOST_WIDE_INT, int, int, int);
+static rtx extract_left_shift (rtx, int);
+static rtx make_compound_operation (rtx, enum rtx_code);
+static int get_pos_from_mask (unsigned HOST_WIDE_INT,
+                             unsigned HOST_WIDE_INT *);
+static rtx force_to_mode (rtx, enum machine_mode,
+                         unsigned HOST_WIDE_INT, rtx, int);
+static rtx if_then_else_cond (rtx, rtx *, rtx *);
+static rtx known_cond (rtx, enum rtx_code, rtx, rtx);
+static int rtx_equal_for_field_assignment_p (rtx, rtx);
+static rtx make_field_assignment (rtx);
+static rtx apply_distributive_law (rtx);
+static rtx simplify_and_const_int (rtx, enum machine_mode, rtx,
+                                  unsigned HOST_WIDE_INT);
+static int merge_outer_ops (enum rtx_code *, HOST_WIDE_INT *, enum rtx_code,
+                           HOST_WIDE_INT, enum machine_mode, int *);
+static rtx simplify_shift_const        (rtx, enum rtx_code, enum machine_mode, rtx,
+                                int);
+static int recog_for_combine (rtx *, rtx, rtx *);
+static rtx gen_lowpart_for_combine (enum machine_mode, rtx);
+static rtx gen_binary (enum rtx_code, enum machine_mode, rtx, rtx);
+static enum rtx_code simplify_comparison (enum rtx_code, rtx *, rtx *);
+static void update_table_tick (rtx);
+static void record_value_for_reg (rtx, rtx, rtx);
+static void check_promoted_subreg (rtx, rtx);
+static void record_dead_and_set_regs_1 (rtx, rtx, void *);
+static void record_dead_and_set_regs (rtx);
+static int get_last_value_validate (rtx *, rtx, int, int);
+static rtx get_last_value (rtx);
+static int use_crosses_set_p (rtx, int);
+static void reg_dead_at_p_1 (rtx, rtx, void *);
+static int reg_dead_at_p (rtx, rtx);
+static void move_deaths (rtx, rtx, int, rtx, rtx *);
+static int reg_bitfield_target_p (rtx, rtx);
+static void distribute_notes (rtx, rtx, rtx, rtx);
+static void distribute_links (rtx);
+static void mark_used_regs_combine (rtx);
+static int insn_cuid (rtx);
+static void record_promoted_value (rtx, rtx);
+static rtx reversed_comparison (rtx, enum machine_mode, rtx, rtx);
+static enum rtx_code combine_reversed_comparison_code (rtx);
+static int unmentioned_reg_p_1 (rtx *, void *);
+static bool unmentioned_reg_p (rtx, rtx);
+\f
+
+/* It is not safe to use ordinary gen_lowpart in combine.
+   See comments in gen_lowpart_for_combine.  */
+#undef RTL_HOOKS_GEN_LOWPART
+#define RTL_HOOKS_GEN_LOWPART              gen_lowpart_for_combine
+
+#undef RTL_HOOKS_REG_NONZERO_REG_BITS
+#define RTL_HOOKS_REG_NONZERO_REG_BITS     reg_nonzero_bits_for_combine
+
+#undef RTL_HOOKS_REG_NUM_SIGN_BIT_COPIES
+#define RTL_HOOKS_REG_NUM_SIGN_BIT_COPIES  reg_num_sign_bit_copies_for_combine
+
+static const struct rtl_hooks combine_rtl_hooks = RTL_HOOKS_INITIALIZER;
+
 \f
 /* Substitute NEWVAL, an rtx expression, into INTO, a place in some
    insn.  The substitution can be undone by undo_all.  If INTO is already
@@ -424,8 +437,7 @@ static enum rtx_code combine_reversed_comparison_code PARAMS ((rtx));
    the undo table.  */
 
 static void
-do_SUBST (into, newval)
-     rtx *into, newval;
+do_SUBST (rtx *into, rtx newval)
 {
   struct undo *buf;
   rtx oldval = *into;
@@ -463,7 +475,7 @@ do_SUBST (into, newval)
   if (undobuf.frees)
     buf = undobuf.frees, undobuf.frees = buf->next;
   else
-    buf = (struct undo *) xmalloc (sizeof (struct undo));
+    buf = xmalloc (sizeof (struct undo));
 
   buf->is_int = 0;
   buf->where.r = into;
@@ -480,8 +492,7 @@ do_SUBST (into, newval)
    not safe.  */
 
 static void
-do_SUBST_INT (into, newval)
-     int *into, newval;
+do_SUBST_INT (int *into, int newval)
 {
   struct undo *buf;
   int oldval = *into;
@@ -492,7 +503,7 @@ do_SUBST_INT (into, newval)
   if (undobuf.frees)
     buf = undobuf.frees, undobuf.frees = buf->next;
   else
-    buf = (struct undo *) xmalloc (sizeof (struct undo));
+    buf = xmalloc (sizeof (struct undo));
 
   buf->is_int = 1;
   buf->where.i = into;
@@ -504,15 +515,106 @@ do_SUBST_INT (into, newval)
 
 #define SUBST_INT(INTO, NEWVAL)  do_SUBST_INT(&(INTO), (NEWVAL))
 \f
+/* Subroutine of try_combine.  Determine whether the combine replacement
+   patterns NEWPAT and NEWI2PAT are cheaper according to insn_rtx_cost
+   that the original instruction sequence I1, I2 and I3.  Note that I1
+   and/or NEWI2PAT may be NULL_RTX.  This function returns false, if the
+   costs of all instructions can be estimated, and the replacements are
+   more expensive than the original sequence.  */
+
+static bool
+combine_validate_cost (rtx i1, rtx i2, rtx i3, rtx newpat, rtx newi2pat)
+{
+  int i1_cost, i2_cost, i3_cost;
+  int new_i2_cost, new_i3_cost;
+  int old_cost, new_cost;
+
+  /* Lookup the original insn_rtx_costs.  */
+  i2_cost = INSN_UID (i2) <= last_insn_cost
+           ? uid_insn_cost[INSN_UID (i2)] : 0;
+  i3_cost = INSN_UID (i3) <= last_insn_cost
+           ? uid_insn_cost[INSN_UID (i3)] : 0;
+
+  if (i1)
+    {
+      i1_cost = INSN_UID (i1) <= last_insn_cost
+               ? uid_insn_cost[INSN_UID (i1)] : 0;
+      old_cost = (i1_cost > 0 && i2_cost > 0 && i3_cost > 0)
+                ? i1_cost + i2_cost + i3_cost : 0;
+    }
+  else
+    {
+      old_cost = (i2_cost > 0 && i3_cost > 0) ? i2_cost + i3_cost : 0;
+      i1_cost = 0;
+    }
+
+  /* Calculate the replacement insn_rtx_costs.  */
+  new_i3_cost = insn_rtx_cost (newpat);
+  if (newi2pat)
+    {
+      new_i2_cost = insn_rtx_cost (newi2pat);
+      new_cost = (new_i2_cost > 0 && new_i3_cost > 0)
+                ? new_i2_cost + new_i3_cost : 0;
+    }
+  else
+    {
+      new_cost = new_i3_cost;
+      new_i2_cost = 0;
+    }
+
+  /* Disallow this recombination if both new_cost and old_cost are
+     greater than zero, and new_cost is greater than old cost.  */
+  if (!undobuf.other_insn
+      && old_cost > 0
+      && new_cost > old_cost)
+    {
+      if (dump_file)
+       {
+         if (i1)
+           {
+             fprintf (dump_file,
+                      "rejecting combination of insns %d, %d and %d\n",
+                      INSN_UID (i1), INSN_UID (i2), INSN_UID (i3));
+             fprintf (dump_file, "original costs %d + %d + %d = %d\n",
+                      i1_cost, i2_cost, i3_cost, old_cost);
+           }
+         else
+           {
+             fprintf (dump_file,
+                      "rejecting combination of insns %d and %d\n",
+                      INSN_UID (i2), INSN_UID (i3));
+             fprintf (dump_file, "original costs %d + %d = %d\n",
+                      i2_cost, i3_cost, old_cost);
+           }
+
+         if (newi2pat)
+           {
+             fprintf (dump_file, "replacement costs %d + %d = %d\n",
+                      new_i2_cost, new_i3_cost, new_cost);
+           }
+         else
+           fprintf (dump_file, "replacement cost %d\n", new_cost);
+       }
+
+      return false;
+    }
+
+  /* Update the uid_insn_cost array with the replacement costs.  */
+  uid_insn_cost[INSN_UID (i2)] = new_i2_cost;
+  uid_insn_cost[INSN_UID (i3)] = new_i3_cost;
+  if (i1)
+    uid_insn_cost[INSN_UID (i1)] = 0;
+
+  return true;
+}
+\f
 /* Main entry point for combiner.  F is the first insn of the function.
    NREGS is the first unused pseudo-reg number.
 
    Return nonzero if the combiner has turned an indirect jump
    instruction into a direct jump.  */
 int
-combine_instructions (f, nregs)
-     rtx f;
-     unsigned int nregs;
+combine_instructions (rtx f, unsigned int nregs)
 {
   rtx insn, next;
 #ifdef HAVE_cc0
@@ -530,25 +632,9 @@ combine_instructions (f, nregs)
 
   combine_max_regno = nregs;
 
-  reg_nonzero_bits = ((unsigned HOST_WIDE_INT *)
-                     xcalloc (nregs, sizeof (unsigned HOST_WIDE_INT)));
-  reg_sign_bit_copies
-    = (unsigned char *) xcalloc (nregs, sizeof (unsigned char));
-
-  reg_last_death = (rtx *) xmalloc (nregs * sizeof (rtx));
-  reg_last_set = (rtx *) xmalloc (nregs * sizeof (rtx));
-  reg_last_set_value = (rtx *) xmalloc (nregs * sizeof (rtx));
-  reg_last_set_table_tick = (int *) xmalloc (nregs * sizeof (int));
-  reg_last_set_label = (int *) xmalloc (nregs * sizeof (int));
-  reg_last_set_invalid = (char *) xmalloc (nregs * sizeof (char));
-  reg_last_set_mode
-    = (enum machine_mode *) xmalloc (nregs * sizeof (enum machine_mode));
-  reg_last_set_nonzero_bits
-    = (unsigned HOST_WIDE_INT *) xmalloc (nregs * sizeof (HOST_WIDE_INT));
-  reg_last_set_sign_bit_copies
-    = (char *) xmalloc (nregs * sizeof (char));
-
-  init_reg_last_arrays ();
+  rtl_hooks = combine_rtl_hooks;
+
+  reg_stat = xcalloc (nregs, sizeof (struct reg_stat));
 
   init_recog_no_volatile ();
 
@@ -558,13 +644,13 @@ combine_instructions (f, nregs)
     if (INSN_UID (insn) > i)
       i = INSN_UID (insn);
 
-  uid_cuid = (int *) xmalloc ((i + 1) * sizeof (int));
+  uid_cuid = xmalloc ((i + 1) * sizeof (int));
   max_uid_cuid = i;
 
   nonzero_bits_mode = mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0);
 
-  /* Don't use reg_nonzero_bits when computing it.  This can cause problems
-     when, for example, we have j <<= 1 in a loop.  */
+  /* Don't use reg_stat[].nonzero_bits when computing it.  This can cause
+     problems when, for example, we have j <<= 1 in a loop.  */
 
   nonzero_sign_valid = 0;
 
@@ -586,6 +672,10 @@ combine_instructions (f, nregs)
   refresh_blocks = sbitmap_alloc (last_basic_block);
   sbitmap_zero (refresh_blocks);
 
+  /* Allocate array of current insn_rtx_costs.  */
+  uid_insn_cost = xcalloc (max_uid_cuid + 1, sizeof (int));
+  last_insn_cost = max_uid_cuid;
+
   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
     {
       uid_cuid[INSN_UID (insn)] = ++i;
@@ -604,9 +694,16 @@ combine_instructions (f, nregs)
              set_nonzero_bits_and_sign_copies (XEXP (links, 0), NULL_RTX,
                                                NULL);
 #endif
+
+         /* Record the current insn_rtx_cost of this instruction.  */
+         if (NONJUMP_INSN_P (insn))
+           uid_insn_cost[INSN_UID (insn)] = insn_rtx_cost (PATTERN (insn));
+         if (dump_file)
+           fprintf(dump_file, "insn_cost %d: %d\n",
+                   INSN_UID (insn), uid_insn_cost[INSN_UID (insn)]);
        }
 
-      if (GET_CODE (insn) == CODE_LABEL)
+      if (LABEL_P (insn))
        label_tick++;
     }
 
@@ -617,18 +714,18 @@ combine_instructions (f, nregs)
   label_tick = 1;
   last_call_cuid = 0;
   mem_last_set = 0;
-  init_reg_last_arrays ();
+  init_reg_last ();
   setup_incoming_promotions ();
 
   FOR_EACH_BB (this_basic_block)
     {
-      for (insn = this_basic_block->head;
-           insn != NEXT_INSN (this_basic_block->end);
+      for (insn = BB_HEAD (this_basic_block);
+           insn != NEXT_INSN (BB_END (this_basic_block));
           insn = next ? next : NEXT_INSN (insn))
        {
          next = 0;
 
-         if (GET_CODE (insn) == CODE_LABEL)
+         if (LABEL_P (insn))
            label_tick++;
 
          else if (INSN_P (insn))
@@ -652,7 +749,7 @@ combine_instructions (f, nregs)
 
                  /* 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)
+                 if (NOTE_P (link))
                    continue;
 
                  for (nextlinks = LOG_LINKS (link);
@@ -672,9 +769,9 @@ combine_instructions (f, nregs)
                 We need this special code because data flow connections
                 via CC0 do not get entered in LOG_LINKS.  */
 
-             if (GET_CODE (insn) == JUMP_INSN
+             if (JUMP_P (insn)
                  && (prev = prev_nonnote_insn (insn)) != 0
-                 && GET_CODE (prev) == INSN
+                 && NONJUMP_INSN_P (prev)
                  && sets_cc0_p (PATTERN (prev)))
                {
                  if ((next = try_combine (insn, prev,
@@ -690,9 +787,9 @@ combine_instructions (f, nregs)
                }
 
              /* Do the same for an insn that explicitly references CC0.  */
-             if (GET_CODE (insn) == INSN
+             if (NONJUMP_INSN_P (insn)
                  && (prev = prev_nonnote_insn (insn)) != 0
-                 && GET_CODE (prev) == INSN
+                 && NONJUMP_INSN_P (prev)
                  && sets_cc0_p (PATTERN (prev))
                  && GET_CODE (PATTERN (insn)) == SET
                  && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (insn))))
@@ -713,11 +810,11 @@ combine_instructions (f, nregs)
                 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
+               if (NONJUMP_INSN_P (XEXP (links, 0))
                    && 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
+                   && NONJUMP_INSN_P (prev)
                    && sets_cc0_p (PATTERN (prev))
                    && (next = try_combine (insn, XEXP (links, 0),
                                            prev, &new_direct_jump_p)) != 0)
@@ -734,7 +831,32 @@ combine_instructions (f, nregs)
                                           &new_direct_jump_p)) != 0)
                    goto retry;
 
-             if (GET_CODE (insn) != NOTE)
+             /* Try this insn with each REG_EQUAL note it links back to.  */
+             for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
+               {
+                 rtx set, note;
+                 rtx temp = XEXP (links, 0);
+                 if ((set = single_set (temp)) != 0
+                     && (note = find_reg_equal_equiv_note (temp)) != 0
+                     && GET_CODE (XEXP (note, 0)) != EXPR_LIST
+                     /* Avoid using a register that may already been marked
+                        dead by an earlier instruction.  */
+                     && ! unmentioned_reg_p (XEXP (note, 0), SET_SRC (set)))
+                   {
+                     /* Temporarily replace the set's source with the
+                        contents of the REG_EQUAL note.  The insn will
+                        be deleted or recognized by try_combine.  */
+                     rtx orig = SET_SRC (set);
+                     SET_SRC (set) = XEXP (note, 0);
+                     next = try_combine (insn, temp, NULL_RTX,
+                                         &new_direct_jump_p);
+                     if (next)
+                       goto retry;
+                     SET_SRC (set) = orig;
+                   }
+               }
+
+             if (!NOTE_P (insn))
                record_dead_and_set_regs (insn);
 
            retry:
@@ -747,7 +869,7 @@ combine_instructions (f, nregs)
   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);
+  delete_noop_moves ();
 
   update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
                                    PROP_DEATH_NOTES | PROP_SCAN_DEAD_CODE
@@ -755,17 +877,8 @@ combine_instructions (f, nregs)
 
   /* Clean up.  */
   sbitmap_free (refresh_blocks);
-  free (reg_nonzero_bits);
-  free (reg_sign_bit_copies);
-  free (reg_last_death);
-  free (reg_last_set);
-  free (reg_last_set_value);
-  free (reg_last_set_table_tick);
-  free (reg_last_set_label);
-  free (reg_last_set_invalid);
-  free (reg_last_set_mode);
-  free (reg_last_set_nonzero_bits);
-  free (reg_last_set_sign_bit_copies);
+  free (uid_insn_cost);
+  free (reg_stat);
   free (uid_cuid);
 
   {
@@ -784,6 +897,7 @@ combine_instructions (f, nregs)
   total_successes += combine_successes;
 
   nonzero_sign_valid = 0;
+  rtl_hooks = general_rtl_hooks;
 
   /* Make recognizer allow volatile MEMs again.  */
   init_recog ();
@@ -791,53 +905,43 @@ combine_instructions (f, nregs)
   return new_direct_jump_p;
 }
 
-/* Wipe the reg_last_xxx arrays in preparation for another pass.  */
+/* Wipe the last_xxx fields of reg_stat in preparation for another pass.  */
 
 static void
-init_reg_last_arrays ()
+init_reg_last (void)
 {
-  unsigned int nregs = combine_max_regno;
-
-  memset ((char *) reg_last_death, 0, nregs * sizeof (rtx));
-  memset ((char *) reg_last_set, 0, nregs * sizeof (rtx));
-  memset ((char *) reg_last_set_value, 0, nregs * sizeof (rtx));
-  memset ((char *) reg_last_set_table_tick, 0, nregs * sizeof (int));
-  memset ((char *) reg_last_set_label, 0, nregs * sizeof (int));
-  memset (reg_last_set_invalid, 0, nregs * sizeof (char));
-  memset ((char *) reg_last_set_mode, 0, nregs * sizeof (enum machine_mode));
-  memset ((char *) reg_last_set_nonzero_bits, 0, nregs * sizeof (HOST_WIDE_INT));
-  memset (reg_last_set_sign_bit_copies, 0, nregs * sizeof (char));
+  unsigned int i;
+  for (i = 0; i < combine_max_regno; i++)
+    memset (reg_stat + i, 0, offsetof (struct reg_stat, sign_bit_copies));
 }
 \f
 /* Set up any promoted values for incoming argument registers.  */
 
 static void
-setup_incoming_promotions ()
+setup_incoming_promotions (void)
 {
-#ifdef PROMOTE_FUNCTION_ARGS
   unsigned int regno;
   rtx reg;
   enum machine_mode mode;
   int unsignedp;
   rtx first = get_insns ();
 
-#ifndef OUTGOING_REGNO
-#define OUTGOING_REGNO(N) N
-#endif
-  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-    /* Check whether this register can hold an incoming pointer
-       argument.  FUNCTION_ARG_REGNO_P tests outgoing register
-       numbers, so translate if necessary due to register windows.  */
-    if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (regno))
-       && (reg = promoted_input_arg (regno, &mode, &unsignedp)) != 0)
-      {
-       record_value_for_reg
-         (reg, first, gen_rtx_fmt_e ((unsignedp ? ZERO_EXTEND
-                                      : SIGN_EXTEND),
-                                     GET_MODE (reg),
-                                     gen_rtx_CLOBBER (mode, const0_rtx)));
-      }
-#endif
+  if (targetm.calls.promote_function_args (TREE_TYPE (cfun->decl)))
+    {
+      for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
+       /* Check whether this register can hold an incoming pointer
+          argument.  FUNCTION_ARG_REGNO_P tests outgoing register
+          numbers, so translate if necessary due to register windows.  */
+       if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (regno))
+           && (reg = promoted_input_arg (regno, &mode, &unsignedp)) != 0)
+         {
+           record_value_for_reg
+             (reg, first, gen_rtx_fmt_e ((unsignedp ? ZERO_EXTEND
+                                          : SIGN_EXTEND),
+                                         GET_MODE (reg),
+                                         gen_rtx_CLOBBER (mode, const0_rtx)));
+         }
+    }
 }
 \f
 /* Called via note_stores.  If X is a pseudo that is narrower than
@@ -852,14 +956,12 @@ setup_incoming_promotions ()
    by any set of X.  */
 
 static void
-set_nonzero_bits_and_sign_copies (x, set, data)
-     rtx x;
-     rtx set;
-     void *data ATTRIBUTE_UNUSED;
+set_nonzero_bits_and_sign_copies (rtx x, rtx set,
+                                 void *data ATTRIBUTE_UNUSED)
 {
   unsigned int num;
 
-  if (GET_CODE (x) == REG
+  if (REG_P (x)
       && REGNO (x) >= FIRST_PSEUDO_REGISTER
       /* If this register is undefined at the start of the file, we can't
         say what its contents were.  */
@@ -868,8 +970,8 @@ set_nonzero_bits_and_sign_copies (x, set, data)
     {
       if (set == 0 || GET_CODE (set) == CLOBBER)
        {
-         reg_nonzero_bits[REGNO (x)] = GET_MODE_MASK (GET_MODE (x));
-         reg_sign_bit_copies[REGNO (x)] = 1;
+         reg_stat[REGNO (x)].nonzero_bits = GET_MODE_MASK (GET_MODE (x));
+         reg_stat[REGNO (x)].sign_bit_copies = 1;
          return;
        }
 
@@ -891,7 +993,7 @@ set_nonzero_bits_and_sign_copies (x, set, data)
 #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
          /* If X is narrower than a word and SRC is a non-negative
             constant that would appear negative in the mode of X,
-            sign-extend it for use in reg_nonzero_bits because some
+            sign-extend it for use in reg_stat[].nonzero_bits because some
             machines (maybe most) will actually do the sign-extension
             and this is the conservative approach.
 
@@ -910,18 +1012,18 @@ set_nonzero_bits_and_sign_copies (x, set, data)
 #endif
 
          /* Don't call nonzero_bits if it cannot change anything.  */
-         if (reg_nonzero_bits[REGNO (x)] != ~(unsigned HOST_WIDE_INT) 0)
-           reg_nonzero_bits[REGNO (x)]
+         if (reg_stat[REGNO (x)].nonzero_bits != ~(unsigned HOST_WIDE_INT) 0)
+           reg_stat[REGNO (x)].nonzero_bits
              |= nonzero_bits (src, nonzero_bits_mode);
          num = num_sign_bit_copies (SET_SRC (set), GET_MODE (x));
-         if (reg_sign_bit_copies[REGNO (x)] == 0
-             || reg_sign_bit_copies[REGNO (x)] > num)
-           reg_sign_bit_copies[REGNO (x)] = num;
+         if (reg_stat[REGNO (x)].sign_bit_copies == 0
+             || reg_stat[REGNO (x)].sign_bit_copies > num)
+           reg_stat[REGNO (x)].sign_bit_copies = num;
        }
       else
        {
-         reg_nonzero_bits[REGNO (x)] = GET_MODE_MASK (GET_MODE (x));
-         reg_sign_bit_copies[REGNO (x)] = 1;
+         reg_stat[REGNO (x)].nonzero_bits = GET_MODE_MASK (GET_MODE (x));
+         reg_stat[REGNO (x)].sign_bit_copies = 1;
        }
     }
 }
@@ -937,12 +1039,8 @@ set_nonzero_bits_and_sign_copies (x, set, data)
    will return 1.  */
 
 static int
-can_combine_p (insn, i3, pred, succ, pdest, psrc)
-     rtx insn;
-     rtx i3;
-     rtx pred ATTRIBUTE_UNUSED;
-     rtx succ;
-     rtx *pdest, *psrc;
+can_combine_p (rtx insn, rtx i3, rtx pred ATTRIBUTE_UNUSED, rtx succ,
+              rtx *pdest, rtx *psrc)
 {
   int i;
   rtx set = 0, src, dest;
@@ -977,6 +1075,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
       for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
        {
          rtx elt = XVECEXP (PATTERN (insn), 0, i);
+         rtx note;
 
          switch (GET_CODE (elt))
            {
@@ -996,7 +1095,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
                 something to tell them apart, e.g. different modes.  For
                 now, we forgo such complicated tests and simply disallow
                 combining of USES of pseudo registers with any other USE.  */
-             if (GET_CODE (XEXP (elt, 0)) == REG
+             if (REG_P (XEXP (elt, 0))
                  && GET_CODE (PATTERN (i3)) == PARALLEL)
                {
                  rtx i3pat = PATTERN (i3);
@@ -1008,7 +1107,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
                      rtx i3elt = XVECEXP (i3pat, 0, i);
 
                      if (GET_CODE (i3elt) == USE
-                         && GET_CODE (XEXP (i3elt, 0)) == REG
+                         && REG_P (XEXP (i3elt, 0))
                          && (REGNO (XEXP (i3elt, 0)) == regno
                              ? reg_set_between_p (XEXP (elt, 0),
                                                   PREV_INSN (insn), i3)
@@ -1027,6 +1126,8 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
              /* Ignore SETs whose result isn't used but not those that
                 have side-effects.  */
              if (find_reg_note (insn, REG_UNUSED, SET_DEST (elt))
+                 && (!(note = find_reg_note (insn, REG_EH_REGION, NULL_RTX))
+                     || INTVAL (XEXP (note, 0)) <= 0)
                  && ! side_effects_p (elt))
                break;
 
@@ -1069,9 +1170,9 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
       /* Can't merge a function call.  */
       || GET_CODE (src) == CALL
       /* Don't eliminate a function call argument.  */
-      || (GET_CODE (i3) == CALL_INSN
+      || (CALL_P (i3)
          && (find_reg_fusage (i3, USE, dest)
-             || (GET_CODE (dest) == REG
+             || (REG_P (dest)
                  && REGNO (dest) < FIRST_PSEUDO_REGISTER
                  && global_regs[REGNO (dest)])))
       /* Don't substitute into an incremented register.  */
@@ -1092,13 +1193,13 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
         does not use any registers whose values alter in between.  However,
         If the insns are adjacent, a use can't cross a set even though we
         think it might (this can happen for a sequence of insns each setting
-        the same destination; reg_last_set of that register might point to
+        the same destination; last_set of that register might point to
         a NOTE).  If INSN has a REG_EQUIV note, the register is always
         equivalent to the memory so the substitution is valid even if there
         are intervening stores.  Also, don't move a volatile asm or
         UNSPEC_VOLATILE across any other insns.  */
       || (! all_adjacent
-         && (((GET_CODE (src) != MEM
+         && (((!MEM_P (src)
                || ! find_reg_note (insn, REG_EQUIV, src))
               && use_crosses_set_p (src, INSN_CUID (insn)))
              || (GET_CODE (src) == ASM_OPERANDS && MEM_VOLATILE_P (src))
@@ -1116,7 +1217,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
     return 0;
 
   /* DEST must either be a REG or CC0.  */
-  if (GET_CODE (dest) == REG)
+  if (REG_P (dest))
     {
       /* If register alignment is being enforced for multi-word items in all
         cases except for parameters, it is possible to have a register copy
@@ -1127,7 +1228,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
         Also, on some machines we don't want to extend the life of a hard
         register.  */
 
-      if (GET_CODE (src) == REG
+      if (REG_P (src)
          && ((REGNO (dest) < FIRST_PSEUDO_REGISTER
               && ! HARD_REGNO_MODE_OK (REGNO (dest), GET_MODE (dest)))
              /* Don't extend the life of a hard register unless it is
@@ -1144,16 +1245,30 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
   else if (GET_CODE (dest) != CC0)
     return 0;
 
-  /* Don't substitute for a register intended as a clobberable operand.
-     Similarly, don't substitute an expression containing a register that
-     will be clobbered in I3.  */
+
   if (GET_CODE (PATTERN (i3)) == PARALLEL)
     for (i = XVECLEN (PATTERN (i3), 0) - 1; i >= 0; i--)
-      if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER
-         && (reg_overlap_mentioned_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0),
-                                      src)
-             || rtx_equal_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0), dest)))
-       return 0;
+      if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER)
+       {
+          /* Don't substitute for a register intended as a clobberable
+            operand. */
+         rtx reg = XEXP (XVECEXP (PATTERN (i3), 0, i), 0);
+         if (rtx_equal_p (reg, dest))
+           return 0;
+
+         /* If the clobber represents an earlyclobber operand, we must not
+            substitute an expression containing the clobbered register.
+            As we do not analyse the constraint strings here, we have to
+            make the conservative assumption.  However, if the register is
+            a fixed hard reg, the clobber cannot represent any operand;
+            we leave it up to the machine description to either accept or
+            reject use-and-clobber patterns.  */
+         if (!REG_P (reg)
+             || REGNO (reg) >= FIRST_PSEUDO_REGISTER
+             || !fixed_regs[REGNO (reg)])
+           if (reg_overlap_mentioned_p (reg, src))
+             return 0;
+       }
 
   /* If INSN contains anything volatile, or is an `asm' (whether volatile
      or not), reject, unless nothing volatile comes between it and I3 */
@@ -1173,7 +1288,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
      to be an explicit register variable, and was chosen for a reason.  */
 
   if (GET_CODE (src) == ASM_OPERANDS
-      && GET_CODE (dest) == REG && REGNO (dest) < FIRST_PSEUDO_REGISTER)
+      && REG_P (dest) && REGNO (dest) < FIRST_PSEUDO_REGISTER)
     return 0;
 
   /* If there are any volatile insns between INSN and I3, reject, because
@@ -1192,7 +1307,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
 #ifdef AUTO_INC_DEC
   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
     if (REG_NOTE_KIND (link) == REG_INC
-       && (GET_CODE (i3) == JUMP_INSN
+       && (JUMP_P (i3)
            || reg_used_between_p (XEXP (link, 0), insn, i3)
            || reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i3))))
       return 0;
@@ -1209,7 +1324,7 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
      but that would be much slower, and this ought to be equivalent.  */
 
   p = prev_nonnote_insn (insn);
-  if (p && p != pred && GET_CODE (p) == INSN && sets_cc0_p (PATTERN (p))
+  if (p && p != pred && NONJUMP_INSN_P (p) && sets_cc0_p (PATTERN (p))
       && ! all_adjacent)
     return 0;
 #endif
@@ -1223,46 +1338,6 @@ can_combine_p (insn, i3, pred, succ, pdest, psrc)
   return 1;
 }
 \f
-/* Check if PAT is an insn - or a part of it - used to set up an
-   argument for a function in a hard register.  */
-
-static int
-sets_function_arg_p (pat)
-     rtx pat;
-{
-  int i;
-  rtx inner_dest;
-
-  switch (GET_CODE (pat))
-    {
-    case INSN:
-      return sets_function_arg_p (PATTERN (pat));
-
-    case PARALLEL:
-      for (i = XVECLEN (pat, 0); --i >= 0;)
-       if (sets_function_arg_p (XVECEXP (pat, 0, i)))
-         return 1;
-
-      break;
-
-    case SET:
-      inner_dest = SET_DEST (pat);
-      while (GET_CODE (inner_dest) == STRICT_LOW_PART
-            || GET_CODE (inner_dest) == SUBREG
-            || GET_CODE (inner_dest) == ZERO_EXTRACT)
-       inner_dest = XEXP (inner_dest, 0);
-
-      return (GET_CODE (inner_dest) == REG
-             && REGNO (inner_dest) < FIRST_PSEUDO_REGISTER
-             && FUNCTION_ARG_REGNO_P (REGNO (inner_dest)));
-
-    default:
-      break;
-    }
-
-  return 0;
-}
-
 /* LOC is the location within I3 that contains its pattern or the component
    of a PARALLEL of the pattern.  We validate that it is valid for combining.
 
@@ -1301,13 +1376,8 @@ sets_function_arg_p (pat)
    Return 1 if the combination is valid, zero otherwise.  */
 
 static int
-combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed)
-     rtx i3;
-     rtx *loc;
-     rtx i2dest;
-     rtx i1dest;
-     int i1_not_in_src;
-     rtx *pi3dest_killed;
+combinable_i3pat (rtx i3, rtx *loc, rtx i2dest, rtx i1dest,
+                 int i1_not_in_src, rtx *pi3dest_killed)
 {
   rtx x = *loc;
 
@@ -1323,9 +1393,14 @@ combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed)
             || GET_CODE (inner_dest) == ZERO_EXTRACT)
        inner_dest = XEXP (inner_dest, 0);
 
-      /* Check for the case where I3 modifies its output, as
-        discussed above.  */
-      if ((inner_dest != dest
+      /* Check for the case where I3 modifies its output, as discussed
+        above.  We don't want to prevent pseudos from being combined
+        into the address of a MEM, so only prevent the combination if
+        i1 or i2 set the same MEM.  */
+      if ((inner_dest != dest &&
+          (!MEM_P (inner_dest)
+           || rtx_equal_p (i2dest, inner_dest)
+           || (i1dest && rtx_equal_p (i1dest, inner_dest)))
           && (reg_overlap_mentioned_p (i2dest, inner_dest)
               || (i1dest && reg_overlap_mentioned_p (i1dest, inner_dest))))
 
@@ -1339,7 +1414,7 @@ combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed)
             function argument; the all_adjacent test in can_combine_p also
             checks this; here, we do a more specific test for this case.  */
 
-         || (GET_CODE (inner_dest) == REG
+         || (REG_P (inner_dest)
              && REGNO (inner_dest) < FIRST_PSEUDO_REGISTER
              && (! HARD_REGNO_MODE_OK (REGNO (inner_dest),
                                        GET_MODE (inner_dest))))
@@ -1351,7 +1426,7 @@ combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed)
         Never add REG_DEAD notes for the FRAME_POINTER_REGNUM or the
         STACK_POINTER_REGNUM, since these are always considered to be
         live.  Similarly for ARG_POINTER_REGNUM if it is fixed.  */
-      if (pi3dest_killed && GET_CODE (dest) == REG
+      if (pi3dest_killed && REG_P (dest)
          && reg_referenced_p (dest, PATTERN (i3))
          && REGNO (dest) != FRAME_POINTER_REGNUM
 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
@@ -1387,8 +1462,7 @@ combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed)
    and division.  We don't count multiplications by powers of two here.  */
 
 static int
-contains_muldiv (x)
-     rtx x;
+contains_muldiv (rtx x)
 {
   switch (GET_CODE (x))
     {
@@ -1399,18 +1473,14 @@ contains_muldiv (x)
       return ! (GET_CODE (XEXP (x, 1)) == CONST_INT
                && exact_log2 (INTVAL (XEXP (x, 1))) >= 0);
     default:
-      switch (GET_RTX_CLASS (GET_CODE (x)))
-       {
-       case 'c':  case '<':  case '2':
-         return contains_muldiv (XEXP (x, 0))
+      if (BINARY_P (x))
+       return contains_muldiv (XEXP (x, 0))
            || contains_muldiv (XEXP (x, 1));
 
-       case '1':
-         return contains_muldiv (XEXP (x, 0));
+      if (UNARY_P (x))
+       return contains_muldiv (XEXP (x, 0));
 
-       default:
-         return 0;
-       }
+      return 0;
     }
 }
 \f
@@ -1419,8 +1489,7 @@ contains_muldiv (x)
    can't perform combinations.  */
 
 static int
-cant_combine_insn_p (insn)
-     rtx insn;
+cant_combine_insn_p (rtx insn)
 {
   rtx set;
   rtx src, dest;
@@ -1459,6 +1528,33 @@ cant_combine_insn_p (insn)
   return 0;
 }
 
+/* Adjust INSN after we made a change to its destination.
+
+   Changing the destination can invalidate notes that say something about
+   the results of the insn and a LOG_LINK pointing to the insn.  */
+
+static void
+adjust_for_new_dest (rtx insn)
+{
+  rtx *loc;
+
+  /* For notes, be conservative and simply remove them.  */
+  loc = &REG_NOTES (insn);
+  while (*loc)
+    {
+      enum reg_note kind = REG_NOTE_KIND (*loc);
+      if (kind == REG_EQUAL || kind == REG_EQUIV)
+       *loc = XEXP (*loc, 1);
+      else
+       loc = &XEXP (*loc, 1);
+    }
+
+  /* The new insn will have a destination that was previously the destination
+     of an insn just above it.  Call distribute_links to make a LOG_LINK from
+     the next use of that destination.  */
+  distribute_links (gen_rtx_INSN_LIST (VOIDmode, insn, NULL_RTX));
+}
+
 /* Try to combine the insns I1 and I2 into I3.
    Here I1 and I2 appear earlier than I3.
    I1 can be zero; then we combine just I2 into I3.
@@ -1476,9 +1572,7 @@ cant_combine_insn_p (insn)
    new direct jump instruction.  */
 
 static rtx
-try_combine (i3, i2, i1, new_direct_jump_p)
-     rtx i3, i2, i1;
-     int *new_direct_jump_p;
+try_combine (rtx i3, rtx i2, rtx i1, int *new_direct_jump_p)
 {
   /* New patterns for I3 and I2, respectively.  */
   rtx newpat, newi2pat = 0;
@@ -1487,7 +1581,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
   int added_sets_1, added_sets_2;
   /* Total number of SETs to put into I3.  */
   int total_sets;
-  /* Nonzero is I2's body now appears in I3.  */
+  /* Nonzero if I2's body now appears in I3.  */
   int i2_is_used;
   /* INSN_CODEs for new I3, new I2, and user of condition code.  */
   int insn_code_number, i2_code_number = 0, other_code_number = 0;
@@ -1508,6 +1602,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
   int i3_subst_into_i2 = 0;
   /* Notes that I1, I2 or I3 is a MULT operation.  */
   int have_mult = 0;
+  int swap_i2i3 = 0;
 
   int maxreg;
   rtx temp;
@@ -1559,8 +1654,8 @@ try_combine (i3, i2, i1, new_direct_jump_p)
      where I2 and I3 are adjacent to avoid making difficult register
      usage tests.  */
 
-  if (i1 == 0 && GET_CODE (i3) == INSN && GET_CODE (PATTERN (i3)) == SET
-      && GET_CODE (SET_SRC (PATTERN (i3))) == REG
+  if (i1 == 0 && NONJUMP_INSN_P (i3) && GET_CODE (PATTERN (i3)) == SET
+      && REG_P (SET_SRC (PATTERN (i3)))
       && REGNO (SET_SRC (PATTERN (i3))) >= FIRST_PSEUDO_REGISTER
       && find_reg_note (i3, REG_DEAD, SET_SRC (PATTERN (i3)))
       && GET_CODE (PATTERN (i2)) == PARALLEL
@@ -1627,7 +1722,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
       && (temp = single_set (i2)) != 0
       && (GET_CODE (SET_SRC (temp)) == CONST_INT
          || GET_CODE (SET_SRC (temp)) == CONST_DOUBLE)
-      && GET_CODE (SET_DEST (temp)) == REG
+      && REG_P (SET_DEST (temp))
       && GET_MODE_CLASS (GET_MODE (SET_DEST (temp))) == MODE_INT
       && GET_MODE_SIZE (GET_MODE (SET_DEST (temp))) == 2 * UNITS_PER_WORD
       && GET_CODE (PATTERN (i3)) == SET
@@ -1712,7 +1807,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
       && GET_CODE (SET_SRC (XVECEXP (PATTERN (i2), 0, 0))) == COMPARE
       && XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 1) == const0_rtx
       && GET_CODE (XVECEXP (PATTERN (i2), 0, 1)) == SET
-      && GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, 1))) == REG
+      && REG_P (SET_DEST (XVECEXP (PATTERN (i2), 0, 1)))
       && rtx_equal_p (XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 0),
                      SET_SRC (XVECEXP (PATTERN (i2), 0, 1))))
     {
@@ -1728,7 +1823,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
             as I2 will not cause a problem.  */
 
          i1 = gen_rtx_INSN (VOIDmode, INSN_UID (i2), NULL_RTX, i2,
-                            BLOCK_FOR_INSN (i2), INSN_SCOPE (i2),
+                            BLOCK_FOR_INSN (i2), INSN_LOCATOR (i2),
                             XVECEXP (PATTERN (i2), 0, 1), -1, NULL_RTX,
                             NULL_RTX);
 
@@ -1784,8 +1879,8 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 
 #if 0
   if (!(GET_CODE (PATTERN (i3)) == SET
-       && GET_CODE (SET_SRC (PATTERN (i3))) == REG
-       && GET_CODE (SET_DEST (PATTERN (i3))) == MEM
+       && REG_P (SET_SRC (PATTERN (i3)))
+       && MEM_P (SET_DEST (PATTERN (i3)))
        && (GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_INC
            || GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_DEC)))
     /* It's not the exception.  */
@@ -1857,9 +1952,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 
   if (flag_expensive_optimizations)
     {
-      /* Pass pc_rtx so no substitutions are done, just simplifications.
-        The cases that we are interested in here do not involve the few
-        cases were is_replaced is checked.  */
+      /* Pass pc_rtx so no substitutions are done, just simplifications.  */
       if (i1)
        {
          subst_low_cuid = INSN_CUID (i1);
@@ -1889,7 +1982,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
       && XEXP (SET_SRC (PATTERN (i3)), 1) == const0_rtx
       && rtx_equal_p (XEXP (SET_SRC (PATTERN (i3)), 0), i2dest))
     {
-#ifdef EXTRA_CC_MODES
+#ifdef SELECT_CC_MODE
       rtx *cc_use;
       enum machine_mode compare_mode;
 #endif
@@ -1899,7 +1992,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 
       i2_is_used = 1;
 
-#ifdef EXTRA_CC_MODES
+#ifdef SELECT_CC_MODE
       /* See if a COMPARE with the operand we substituted in should be done
         with the mode that is currently being used.  If not, do the same
         processing we do in `subst' for a SET; namely, if the destination
@@ -2048,38 +2141,69 @@ try_combine (i3, i2, i1, new_direct_jump_p)
   insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
 
   /* If the result isn't valid, see if it is a PARALLEL of two SETs where
-     the second SET's destination is a register that is unused.  In that case,
+     the second SET's destination is a register that is unused and isn't
+     marked as an instruction that might trap in an EH region.  In that case,
      we just need the first SET.   This can occur when simplifying a divmod
      insn.  We *must* test for this case here because the code below that
      splits two independent SETs doesn't handle this case correctly when it
-     updates the register status.  Also check the case where the first
-     SET's destination is unused.  That would not cause incorrect code, but
-     does cause an unneeded insn to remain.  */
+     updates the register status.
+
+     It's pointless doing this if we originally had two sets, one from
+     i3, and one from i2.  Combining then splitting the parallel results
+     in the original i2 again plus an invalid insn (which we delete).
+     The net effect is only to move instructions around, which makes
+     debug info less accurate.
+
+     Also check the case where the first SET's destination is unused.
+     That would not cause incorrect code, but does cause an unneeded
+     insn to remain.  */
 
-  if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL
+  if (insn_code_number < 0
+      && !(added_sets_2 && i1 == 0)
+      && GET_CODE (newpat) == PARALLEL
       && XVECLEN (newpat, 0) == 2
       && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
       && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
-      && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) == REG
-      && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 1)))
-      && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 1)))
       && asm_noperands (newpat) < 0)
     {
-      newpat = XVECEXP (newpat, 0, 0);
-      insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
-    }
+      rtx set0 = XVECEXP (newpat, 0, 0);
+      rtx set1 = XVECEXP (newpat, 0, 1);
+      rtx note;
 
-  else if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL
-          && XVECLEN (newpat, 0) == 2
-          && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
-          && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
-          && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) == REG
-          && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 0)))
-          && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 0)))
-          && asm_noperands (newpat) < 0)
-    {
-      newpat = XVECEXP (newpat, 0, 1);
-      insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
+      if (((REG_P (SET_DEST (set1))
+           && find_reg_note (i3, REG_UNUSED, SET_DEST (set1)))
+          || (GET_CODE (SET_DEST (set1)) == SUBREG
+              && find_reg_note (i3, REG_UNUSED, SUBREG_REG (SET_DEST (set1)))))
+         && (!(note = find_reg_note (i3, REG_EH_REGION, NULL_RTX))
+             || INTVAL (XEXP (note, 0)) <= 0)
+         && ! side_effects_p (SET_SRC (set1)))
+       {
+         newpat = set0;
+         insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
+       }
+
+      else if (((REG_P (SET_DEST (set0))
+                && find_reg_note (i3, REG_UNUSED, SET_DEST (set0)))
+               || (GET_CODE (SET_DEST (set0)) == SUBREG
+                   && find_reg_note (i3, REG_UNUSED,
+                                     SUBREG_REG (SET_DEST (set0)))))
+              && (!(note = find_reg_note (i3, REG_EH_REGION, NULL_RTX))
+                  || INTVAL (XEXP (note, 0)) <= 0)
+              && ! side_effects_p (SET_SRC (set0)))
+       {
+         newpat = set1;
+         insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
+
+         if (insn_code_number >= 0)
+           {
+             /* If we will be able to accept this, we have made a
+                change to the destination of I3.  This requires us to
+                do a few adjustments.  */
+
+             PATTERN (i3) = newpat;
+             adjust_for_new_dest (i3);
+           }
+       }
     }
 
   /* If we were combining three insns and the result is a simple SET
@@ -2113,7 +2237,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
             we can change its mode.  */
          if (GET_MODE (SET_DEST (newpat)) != GET_MODE (i2dest)
              && GET_MODE (SET_DEST (newpat)) != VOIDmode
-             && GET_CODE (i2dest) == REG
+             && REG_P (i2dest)
              && (REGNO (i2dest) < FIRST_PSEUDO_REGISTER
                  || (REG_N_SETS (REGNO (i2dest)) == 1 && ! added_sets_2
                      && ! REG_USERVAR_P (i2dest))))
@@ -2197,8 +2321,8 @@ try_combine (i3, i2, i1, new_direct_jump_p)
                     || GET_CODE (new_i2_dest) == SUBREG)
                new_i2_dest = XEXP (new_i2_dest, 0);
 
-             if (GET_CODE (new_i3_dest) == REG
-                 && GET_CODE (new_i2_dest) == REG
+             if (REG_P (new_i3_dest)
+                 && REG_P (new_i2_dest)
                  && REGNO (new_i3_dest) == REGNO (new_i2_dest))
                REG_N_SETS (REGNO (new_i2_dest))++;
            }
@@ -2209,7 +2333,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
         are set between I2 and I3.  */
       if (insn_code_number < 0 && (split = find_split_point (&newpat, i3)) != 0
 #ifdef HAVE_cc0
-         && GET_CODE (i2dest) == REG
+         && REG_P (i2dest)
 #endif
          /* We need I2DEST in the proper mode.  If it is a hard register
             or the only use of a pseudo, we can change its mode.  */
@@ -2256,7 +2380,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 #ifdef INSN_SCHEDULING
          /* 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)
+         if (split_code == SUBREG && MEM_P (SUBREG_REG (*split)))
            {
 #ifdef LOAD_EXTEND_OP
              /* Or as a SIGN_EXTEND if LOAD_EXTEND_OP says that that's
@@ -2313,19 +2437,19 @@ try_combine (i3, i2, i1, new_direct_jump_p)
           && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != ZERO_EXTRACT
           && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != STRICT_LOW_PART
           && ! (temp = SET_DEST (XVECEXP (newpat, 0, 1)),
-                (GET_CODE (temp) == REG
-                 && reg_nonzero_bits[REGNO (temp)] != 0
+                (REG_P (temp)
+                 && reg_stat[REGNO (temp)].nonzero_bits != 0
                  && GET_MODE_BITSIZE (GET_MODE (temp)) < BITS_PER_WORD
                  && GET_MODE_BITSIZE (GET_MODE (temp)) < HOST_BITS_PER_INT
-                 && (reg_nonzero_bits[REGNO (temp)]
+                 && (reg_stat[REGNO (temp)].nonzero_bits
                      != GET_MODE_MASK (word_mode))))
           && ! (GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) == SUBREG
                 && (temp = SUBREG_REG (SET_DEST (XVECEXP (newpat, 0, 1))),
-                    (GET_CODE (temp) == REG
-                     && reg_nonzero_bits[REGNO (temp)] != 0
+                    (REG_P (temp)
+                     && reg_stat[REGNO (temp)].nonzero_bits != 0
                      && GET_MODE_BITSIZE (GET_MODE (temp)) < BITS_PER_WORD
                      && GET_MODE_BITSIZE (GET_MODE (temp)) < HOST_BITS_PER_INT
-                     && (reg_nonzero_bits[REGNO (temp)]
+                     && (reg_stat[REGNO (temp)].nonzero_bits
                          != GET_MODE_MASK (word_mode)))))
           && ! reg_overlap_mentioned_p (SET_DEST (XVECEXP (newpat, 0, 1)),
                                         SET_SRC (XVECEXP (newpat, 0, 1)))
@@ -2338,54 +2462,14 @@ try_combine (i3, i2, i1, new_direct_jump_p)
       ni2dest = SET_DEST (XVECEXP (newpat, 0, 0));
       newpat = XVECEXP (newpat, 0, 1);
       SUBST (SET_SRC (newpat),
-            gen_lowpart_for_combine (GET_MODE (SET_SRC (newpat)), ni2dest));
+            gen_lowpart (GET_MODE (SET_SRC (newpat)), ni2dest));
       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
 
       if (i2_code_number >= 0)
        insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
 
       if (insn_code_number >= 0)
-       {
-         rtx insn;
-         rtx link;
-
-         /* If we will be able to accept this, we have made a change to the
-            destination of I3.  This can invalidate a LOG_LINKS pointing
-            to I3.  No other part of combine.c makes such a transformation.
-
-            The new I3 will have a destination that was previously the
-            destination of I1 or I2 and which was used in i2 or I3.  Call
-            distribute_links to make a LOG_LINK from the next use of
-            that destination.  */
-
-         PATTERN (i3) = newpat;
-         distribute_links (gen_rtx_INSN_LIST (VOIDmode, i3, NULL_RTX));
-
-         /* I3 now uses what used to be its destination and which is
-            now I2's destination.  That means we need a LOG_LINK from
-            I3 to I2.  But we used to have one, so we still will.
-
-            However, some later insn might be using I2's dest and have
-            a LOG_LINK pointing at I3.  We must remove this link.
-            The simplest way to remove the link is to point it at I1,
-            which we know will be a NOTE.  */
-
-         for (insn = NEXT_INSN (i3);
-              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)))
-               {
-                 for (link = LOG_LINKS (insn); link;
-                      link = XEXP (link, 1))
-                   if (XEXP (link, 0) == i3)
-                     XEXP (link, 0) = i1;
-
-                 break;
-               }
-           }
-       }
+       swap_i2i3 = 1;
     }
 
   /* Similarly, check for a case where we have a PARALLEL of two independent
@@ -2476,7 +2560,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
          if (REG_NOTE_KIND (note) == REG_UNUSED
              && ! reg_set_p (XEXP (note, 0), PATTERN (undobuf.other_insn)))
            {
-             if (GET_CODE (XEXP (note, 0)) == REG)
+             if (REG_P (XEXP (note, 0)))
                REG_N_DEATHS (REGNO (XEXP (note, 0)))--;
 
              remove_note (undobuf.other_insn, note);
@@ -2484,18 +2568,18 @@ try_combine (i3, i2, i1, new_direct_jump_p)
        }
 
       for (note = new_other_notes; note; note = XEXP (note, 1))
-       if (GET_CODE (XEXP (note, 0)) == REG)
+       if (REG_P (XEXP (note, 0)))
          REG_N_DEATHS (REGNO (XEXP (note, 0)))++;
 
       distribute_notes (new_other_notes, undobuf.other_insn,
                        undobuf.other_insn, NULL_RTX);
     }
 #ifdef HAVE_cc0
-  /* If I2 is the setter CC0 and I3 is the user CC0 then check whether
+  /* If I2 is the CC0 setter and I3 is the CC0 user then check whether
      they are adjacent to each other or not.  */
   {
     rtx p = prev_nonnote_insn (i3);
-    if (p && p != i2 && GET_CODE (p) == INSN && newi2pat
+    if (p && p != i2 && NONJUMP_INSN_P (p) && newi2pat
        && sets_cc0_p (newi2pat))
       {
        undo_all ();
@@ -2504,9 +2588,54 @@ try_combine (i3, i2, i1, new_direct_jump_p)
   }
 #endif
 
+  /* Only allow this combination if insn_rtx_costs reports that the
+     replacement instructions are cheaper than the originals.  */
+  if (!combine_validate_cost (i1, i2, i3, newpat, newi2pat))
+    {
+      undo_all ();
+      return 0;
+    }
+
   /* We now know that we can do this combination.  Merge the insns and
      update the status of registers and LOG_LINKS.  */
 
+  if (swap_i2i3)
+    {
+      rtx insn;
+      rtx link;
+      rtx ni2dest;
+
+      /* I3 now uses what used to be its destination and which is now
+         I2's destination.  This requires us to do a few adjustments.  */
+      PATTERN (i3) = newpat;
+      adjust_for_new_dest (i3);
+
+      /* We need a LOG_LINK from I3 to I2.  But we used to have one,
+         so we still will.
+
+        However, some later insn might be using I2's dest and have
+        a LOG_LINK pointing at I3.  We must remove this link.
+        The simplest way to remove the link is to point it at I1,
+        which we know will be a NOTE.  */
+
+      ni2dest = SET_DEST (newi2pat);
+      for (insn = NEXT_INSN (i3);
+          insn && (this_basic_block->next_bb == EXIT_BLOCK_PTR
+                   || insn != BB_HEAD (this_basic_block->next_bb));
+          insn = NEXT_INSN (insn))
+       {
+         if (INSN_P (insn) && reg_referenced_p (ni2dest, PATTERN (insn)))
+           {
+             for (link = LOG_LINKS (insn); link;
+                  link = XEXP (link, 1))
+               if (XEXP (link, 0) == i3)
+                 XEXP (link, 0) = i1;
+
+             break;
+           }
+       }
+    }
+
   {
     rtx i3notes, i2notes, i1notes = 0;
     rtx i3links, i2links, i1links = 0;
@@ -2543,7 +2672,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
     INSN_CODE (i3) = insn_code_number;
     PATTERN (i3) = newpat;
 
-    if (GET_CODE (i3) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (i3))
+    if (CALL_P (i3) && CALL_INSN_FUNCTION_USAGE (i3))
       {
        rtx call_usage = CALL_INSN_FUNCTION_USAGE (i3);
 
@@ -2575,13 +2704,13 @@ try_combine (i3, i2, i1, new_direct_jump_p)
       {
        for (i = 0; i < XVECLEN (PATTERN (i2), 0); i++)
          if (GET_CODE (XVECEXP (PATTERN (i2), 0, i)) != USE
-             && GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, i))) == REG
+             && REG_P (SET_DEST (XVECEXP (PATTERN (i2), 0, i)))
              && SET_DEST (XVECEXP (PATTERN (i2), 0, i)) != i2dest
              && ! find_reg_note (i2, REG_UNUSED,
                                  SET_DEST (XVECEXP (PATTERN (i2), 0, i))))
            for (temp = NEXT_INSN (i2);
                 temp && (this_basic_block->next_bb == EXIT_BLOCK_PTR
-                         || this_basic_block->head != temp);
+                         || BB_HEAD (this_basic_block) != temp);
                 temp = NEXT_INSN (temp))
              if (temp != i3 && INSN_P (temp))
                for (link = LOG_LINKS (temp); link; link = XEXP (link, 1))
@@ -2611,19 +2740,13 @@ try_combine (i3, i2, i1, new_direct_jump_p)
        PATTERN (i2) = newi2pat;
       }
     else
-      {
-       PUT_CODE (i2, NOTE);
-       NOTE_LINE_NUMBER (i2) = NOTE_INSN_DELETED;
-       NOTE_SOURCE_FILE (i2) = 0;
-      }
+      SET_INSN_DELETED (i2);
 
     if (i1)
       {
        LOG_LINKS (i1) = 0;
        REG_NOTES (i1) = 0;
-       PUT_CODE (i1, NOTE);
-       NOTE_LINE_NUMBER (i1) = NOTE_INSN_DELETED;
-       NOTE_SOURCE_FILE (i1) = 0;
+       SET_INSN_DELETED (i1);
       }
 
     /* Get death notes for everything that is now used in either I3 or
@@ -2658,7 +2781,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
     if (newi2pat && new_i2_notes)
       {
        for (temp = new_i2_notes; temp; temp = XEXP (temp, 1))
-         if (GET_CODE (XEXP (temp, 0)) == REG)
+         if (REG_P (XEXP (temp, 0)))
            REG_N_DEATHS (REGNO (XEXP (temp, 0)))++;
 
        distribute_notes (new_i2_notes, i2, i2, NULL_RTX);
@@ -2667,7 +2790,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
     if (new_i3_notes)
       {
        for (temp = new_i3_notes; temp; temp = XEXP (temp, 1))
-         if (GET_CODE (XEXP (temp, 0)) == REG)
+         if (REG_P (XEXP (temp, 0)))
            REG_N_DEATHS (REGNO (XEXP (temp, 0)))++;
 
        distribute_notes (new_i3_notes, i3, i3, NULL_RTX);
@@ -2682,7 +2805,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 
     if (i3dest_killed)
       {
-       if (GET_CODE (i3dest_killed) == REG)
+       if (REG_P (i3dest_killed))
          REG_N_DEATHS (REGNO (i3dest_killed))++;
 
        if (newi2pat && reg_set_p (i3dest_killed, newi2pat))
@@ -2697,7 +2820,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 
     if (i2dest_in_i2src)
       {
-       if (GET_CODE (i2dest) == REG)
+       if (REG_P (i2dest))
          REG_N_DEATHS (REGNO (i2dest))++;
 
        if (newi2pat && reg_set_p (i2dest, newi2pat))
@@ -2710,7 +2833,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 
     if (i1dest_in_i1src)
       {
-       if (GET_CODE (i1dest) == REG)
+       if (REG_P (i1dest))
          REG_N_DEATHS (REGNO (i1dest))++;
 
        if (newi2pat && reg_set_p (i1dest, newi2pat))
@@ -2725,7 +2848,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
     distribute_links (i2links);
     distribute_links (i1links);
 
-    if (GET_CODE (i2dest) == REG)
+    if (REG_P (i2dest))
       {
        rtx link;
        rtx i2_insn = 0, i2_val = 0, set;
@@ -2756,7 +2879,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
          }
       }
 
-    if (i1 && GET_CODE (i1dest) == REG)
+    if (i1 && REG_P (i1dest))
       {
        rtx link;
        rtx i1_insn = 0, i1_val = 0, set;
@@ -2773,9 +2896,10 @@ try_combine (i3, i2, i1, new_direct_jump_p)
          REG_N_SETS (regno)--;
       }
 
-    /* Update reg_nonzero_bits et al for any changes that may have been made
-       to this insn.  The order of set_nonzero_bits_and_sign_copies() is
-       important.  Because newi2pat can affect nonzero_bits of newpat */
+    /* Update reg_stat[].nonzero_bits et al for any changes that may have
+       been made to this insn.  The order of
+       set_nonzero_bits_and_sign_copies() is important.  Because newi2pat
+       can affect nonzero_bits of newpat */
     if (newi2pat)
       note_stores (newi2pat, set_nonzero_bits_and_sign_copies, NULL);
     note_stores (newpat, set_nonzero_bits_and_sign_copies, NULL);
@@ -2790,9 +2914,10 @@ try_combine (i3, i2, i1, new_direct_jump_p)
     if (returnjump_p (i3) || any_uncondjump_p (i3))
       {
        *new_direct_jump_p = 1;
+       mark_jump_label (PATTERN (i3), i3, 0);
 
        if ((temp = next_nonnote_insn (i3)) == NULL_RTX
-           || GET_CODE (temp) != BARRIER)
+           || !BARRIER_P (temp))
          emit_barrier_after (i3);
       }
 
@@ -2803,7 +2928,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
        *new_direct_jump_p = 1;
 
        if ((temp = next_nonnote_insn (undobuf.other_insn)) == NULL_RTX
-           || GET_CODE (temp) != BARRIER)
+           || !BARRIER_P (temp))
          emit_barrier_after (undobuf.other_insn);
       }
 
@@ -2829,7 +2954,7 @@ try_combine (i3, i2, i1, new_direct_jump_p)
 /* Undo all the modifications recorded in undobuf.  */
 
 static void
-undo_all ()
+undo_all (void)
 {
   struct undo *undo, *next;
 
@@ -2852,7 +2977,7 @@ undo_all ()
    of the undos to the free list.  */
 
 static void
-undo_commit ()
+undo_commit (void)
 {
   struct undo *undo, *next;
 
@@ -2874,9 +2999,7 @@ undo_commit ()
    two insns.  */
 
 static rtx *
-find_split_point (loc, insn)
-     rtx *loc;
-     rtx insn;
+find_split_point (rtx *loc, rtx insn)
 {
   rtx x = *loc;
   enum rtx_code code = GET_CODE (x);
@@ -2893,7 +3016,7 @@ find_split_point (loc, insn)
 #ifdef INSN_SCHEDULING
       /* If we are making a paradoxical SUBREG invalid, it becomes a split
         point.  */
-      if (GET_CODE (SUBREG_REG (x)) == MEM)
+      if (MEM_P (SUBREG_REG (x)))
        return loc;
 #endif
       return find_split_point (&SUBREG_REG (x), insn);
@@ -2934,12 +3057,12 @@ find_split_point (loc, insn)
          if (seq
              && NEXT_INSN (seq) != NULL_RTX
              && NEXT_INSN (NEXT_INSN (seq)) == NULL_RTX
-             && GET_CODE (seq) == INSN
+             && NONJUMP_INSN_P (seq)
              && GET_CODE (PATTERN (seq)) == SET
              && SET_DEST (PATTERN (seq)) == reg
              && ! reg_mentioned_p (reg,
                                    SET_SRC (PATTERN (seq)))
-             && GET_CODE (NEXT_INSN (seq)) == INSN
+             && NONJUMP_INSN_P (NEXT_INSN (seq))
              && GET_CODE (PATTERN (NEXT_INSN (seq))) == SET
              && SET_DEST (PATTERN (NEXT_INSN (seq))) == reg
              && memory_address_p (GET_MODE (x),
@@ -2973,10 +3096,9 @@ find_split_point (loc, insn)
             This will occur on machines that just support REG + CONST
             and have a constant moved through some previous computation.  */
 
-         else if (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (x, 0), 0))) != 'o'
+         else if (!OBJECT_P (XEXP (XEXP (x, 0), 0))
                   && ! (GET_CODE (XEXP (XEXP (x, 0), 0)) == SUBREG
-                        && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (XEXP (x, 0), 0))))
-                            == 'o')))
+                        && OBJECT_P (SUBREG_REG (XEXP (XEXP (x, 0), 0)))))
            return &XEXP (XEXP (x, 0), 0);
        }
       break;
@@ -2991,9 +3113,9 @@ find_split_point (loc, insn)
       if (SET_DEST (x) == cc0_rtx
          && GET_CODE (SET_SRC (x)) != COMPARE
          && GET_CODE (SET_SRC (x)) != ZERO_EXTRACT
-         && GET_RTX_CLASS (GET_CODE (SET_SRC (x))) != 'o'
+         && !OBJECT_P (SET_SRC (x))
          && ! (GET_CODE (SET_SRC (x)) == SUBREG
-               && GET_RTX_CLASS (GET_CODE (SUBREG_REG (SET_SRC (x)))) == 'o'))
+               && OBJECT_P (SUBREG_REG (SET_SRC (x)))))
        return &SET_SRC (x);
 #endif
 
@@ -3065,9 +3187,9 @@ find_split_point (loc, insn)
             be better.  */
 
          if (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
-             && GET_CODE (XEXP (SET_SRC (x), 0)) == REG
+             && REG_P (XEXP (SET_SRC (x), 0))
              && (pos = exact_log2 (INTVAL (XEXP (SET_SRC (x), 1)))) >= 7
-             && GET_CODE (SET_DEST (x)) == REG
+             && REG_P (SET_DEST (x))
              && (split = find_single_use (SET_DEST (x), insn, (rtx*) 0)) != 0
              && (GET_CODE (*split) == EQ || GET_CODE (*split) == NE)
              && XEXP (*split, 0) == SET_DEST (x)
@@ -3085,7 +3207,7 @@ find_split_point (loc, insn)
          break;
 
        case NE:
-         /* if STORE_FLAG_VALUE is -1, this is (NE X 0) and only one bit of X
+         /* If STORE_FLAG_VALUE is -1, this is (NE X 0) and only one bit of X
             is known to be on, this can be converted into a NEG of a shift.  */
          if (STORE_FLAG_VALUE == -1 && XEXP (SET_SRC (x), 1) == const0_rtx
              && GET_MODE (SET_SRC (x)) == GET_MODE (XEXP (SET_SRC (x), 0))
@@ -3156,7 +3278,7 @@ find_split_point (loc, insn)
              SUBST (SET_SRC (x),
                     gen_rtx_AND (mode,
                                  gen_rtx_LSHIFTRT
-                                 (mode, gen_lowpart_for_combine (mode, inner),
+                                 (mode, gen_lowpart (mode, inner),
                                   GEN_INT (pos)),
                                  GEN_INT (((HOST_WIDE_INT) 1 << len) - 1)));
 
@@ -3170,7 +3292,7 @@ find_split_point (loc, insn)
                     gen_rtx_fmt_ee
                     (unsignedp ? LSHIFTRT : ASHIFTRT, mode,
                      gen_rtx_ASHIFT (mode,
-                                     gen_lowpart_for_combine (mode, inner),
+                                     gen_lowpart (mode, inner),
                                      GEN_INT (GET_MODE_BITSIZE (mode)
                                               - len - pos)),
                      GEN_INT (GET_MODE_BITSIZE (mode) - len)));
@@ -3184,14 +3306,11 @@ find_split_point (loc, insn)
       /* See if this is a simple operation with a constant as the second
         operand.  It might be that this constant is out of range and hence
         could be used as a split point.  */
-      if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2'
-          || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c'
-          || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<')
+      if (BINARY_P (SET_SRC (x))
          && CONSTANT_P (XEXP (SET_SRC (x), 1))
-         && (GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (x), 0))) == 'o'
+         && (OBJECT_P (XEXP (SET_SRC (x), 0))
              || (GET_CODE (XEXP (SET_SRC (x), 0)) == SUBREG
-                 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (SET_SRC (x), 0))))
-                     == 'o'))))
+                 && OBJECT_P (SUBREG_REG (XEXP (SET_SRC (x), 0))))))
        return &XEXP (SET_SRC (x), 1);
 
       /* Finally, see if this is a simple operation with its first operand
@@ -3199,10 +3318,7 @@ find_split_point (loc, insn)
         register, so return it as a split point.  We can always do this
         because if the first operand were another operation, we would have
         already found it as a split point.  */
-      if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2'
-          || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c'
-          || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<'
-          || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '1')
+      if ((BINARY_P (SET_SRC (x)) || UNARY_P (SET_SRC (x)))
          && ! register_operand (XEXP (SET_SRC (x), 0), VOIDmode))
        return &XEXP (SET_SRC (x), 0);
 
@@ -3242,20 +3358,21 @@ find_split_point (loc, insn)
   /* Otherwise, select our actions depending on our rtx class.  */
   switch (GET_RTX_CLASS (code))
     {
-    case 'b':                  /* This is ZERO_EXTRACT and SIGN_EXTRACT.  */
-    case '3':
+    case RTX_BITFIELD_OPS:             /* This is ZERO_EXTRACT and SIGN_EXTRACT.  */
+    case RTX_TERNARY:
       split = find_split_point (&XEXP (x, 2), insn);
       if (split)
        return split;
       /* ... fall through ...  */
-    case '2':
-    case 'c':
-    case '<':
+    case RTX_BIN_ARITH:
+    case RTX_COMM_ARITH:
+    case RTX_COMPARE:
+    case RTX_COMM_COMPARE:
       split = find_split_point (&XEXP (x, 1), insn);
       if (split)
        return split;
       /* ... fall through ...  */
-    case '1':
+    case RTX_UNARY:
       /* Some machines have (and (shift ...) ...) insns.  If X is not
         an AND, but XEXP (X, 0) is, use it as our split point.  */
       if (GET_CODE (x) != AND && GET_CODE (XEXP (x, 0)) == AND)
@@ -3265,10 +3382,11 @@ find_split_point (loc, insn)
       if (split)
        return split;
       return loc;
-    }
 
-  /* Otherwise, we don't have a split point.  */
-  return 0;
+    default:
+      /* Otherwise, we don't have a split point.  */
+      return 0;
+    }
 }
 \f
 /* Throughout X, replace FROM with TO, and return the result.
@@ -3291,10 +3409,7 @@ find_split_point (loc, insn)
    by copying if `n_occurrences' is nonzero.  */
 
 static rtx
-subst (x, from, to, in_dest, unique_copy)
-     rtx x, from, to;
-     int in_dest;
-     int unique_copy;
+subst (rtx x, rtx from, rtx to, int in_dest, int unique_copy)
 {
   enum rtx_code code = GET_CODE (x);
   enum machine_mode op0_mode = VOIDmode;
@@ -3308,7 +3423,7 @@ subst (x, from, to, in_dest, unique_copy)
 
 #define COMBINE_RTX_EQUAL_P(X,Y)                       \
   ((X) == (Y)                                          \
-   || (GET_CODE (X) == REG && GET_CODE (Y) == REG      \
+   || (REG_P (X) && REG_P (Y)  \
        && REGNO (X) == REGNO (Y) && GET_MODE (X) == GET_MODE (Y)))
 
   if (! in_dest && COMBINE_RTX_EQUAL_P (x, from))
@@ -3324,13 +3439,13 @@ subst (x, from, to, in_dest, unique_copy)
      delete the feeding insn, which is incorrect.
 
      So force this insn not to match in this (rare) case.  */
-  if (! in_dest && code == REG && GET_CODE (from) == REG
+  if (! in_dest && code == REG && REG_P (from)
       && REGNO (x) == REGNO (from))
     return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
 
   /* If this is an object, we are done unless it is a MEM or LO_SUM, both
      of which may contain things that can be combined.  */
-  if (code != MEM && code != LO_SUM && GET_RTX_CLASS (code) == 'o')
+  if (code != MEM && code != LO_SUM && OBJECT_P (x))
     return x;
 
   /* It is possible to have a subexpression appear twice in the insn.
@@ -3368,7 +3483,7 @@ subst (x, from, to, in_dest, unique_copy)
        {
          rtx dest = SET_DEST (XVECEXP (x, 0, i));
 
-         if (GET_CODE (dest) != REG
+         if (!REG_P (dest)
              && GET_CODE (dest) != CC0
              && GET_CODE (dest) != PC)
            {
@@ -3393,7 +3508,7 @@ subst (x, from, to, in_dest, unique_copy)
         where we want to suppress replacing something inside a
         SET_SRC are handled via the IN_DEST operand.  */
       if (code == SET
-         && (GET_CODE (SET_DEST (x)) == REG
+         && (REG_P (SET_DEST (x))
              || GET_CODE (SET_DEST (x)) == CC0
              || GET_CODE (SET_DEST (x)) == PC))
        fmt = "ie";
@@ -3439,7 +3554,7 @@ subst (x, from, to, in_dest, unique_copy)
                  && (code == SUBREG || code == STRICT_LOW_PART
                      || code == ZERO_EXTRACT)
                  && i == 0
-                 && GET_CODE (new) == REG)
+                 && REG_P (new))
                ;
 
              else if (COMBINE_RTX_EQUAL_P (XEXP (x, i), from))
@@ -3471,7 +3586,7 @@ subst (x, from, to, in_dest, unique_copy)
 
 #ifdef CANNOT_CHANGE_MODE_CLASS
                  if (code == SUBREG
-                     && GET_CODE (to) == REG
+                     && REG_P (to)
                      && REGNO (to) < FIRST_PSEUDO_REGISTER
                      && REG_CANNOT_CHANGE_MODE_P (REGNO (to),
                                                   GET_MODE (to),
@@ -3507,7 +3622,9 @@ subst (x, from, to, in_dest, unique_copy)
              if (GET_CODE (new) == CLOBBER && XEXP (new, 0) == const0_rtx)
                return new;
 
-             if (GET_CODE (new) == CONST_INT && GET_CODE (x) == SUBREG)
+             if (GET_CODE (x) == SUBREG
+                 && (GET_CODE (new) == CONST_INT
+                     || GET_CODE (new) == CONST_DOUBLE))
                {
                  enum machine_mode mode = GET_MODE (x);
 
@@ -3540,7 +3657,7 @@ subst (x, from, to, in_dest, unique_copy)
       /* If X is sufficiently simple, don't bother trying to do anything
         with it.  */
       if (code != CONST_INT && code != REG && code != CLOBBER)
-       x = combine_simplify_rtx (x, op0_mode, i == 3, in_dest);
+       x = combine_simplify_rtx (x, op0_mode, in_dest);
 
       if (GET_CODE (x) == code)
        break;
@@ -3559,16 +3676,11 @@ subst (x, from, to, in_dest, unique_copy)
    outer level; call `subst' to simplify recursively.  Return the new
    expression.
 
-   OP0_MODE is the original mode of XEXP (x, 0); LAST is nonzero if this
-   will be the iteration even if an expression with a code different from
-   X is returned; IN_DEST is nonzero if we are inside a SET_DEST.  */
+   OP0_MODE is the original mode of XEXP (x, 0).  IN_DEST is nonzero
+   if we are inside a SET_DEST.  */
 
 static rtx
-combine_simplify_rtx (x, op0_mode, last, in_dest)
-     rtx x;
-     enum machine_mode op0_mode;
-     int last;
-     int in_dest;
+combine_simplify_rtx (rtx x, enum machine_mode op0_mode, int in_dest)
 {
   enum rtx_code code = GET_CODE (x);
   enum machine_mode mode = GET_MODE (x);
@@ -3578,7 +3690,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 
   /* If this is a commutative operation, put a constant last and a complex
      expression first.  We don't need to do this for comparisons here.  */
-  if (GET_RTX_CLASS (code) == 'c'
+  if (COMMUTATIVE_ARITH_P (x)
       && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
     {
       temp = XEXP (x, 0);
@@ -3634,21 +3746,17 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 
      Don't do anything if all operands are very simple.  */
 
-  if (((GET_RTX_CLASS (code) == '2' || GET_RTX_CLASS (code) == 'c'
-       || GET_RTX_CLASS (code) == '<')
-       && ((GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) != 'o'
+  if ((BINARY_P (x)
+       && ((!OBJECT_P (XEXP (x, 0))
            && ! (GET_CODE (XEXP (x, 0)) == SUBREG
-                 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0))))
-                     == 'o')))
-          || (GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o'
+                 && OBJECT_P (SUBREG_REG (XEXP (x, 0)))))
+          || (!OBJECT_P (XEXP (x, 1))
               && ! (GET_CODE (XEXP (x, 1)) == SUBREG
-                    && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 1))))
-                        == 'o')))))
-      || (GET_RTX_CLASS (code) == '1'
-         && ((GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) != 'o'
+                    && OBJECT_P (SUBREG_REG (XEXP (x, 1)))))))
+      || (UNARY_P (x)
+          && (!OBJECT_P (XEXP (x, 0))
               && ! (GET_CODE (XEXP (x, 0)) == SUBREG
-                    && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0))))
-                        == 'o'))))))
+                    && OBJECT_P (SUBREG_REG (XEXP (x, 0)))))))
     {
       rtx cond, true_rtx, false_rtx;
 
@@ -3656,20 +3764,21 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
       if (cond != 0
          /* If everything is a comparison, what we have is highly unlikely
             to be simpler, so don't use it.  */
-         && ! (GET_RTX_CLASS (code) == '<'
-               && (GET_RTX_CLASS (GET_CODE (true_rtx)) == '<'
-                   || GET_RTX_CLASS (GET_CODE (false_rtx)) == '<')))
+         && ! (COMPARISON_P (x)
+               && (COMPARISON_P (true_rtx) || COMPARISON_P (false_rtx))))
        {
          rtx cop1 = const0_rtx;
          enum rtx_code cond_code = simplify_comparison (NE, &cond, &cop1);
 
-         if (cond_code == NE && GET_RTX_CLASS (GET_CODE (cond)) == '<')
+         if (cond_code == NE && COMPARISON_P (cond))
            return x;
 
          /* Simplify the alternative arms; this may collapse the true and
-            false arms to store-flag values.  */
-         true_rtx = subst (true_rtx, pc_rtx, pc_rtx, 0, 0);
-         false_rtx = subst (false_rtx, pc_rtx, pc_rtx, 0, 0);
+            false arms to store-flag values.  Be careful to use copy_rtx
+            here since true_rtx or false_rtx might share RTL with x as a
+            result of the if_then_else_cond call above.  */
+         true_rtx = subst (copy_rtx (true_rtx), pc_rtx, pc_rtx, 0, 0);
+         false_rtx = subst (copy_rtx (false_rtx), pc_rtx, pc_rtx, 0, 0);
 
          /* If true_rtx and false_rtx are not general_operands, an if_then_else
             is unlikely to be simpler.  */
@@ -3687,7 +3796,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
                x = gen_binary (cond_code, mode, cond, cop1);
              else if (true_rtx == const0_rtx && false_rtx == const_true_rtx
                       && ((reversed = reversed_comparison_code_parts
-                                       (cond_code, cond, cop1, NULL))
+                                       (cond_code, cond, cop1, NULL))
                           != UNKNOWN))
                x = gen_binary (reversed, mode, cond, cop1);
 
@@ -3704,11 +3813,11 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
                       && INTVAL (false_rtx) == - STORE_FLAG_VALUE
                       && true_rtx == const0_rtx
                       && ((reversed = reversed_comparison_code_parts
-                                       (cond_code, cond, cop1, NULL))
+                                       (cond_code, cond, cop1, NULL))
                           != UNKNOWN))
                x = simplify_gen_unary (NEG, mode,
                                        gen_binary (reversed, mode,
-                                                   cond, cop1),
+                                                   cond, cop1),
                                        mode);
              else
                return gen_rtx_IF_THEN_ELSE (mode,
@@ -3727,10 +3836,13 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
   temp = 0;
   switch (GET_RTX_CLASS (code))
     {
-    case '1':
+    case RTX_UNARY:
+      if (op0_mode == VOIDmode)
+       op0_mode = GET_MODE (XEXP (x, 0));
       temp = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode);
       break;
-    case '<':
+    case RTX_COMPARE:
+    case RTX_COMM_COMPARE:
       {
        enum machine_mode cmp_mode = GET_MODE (XEXP (x, 0));
        if (cmp_mode == VOIDmode)
@@ -3739,29 +3851,21 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
            if (cmp_mode == VOIDmode)
              cmp_mode = op0_mode;
          }
-       temp = simplify_relational_operation (code, cmp_mode,
+       temp = simplify_relational_operation (code, mode, cmp_mode,
                                              XEXP (x, 0), XEXP (x, 1));
       }
-#ifdef FLOAT_STORE_FLAG_VALUE
-      if (temp != 0 && GET_MODE_CLASS (mode) == MODE_FLOAT)
-       {
-         if (temp == const0_rtx)
-           temp = CONST0_RTX (mode);
-         else
-           temp = CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE (mode),
-                                                mode);
-       }
-#endif
       break;
-    case 'c':
-    case '2':
+    case RTX_COMM_ARITH:
+    case RTX_BIN_ARITH:
       temp = simplify_binary_operation (code, mode, XEXP (x, 0), XEXP (x, 1));
       break;
-    case 'b':
-    case '3':
+    case RTX_BITFIELD_OPS:
+    case RTX_TERNARY:
       temp = simplify_ternary_operation (code, mode, op0_mode, XEXP (x, 0),
                                         XEXP (x, 1), XEXP (x, 2));
       break;
+    default:
+      break;
     }
 
   if (temp)
@@ -3799,7 +3903,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 
          /* Make sure we pass the constant operand if any as the second
             one if this is a commutative operation.  */
-         if (CONSTANT_P (inner_op0) && GET_RTX_CLASS (code) == 'c')
+         if (CONSTANT_P (inner_op0) && COMMUTATIVE_ARITH_P (x))
            {
              rtx tem = inner_op0;
              inner_op0 = inner_op1;
@@ -3812,7 +3916,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 
          /* For commutative operations, try the other pair if that one
             didn't simplify.  */
-         if (inner == 0 && GET_RTX_CLASS (code) == 'c')
+         if (inner == 0 && COMMUTATIVE_ARITH_P (x))
            {
              other = XEXP (XEXP (x, 0), 1);
              inner = simplify_binary_operation (code, mode,
@@ -3839,15 +3943,15 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
       if (op0_mode == VOIDmode)
        op0_mode = GET_MODE (SUBREG_REG (x));
 
-      /* simplify_subreg can't use gen_lowpart_for_combine.  */
+      /* See if this can be moved to simplify_subreg.  */
       if (CONSTANT_P (SUBREG_REG (x))
          && subreg_lowpart_offset (mode, op0_mode) == SUBREG_BYTE (x)
-            /* Don't call gen_lowpart_for_combine if the inner mode
+            /* Don't call gen_lowpart 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));
+       return gen_lowpart (mode, SUBREG_REG (x));
 
       if (GET_MODE_CLASS (GET_MODE (SUBREG_REG (x))) == MODE_CC)
         break;
@@ -3861,7 +3965,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 
       /* Don't change the mode of the MEM if that would change the meaning
         of the address.  */
-      if (GET_CODE (SUBREG_REG (x)) == MEM
+      if (MEM_P (SUBREG_REG (x))
          && (MEM_VOLATILE_P (SUBREG_REG (x))
              || mode_dependent_address_p (XEXP (SUBREG_REG (x), 0))))
        return gen_rtx_CLOBBER (mode, const0_rtx);
@@ -3873,33 +3977,6 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
       break;
 
     case NOT:
-      /* (not (plus X -1)) can become (neg X).  */
-      if (GET_CODE (XEXP (x, 0)) == PLUS
-         && XEXP (XEXP (x, 0), 1) == constm1_rtx)
-       return gen_rtx_NEG (mode, XEXP (XEXP (x, 0), 0));
-
-      /* Similarly, (not (neg X)) is (plus X -1).  */
-      if (GET_CODE (XEXP (x, 0)) == NEG)
-       return gen_rtx_PLUS (mode, XEXP (XEXP (x, 0), 0), constm1_rtx);
-
-      /* (not (xor X C)) for C constant is (xor X D) with D = ~C.  */
-      if (GET_CODE (XEXP (x, 0)) == XOR
-         && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
-         && (temp = simplify_unary_operation (NOT, mode,
-                                              XEXP (XEXP (x, 0), 1),
-                                              mode)) != 0)
-       return gen_binary (XOR, mode, XEXP (XEXP (x, 0), 0), temp);
-
-      /* (not (ashift 1 X)) is (rotate ~1 X).  We used to do this for operands
-        other than 1, but that is not valid.  We could do a similar
-        simplification for (not (lshiftrt C X)) where C is just the sign bit,
-        but this doesn't seem common enough to bother with.  */
-      if (GET_CODE (XEXP (x, 0)) == ASHIFT
-         && XEXP (XEXP (x, 0), 0) == const1_rtx)
-       return gen_rtx_ROTATE (mode, simplify_gen_unary (NOT, mode,
-                                                        const1_rtx, mode),
-                              XEXP (XEXP (x, 0), 1));
-
       if (GET_CODE (XEXP (x, 0)) == SUBREG
          && subreg_lowpart_p (XEXP (x, 0))
          && (GET_MODE_SIZE (GET_MODE (XEXP (x, 0)))
@@ -3913,27 +3990,9 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
                              simplify_gen_unary (NOT, inner_mode, const1_rtx,
                                                  inner_mode),
                              XEXP (SUBREG_REG (XEXP (x, 0)), 1));
-         return gen_lowpart_for_combine (mode, x);
+         return gen_lowpart (mode, x);
        }
 
-      /* If STORE_FLAG_VALUE is -1, (not (comparison foo bar)) can be done by
-        reversing the comparison code if valid.  */
-      if (STORE_FLAG_VALUE == -1
-         && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
-         && (reversed = reversed_comparison (x, mode, XEXP (XEXP (x, 0), 0),
-                                             XEXP (XEXP (x, 0), 1))))
-       return reversed;
-
-      /* (not (ashiftrt foo C)) where C is the number of bits in FOO minus 1
-        is (ge foo (const_int 0)) if STORE_FLAG_VALUE is -1, so we can
-        perform the above simplification.  */
-
-      if (STORE_FLAG_VALUE == -1
-         && GET_CODE (XEXP (x, 0)) == ASHIFTRT
-         && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
-         && INTVAL (XEXP (XEXP (x, 0), 1)) == GET_MODE_BITSIZE (mode) - 1)
-       return gen_rtx_GE (mode, XEXP (XEXP (x, 0), 0), const0_rtx);
-
       /* Apply De Morgan's laws to reduce number of patterns for machines
         with negating logical insns (and-not, nand, etc.).  If result has
         only one NOT, put it first, since that is how the patterns are
@@ -3964,61 +4023,12 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
       break;
 
     case NEG:
-      /* (neg (plus X 1)) can become (not X).  */
-      if (GET_CODE (XEXP (x, 0)) == PLUS
-         && XEXP (XEXP (x, 0), 1) == const1_rtx)
-       return gen_rtx_NOT (mode, XEXP (XEXP (x, 0), 0));
-
-      /* Similarly, (neg (not X)) is (plus X 1).  */
-      if (GET_CODE (XEXP (x, 0)) == NOT)
-       return plus_constant (XEXP (XEXP (x, 0), 0), 1);
-
-      /* (neg (minus X Y)) can become (minus Y X).  This transformation
-        isn't safe for modes with signed zeros, since if X and Y are
-        both +0, (minus Y X) is the same as (minus X Y).  If the rounding
-        mode is towards +infinity (or -infinity) then the two expressions
-        will be rounded differently.  */
-      if (GET_CODE (XEXP (x, 0)) == MINUS
-         && !HONOR_SIGNED_ZEROS (mode)
-         && !HONOR_SIGN_DEPENDENT_ROUNDING (mode))
-       return gen_binary (MINUS, mode, XEXP (XEXP (x, 0), 1),
-                          XEXP (XEXP (x, 0), 0));
-
-      /* (neg (plus A B)) is canonicalized to (minus (neg A) B).  */
-      if (GET_CODE (XEXP (x, 0)) == PLUS
-         && !HONOR_SIGNED_ZEROS (mode)
-         && !HONOR_SIGN_DEPENDENT_ROUNDING (mode))
-       {
-         temp = simplify_gen_unary (NEG, mode, XEXP (XEXP (x, 0), 0), mode);
-         temp = combine_simplify_rtx (temp, mode, last, in_dest);
-         return gen_binary (MINUS, mode, temp, XEXP (XEXP (x, 0), 1));
-       }
-
-      /* (neg (mult A B)) becomes (mult (neg A) B).
-         This works even for floating-point values.  */
-      if (GET_CODE (XEXP (x, 0)) == MULT)
-       {
-         temp = simplify_gen_unary (NEG, mode, XEXP (XEXP (x, 0), 0), mode);
-         return gen_binary (MULT, mode, temp, XEXP (XEXP (x, 0), 1));
-       }
-
       /* (neg (xor A 1)) is (plus A -1) if A is known to be either 0 or 1.  */
-      if (GET_CODE (XEXP (x, 0)) == XOR && XEXP (XEXP (x, 0), 1) == const1_rtx
+      if (GET_CODE (XEXP (x, 0)) == XOR
+         && XEXP (XEXP (x, 0), 1) == const1_rtx
          && nonzero_bits (XEXP (XEXP (x, 0), 0), mode) == 1)
        return gen_binary (PLUS, mode, XEXP (XEXP (x, 0), 0), constm1_rtx);
 
-      /* NEG commutes with ASHIFT since it is multiplication.  Only do this
-        if we can then eliminate the NEG (e.g.,
-        if the operand is a constant).  */
-
-      if (GET_CODE (XEXP (x, 0)) == ASHIFT)
-       {
-         temp = simplify_unary_operation (NEG, mode,
-                                          XEXP (XEXP (x, 0), 0), mode);
-         if (temp)
-           return gen_binary (ASHIFT, mode, temp, XEXP (XEXP (x, 0), 1));
-       }
-
       temp = expand_compound_operation (XEXP (x, 0));
 
       /* For C equal to the width of MODE minus 1, (neg (ashiftrt X C)) can be
@@ -4038,9 +4048,9 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
         or a SUBREG of one since we'd be making the expression more
         complex if it was just a register.  */
 
-      if (GET_CODE (temp) != REG
+      if (!REG_P (temp)
          && ! (GET_CODE (temp) == SUBREG
-               && GET_CODE (SUBREG_REG (temp)) == REG)
+               && REG_P (SUBREG_REG (temp)))
          && (i = exact_log2 (nonzero_bits (temp, mode))) >= 0)
        {
          rtx temp1 = simplify_shift_const
@@ -4107,16 +4117,16 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
             >= (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));
+       return gen_lowpart (mode, XEXP (x, 0));
 
       /* A truncate of a comparison can be replaced with a subreg if
          STORE_FLAG_VALUE permits.  This is like the previous test,
          but it works even if the comparison is done in a mode larger
          than HOST_BITS_PER_WIDE_INT.  */
       if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
-         && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
+         && COMPARISON_P (XEXP (x, 0))
          && ((HOST_WIDE_INT) STORE_FLAG_VALUE & ~GET_MODE_MASK (mode)) == 0)
-       return gen_lowpart_for_combine (mode, XEXP (x, 0));
+       return gen_lowpart (mode, XEXP (x, 0));
 
       /* Similarly, a truncate of a register whose value is a
          comparison can be replaced with a subreg if STORE_FLAG_VALUE
@@ -4124,8 +4134,8 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
       if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
          && ((HOST_WIDE_INT) STORE_FLAG_VALUE & ~GET_MODE_MASK (mode)) == 0
          && (temp = get_last_value (XEXP (x, 0)))
-         && GET_RTX_CLASS (GET_CODE (temp)) == '<')
-       return gen_lowpart_for_combine (mode, XEXP (x, 0));
+         && COMPARISON_P (temp))
+       return gen_lowpart (mode, XEXP (x, 0));
 
       break;
 
@@ -4137,7 +4147,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 
       /* (float_truncate:SF (float_truncate:DF foo:XF))
          = (float_truncate:SF foo:XF).
-        This may elliminate double rounding, so it is unsafe.
+        This may eliminate double rounding, so it is unsafe.
 
          (float_truncate:SF (float_extend:XF foo:DF))
          = (float_truncate:SF foo:DF).
@@ -4148,10 +4158,10 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
           && flag_unsafe_math_optimizations)
          || GET_CODE (XEXP (x, 0)) == FLOAT_EXTEND)
        return simplify_gen_unary (GET_MODE_SIZE (GET_MODE (XEXP (XEXP (x, 0),
-                                                           0)))
-                                  > GET_MODE_SIZE (mode)
+                                                           0)))
+                                  > GET_MODE_SIZE (mode)
                                   ? FLOAT_TRUNCATE : FLOAT_EXTEND,
-                                  mode,
+                                  mode,
                                   XEXP (XEXP (x, 0), 0), mode);
 
       /*  (float_truncate (float x)) is (float x)  */
@@ -4290,7 +4300,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
         C is 1 and STORE_FLAG_VALUE is -1 or if C is -1 and STORE_FLAG_VALUE
         is 1.  This produces better code than the alternative immediately
         below.  */
-      if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
+      if (COMPARISON_P (XEXP (x, 0))
          && ((STORE_FLAG_VALUE == -1 && XEXP (x, 1) == const1_rtx)
              || (STORE_FLAG_VALUE == 1 && XEXP (x, 1) == constm1_rtx))
          && (reversed = reversed_comparison (XEXP (x, 0), mode,
@@ -4304,9 +4314,9 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
         the bitsize of the mode - 1.  This allows simplification of
         "a = (b & 8) == 0;"  */
       if (XEXP (x, 1) == constm1_rtx
-         && GET_CODE (XEXP (x, 0)) != REG
+         && !REG_P (XEXP (x, 0))
          && ! (GET_CODE (XEXP (x, 0)) == SUBREG
-               && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG)
+               && REG_P (SUBREG_REG (XEXP (x, 0))))
          && nonzero_bits (XEXP (x, 0), mode) == 1)
        return simplify_shift_const (NULL_RTX, ASHIFTRT, mode,
           simplify_shift_const (NULL_RTX, ASHIFT, mode,
@@ -4325,7 +4335,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
        {
          /* Try to simplify the expression further.  */
          rtx tor = gen_binary (IOR, mode, XEXP (x, 0), XEXP (x, 1));
-         temp = combine_simplify_rtx (tor, mode, last, in_dest);
+         temp = combine_simplify_rtx (tor, mode, in_dest);
 
          /* If we could, great.  If not, do not go ahead with the IOR
             replacement, since PLUS appears in many special purpose
@@ -4340,7 +4350,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
         by reversing the comparison code if valid.  */
       if (STORE_FLAG_VALUE == 1
          && XEXP (x, 0) == const1_rtx
-         && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<'
+         && COMPARISON_P (XEXP (x, 1))
          && (reversed = reversed_comparison (XEXP (x, 1), mode,
                                              XEXP (XEXP (x, 1), 0),
                                              XEXP (XEXP (x, 1), 1))))
@@ -4473,8 +4483,8 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
              && op1 == const0_rtx
              && mode == GET_MODE (op0)
              && nonzero_bits (op0, mode) == 1)
-           return gen_lowpart_for_combine (mode,
-                                           expand_compound_operation (op0));
+           return gen_lowpart (mode,
+                               expand_compound_operation (op0));
 
          else if (STORE_FLAG_VALUE == 1
                   && new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
@@ -4485,7 +4495,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
            {
              op0 = expand_compound_operation (op0);
              return simplify_gen_unary (NEG, mode,
-                                        gen_lowpart_for_combine (mode, op0),
+                                        gen_lowpart (mode, op0),
                                         mode);
            }
 
@@ -4497,7 +4507,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
            {
              op0 = expand_compound_operation (op0);
              return gen_binary (XOR, mode,
-                                gen_lowpart_for_combine (mode, op0),
+                                gen_lowpart (mode, op0),
                                 const1_rtx);
            }
 
@@ -4509,7 +4519,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
                       == GET_MODE_BITSIZE (mode)))
            {
              op0 = expand_compound_operation (op0);
-             return plus_constant (gen_lowpart_for_combine (mode, op0), 1);
+             return plus_constant (gen_lowpart (mode, op0), 1);
            }
 
          /* If STORE_FLAG_VALUE is -1, we have cases similar to
@@ -4519,8 +4529,8 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
              && op1 == const0_rtx
              && (num_sign_bit_copies (op0, mode)
                  == GET_MODE_BITSIZE (mode)))
-           return gen_lowpart_for_combine (mode,
-                                           expand_compound_operation (op0));
+           return gen_lowpart (mode,
+                               expand_compound_operation (op0));
 
          else if (STORE_FLAG_VALUE == -1
                   && new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
@@ -4530,7 +4540,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
            {
              op0 = expand_compound_operation (op0);
              return simplify_gen_unary (NEG, mode,
-                                        gen_lowpart_for_combine (mode, op0),
+                                        gen_lowpart (mode, op0),
                                         mode);
            }
 
@@ -4543,7 +4553,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
            {
              op0 = expand_compound_operation (op0);
              return simplify_gen_unary (NOT, mode,
-                                        gen_lowpart_for_combine (mode, op0),
+                                        gen_lowpart (mode, op0),
                                         mode);
            }
 
@@ -4555,7 +4565,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
                   && nonzero_bits (op0, mode) == 1)
            {
              op0 = expand_compound_operation (op0);
-             return plus_constant (gen_lowpart_for_combine (mode, op0), -1);
+             return plus_constant (gen_lowpart (mode, op0), -1);
            }
 
          /* If STORE_FLAG_VALUE says to just test the sign bit and X has just
@@ -4610,7 +4620,7 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
     case AND:
     case IOR:
     case XOR:
-      return simplify_logical (x, last);
+      return simplify_logical (x);
 
     case ABS:
       /* (abs (neg <foo>)) -> (abs <foo>) */
@@ -4668,16 +4678,13 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
        return simplify_shift_const (x, code, mode, XEXP (x, 0),
                                     INTVAL (XEXP (x, 1)));
 
-#ifdef SHIFT_COUNT_TRUNCATED
-      else if (SHIFT_COUNT_TRUNCATED && GET_CODE (XEXP (x, 1)) != REG)
+      else if (SHIFT_COUNT_TRUNCATED && !REG_P (XEXP (x, 1)))
        SUBST (XEXP (x, 1),
               force_to_mode (XEXP (x, 1), GET_MODE (XEXP (x, 1)),
                              ((HOST_WIDE_INT) 1
                               << exact_log2 (GET_MODE_BITSIZE (GET_MODE (x))))
                              - 1,
                              NULL_RTX, 0));
-#endif
-
       break;
 
     case VEC_SELECT:
@@ -4729,15 +4736,14 @@ combine_simplify_rtx (x, op0_mode, last, in_dest)
 /* Simplify X, an IF_THEN_ELSE expression.  Return the new expression.  */
 
 static rtx
-simplify_if_then_else (x)
-     rtx x;
+simplify_if_then_else (rtx x)
 {
   enum machine_mode mode = GET_MODE (x);
   rtx cond = XEXP (x, 0);
   rtx true_rtx = XEXP (x, 1);
   rtx false_rtx = XEXP (x, 2);
   enum rtx_code true_code = GET_CODE (cond);
-  int comparison_p = GET_RTX_CLASS (true_code) == '<';
+  int comparison_p = COMPARISON_P (cond);
   rtx temp;
   int i;
   enum rtx_code false_code;
@@ -4761,7 +4767,7 @@ simplify_if_then_else (x)
   if (comparison_p
       && ((false_code = combine_reversed_comparison_code (cond))
          != UNKNOWN)
-      && GET_CODE (XEXP (cond, 0)) == REG)
+      && REG_P (XEXP (cond, 0)))
     {
       HOST_WIDE_INT nzb;
       rtx from = XEXP (cond, 0);
@@ -4822,11 +4828,9 @@ simplify_if_then_else (x)
          || (CONSTANT_P (true_rtx)
              && GET_CODE (false_rtx) != CONST_INT && false_rtx != pc_rtx)
          || true_rtx == const0_rtx
-         || (GET_RTX_CLASS (GET_CODE (true_rtx)) == 'o'
-             && GET_RTX_CLASS (GET_CODE (false_rtx)) != 'o')
-         || (GET_CODE (true_rtx) == SUBREG
-             && GET_RTX_CLASS (GET_CODE (SUBREG_REG (true_rtx))) == 'o'
-             && GET_RTX_CLASS (GET_CODE (false_rtx)) != 'o')
+         || (OBJECT_P (true_rtx) && !OBJECT_P (false_rtx))
+         || (GET_CODE (true_rtx) == SUBREG && OBJECT_P (SUBREG_REG (true_rtx))
+             && !OBJECT_P (false_rtx))
          || reg_mentioned_p (true_rtx, false_rtx)
          || rtx_equal_p (false_rtx, XEXP (cond, 0))))
     {
@@ -4843,7 +4847,7 @@ simplify_if_then_else (x)
 
       /* It is possible that the conditional has been simplified out.  */
       true_code = GET_CODE (cond);
-      comparison_p = GET_RTX_CLASS (true_code) == '<';
+      comparison_p = COMPARISON_P (cond);
     }
 
   /* If the two arms are identical, we don't need the comparison.  */
@@ -4927,7 +4931,7 @@ simplify_if_then_else (x)
       rtx f = make_compound_operation (false_rtx, SET);
       rtx cond_op0 = XEXP (cond, 0);
       rtx cond_op1 = XEXP (cond, 1);
-      enum rtx_code op = NIL, extend_op = NIL;
+      enum rtx_code op = UNKNOWN, extend_op = UNKNOWN;
       enum machine_mode m = mode;
       rtx z = 0, c1 = NULL_RTX;
 
@@ -5024,9 +5028,9 @@ simplify_if_then_else (x)
          temp = gen_binary (MULT, m, temp,
                             gen_binary (MULT, m, c1, const_true_rtx));
          temp = subst (temp, pc_rtx, pc_rtx, 0, 0);
-         temp = gen_binary (op, m, gen_lowpart_for_combine (m, z), temp);
+         temp = gen_binary (op, m, gen_lowpart (m, z), temp);
 
-         if (extend_op != NIL)
+         if (extend_op != UNKNOWN)
            temp = simplify_gen_unary (extend_op, mode, temp, m);
 
          return temp;
@@ -5047,7 +5051,16 @@ simplify_if_then_else (x)
              && (i = exact_log2 (-INTVAL (true_rtx))) >= 0)))
     return
       simplify_shift_const (NULL_RTX, ASHIFT, mode,
-                           gen_lowpart_for_combine (mode, XEXP (cond, 0)), i);
+                           gen_lowpart (mode, XEXP (cond, 0)), i);
+
+  /* (IF_THEN_ELSE (NE REG 0) (0) (8)) is REG for nonzero_bits (REG) == 8.  */
+  if (true_code == NE && XEXP (cond, 1) == const0_rtx
+      && false_rtx == const0_rtx && GET_CODE (true_rtx) == CONST_INT
+      && GET_MODE (XEXP (cond, 0)) == mode
+      && (INTVAL (true_rtx) & GET_MODE_MASK (mode))
+         == nonzero_bits (XEXP (cond, 0), mode)
+      && (i = exact_log2 (INTVAL (true_rtx) & GET_MODE_MASK (mode))) >= 0)
+    return XEXP (cond, 0);
 
   return x;
 }
@@ -5055,8 +5068,7 @@ simplify_if_then_else (x)
 /* Simplify X, a SET expression.  Return the new expression.  */
 
 static rtx
-simplify_set (x)
-     rtx x;
+simplify_set (rtx x)
 {
   rtx src = SET_SRC (x);
   rtx dest = SET_DEST (x);
@@ -5088,7 +5100,7 @@ simplify_set (x)
        || 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)) == '<'
+      && COMPARISON_P (*cc_use)
       && rtx_equal_p (XEXP (*cc_use, 0), dest))
     {
       enum rtx_code old_code = GET_CODE (*cc_use);
@@ -5096,22 +5108,23 @@ simplify_set (x)
       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);
+       op0 = src, op1 = CONST0_RTX (GET_MODE (src));
+
+      tmp = simplify_relational_operation (old_code, compare_mode, VOIDmode,
+                                          op0, op1);
+      if (!tmp)
+        new_code = old_code;
+      else if (!CONSTANT_P (tmp))
+        {
+          new_code = GET_CODE (tmp);
+          op0 = XEXP (tmp, 0);
+          op1 = XEXP (tmp, 1);
+        }
       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;
@@ -5132,15 +5145,17 @@ simplify_set (x)
        }
 
       /* Simplify our comparison, if possible.  */
-      new_code = simplify_comparison (old_code, &op0, &op1);
+      new_code = simplify_comparison (new_code, &op0, &op1);
 
-#ifdef EXTRA_CC_MODES
+#ifdef SELECT_CC_MODE
       /* If this machine has CC modes other than CCmode, check to see if we
         need to use a different CC mode here.  */
-      compare_mode = SELECT_CC_MODE (new_code, op0, op1);
-#endif /* EXTRA_CC_MODES */
+      if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
+       compare_mode = GET_MODE (op0);
+      else
+       compare_mode = SELECT_CC_MODE (new_code, op0, op1);
 
-#if !defined (HAVE_cc0) && defined (EXTRA_CC_MODES)
+#ifndef HAVE_cc0
       /* If the mode changed, we have to change SET_DEST, the mode in the
         compare, and the mode in the place SET_DEST is used.  If SET_DEST is
         a hard register, just build new versions with the proper mode.  If it
@@ -5164,16 +5179,19 @@ simplify_set (x)
              dest = new_dest;
            }
        }
-#endif
+#endif  /* cc0 */
+#endif  /* SELECT_CC_MODE */
 
       /* If the code changed, we have to build a new comparison in
         undobuf.other_insn.  */
       if (new_code != old_code)
        {
+         int other_changed_previously = other_changed;
          unsigned HOST_WIDE_INT mask;
 
          SUBST (*cc_use, gen_rtx_fmt_ee (new_code, GET_MODE (*cc_use),
                                          dest, const0_rtx));
+         other_changed = 1;
 
          /* If the only change we made was to change an EQ into an NE or
             vice versa, OP0 has only one bit that might be nonzero, and OP1
@@ -5183,7 +5201,7 @@ simplify_set (x)
 
          if (((old_code == NE && new_code == EQ)
               || (old_code == EQ && new_code == NE))
-             && ! other_changed && op1 == const0_rtx
+             && ! other_changed_previously && op1 == const0_rtx
              && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
              && exact_log2 (mask = nonzero_bits (op0, GET_MODE (op0))) >= 0)
            {
@@ -5193,13 +5211,11 @@ simplify_set (x)
                   && ! check_asm_operands (pat)))
                {
                  PUT_CODE (*cc_use, old_code);
-                 other_insn = 0;
+                 other_changed = 0;
 
                  op0 = gen_binary (XOR, GET_MODE (op0), op0, GEN_INT (mask));
                }
            }
-
-         other_changed = 1;
        }
 
       if (other_changed)
@@ -5238,43 +5254,45 @@ simplify_set (x)
       SUBST (SET_SRC (x), src);
     }
 
-#ifdef WORD_REGISTER_OPERATIONS
   /* If we have (set x (subreg:m1 (op:m2 ...) 0)) with OP being some operation,
      and X being a REG or (subreg (reg)), we may be able to convert this to
      (set (subreg:m2 x) (op)).
 
-     On a machine where WORD_REGISTER_OPERATIONS is defined, this
-     transformation is safe as long as M1 and M2 have the same number
-     of words.
+     We can always do this if M1 is narrower than M2 because that means that
+     we only care about the low bits of the result.
 
-     However, on a machine without WORD_REGISTER_OPERATIONS defined,
-     we cannot apply this transformation because it would create a
-     paradoxical subreg in SET_DEST.  */
+     However, on machines without WORD_REGISTER_OPERATIONS defined, we cannot
+     perform a narrower operation than requested since the high-order bits will
+     be undefined.  On machine where it is defined, this transformation is safe
+     as long as M1 and M2 have the same number of words.  */
 
   if (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)
-      && GET_RTX_CLASS (GET_CODE (SUBREG_REG (src))) != 'o'
+      && !OBJECT_P (SUBREG_REG (src))
       && (((GET_MODE_SIZE (GET_MODE (src)) + (UNITS_PER_WORD - 1))
           / UNITS_PER_WORD)
          == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))
               + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))
+#ifndef WORD_REGISTER_OPERATIONS
+      && (GET_MODE_SIZE (GET_MODE (src))
+        < GET_MODE_SIZE (GET_MODE (SUBREG_REG (src))))
+#endif
 #ifdef CANNOT_CHANGE_MODE_CLASS
-      && ! (GET_CODE (dest) == REG && REGNO (dest) < FIRST_PSEUDO_REGISTER
+      && ! (REG_P (dest) && REGNO (dest) < FIRST_PSEUDO_REGISTER
            && REG_CANNOT_CHANGE_MODE_P (REGNO (dest),
                                         GET_MODE (SUBREG_REG (src)),
                                         GET_MODE (src)))
 #endif
-      && (GET_CODE (dest) == REG
+      && (REG_P (dest)
          || (GET_CODE (dest) == SUBREG
-             && GET_CODE (SUBREG_REG (dest)) == REG)))
+             && REG_P (SUBREG_REG (dest)))))
     {
       SUBST (SET_DEST (x),
-            gen_lowpart_for_combine (GET_MODE (SUBREG_REG (src)),
+            gen_lowpart (GET_MODE (SUBREG_REG (src)),
                                      dest));
       SUBST (SET_SRC (x), SUBREG_REG (src));
 
       src = SET_SRC (x), dest = SET_DEST (x);
     }
-#endif
 
 #ifdef HAVE_cc0
   /* If we have (set (cc0) (subreg ...)), we try to remove the subreg
@@ -5306,15 +5324,15 @@ simplify_set (x)
      zero_extend to avoid the reload that would otherwise be required.  */
 
   if (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)
-      && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))) != NIL
+      && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))) != UNKNOWN
       && SUBREG_BYTE (src) == 0
       && (GET_MODE_SIZE (GET_MODE (src))
          > GET_MODE_SIZE (GET_MODE (SUBREG_REG (src))))
-      && GET_CODE (SUBREG_REG (src)) == MEM)
+      && MEM_P (SUBREG_REG (src)))
     {
       SUBST (SET_SRC (x),
-            gen_rtx (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))),
-                     GET_MODE (src), SUBREG_REG (src)));
+            gen_rtx_fmt_e (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))),
+                           GET_MODE (src), SUBREG_REG (src)));
 
       src = SET_SRC (x);
     }
@@ -5387,12 +5405,10 @@ simplify_set (x)
 }
 \f
 /* Simplify, X, and AND, IOR, or XOR operation, and return the simplified
-   result.  LAST is nonzero if this is the last retry.  */
+   result.  */
 
 static rtx
-simplify_logical (x, last)
-     rtx x;
-     int last;
+simplify_logical (rtx x)
 {
   enum machine_mode mode = GET_MODE (x);
   rtx op0 = XEXP (x, 0);
@@ -5442,11 +5458,13 @@ simplify_logical (x, last)
 
          /* If we have (ior (and (X C1) C2)) and the next restart would be
             the last, simplify this by making C1 as small as possible
-            and then exit.  */
-         if (last
-             && GET_CODE (x) == IOR && GET_CODE (op0) == AND
+            and then exit.  Only do this if C1 actually changes: for now
+            this only saves memory but, should this transformation be
+            moved to simplify-rtx.c, we'd risk unbounded recursion there.  */
+         if (GET_CODE (x) == IOR && GET_CODE (op0) == AND
              && GET_CODE (XEXP (op0, 1)) == CONST_INT
-             && GET_CODE (op1) == CONST_INT)
+             && GET_CODE (op1) == CONST_INT
+             && (INTVAL (XEXP (op0, 1)) & INTVAL (op1)) != 0)
            return gen_binary (IOR, mode,
                               gen_binary (AND, mode, XEXP (op0, 0),
                                           GEN_INT (INTVAL (XEXP (op0, 1))
@@ -5455,9 +5473,8 @@ simplify_logical (x, last)
          if (GET_CODE (x) != AND)
            return x;
 
-         if (GET_RTX_CLASS (GET_CODE (x)) == 'c'
-             || GET_RTX_CLASS (GET_CODE (x)) == '2')
-           op0 = XEXP (x, 0), op1 = XEXP (x, 1);
+         op0 = XEXP (x, 0);
+         op1 = XEXP (x, 1);
        }
 
       /* Convert (A | B) & A to A.  */
@@ -5652,7 +5669,7 @@ simplify_logical (x, last)
         comparison if STORE_FLAG_VALUE is 1.  */
       if (STORE_FLAG_VALUE == 1
          && op1 == const1_rtx
-         && GET_RTX_CLASS (GET_CODE (op0)) == '<'
+         && COMPARISON_P (op0)
          && (reversed = reversed_comparison (op0, mode, XEXP (op0, 0),
                                              XEXP (op0, 1))))
        return reversed;
@@ -5674,7 +5691,7 @@ simplify_logical (x, last)
          && ((STORE_FLAG_VALUE & GET_MODE_MASK (mode))
              == (unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1))
          && op1 == const_true_rtx
-         && GET_RTX_CLASS (GET_CODE (op0)) == '<'
+         && COMPARISON_P (op0)
          && (reversed = reversed_comparison (op0, mode, XEXP (op0, 0),
                                              XEXP (op0, 1))))
        return reversed;
@@ -5702,8 +5719,7 @@ simplify_logical (x, last)
    It is the inverse of this function, loosely speaking.  */
 
 static rtx
-expand_compound_operation (x)
-     rtx x;
+expand_compound_operation (rtx x)
 {
   unsigned HOST_WIDE_INT pos = 0, len;
   int unsignedp = 0;
@@ -5839,7 +5855,7 @@ expand_compound_operation (x)
          than HOST_WIDE_INT.  */
       if (GET_CODE (XEXP (x, 0)) == TRUNCATE
          && GET_MODE (XEXP (XEXP (x, 0), 0)) == GET_MODE (x)
-         && GET_RTX_CLASS (GET_CODE (XEXP (XEXP (x, 0), 0))) == '<'
+         && COMPARISON_P (XEXP (XEXP (x, 0), 0))
          && (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
              <= HOST_BITS_PER_WIDE_INT)
          && ((HOST_WIDE_INT) STORE_FLAG_VALUE
@@ -5850,7 +5866,7 @@ expand_compound_operation (x)
       if (GET_CODE (XEXP (x, 0)) == SUBREG
          && GET_MODE (SUBREG_REG (XEXP (x, 0))) == GET_MODE (x)
          && subreg_lowpart_p (XEXP (x, 0))
-         && GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0)))) == '<'
+         && COMPARISON_P (SUBREG_REG (XEXP (x, 0)))
          && (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
              <= HOST_BITS_PER_WIDE_INT)
          && ((HOST_WIDE_INT) STORE_FLAG_VALUE
@@ -5911,8 +5927,7 @@ expand_compound_operation (x)
    support variable lengths.  */
 
 static rtx
-expand_field_assignment (x)
-     rtx x;
+expand_field_assignment (rtx x)
 {
   rtx inner;
   rtx pos;                     /* Always counts from low bit.  */
@@ -5973,7 +5988,7 @@ expand_field_assignment (x)
                        + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
        {
          x = gen_rtx_SET (VOIDmode, SUBREG_REG (SET_DEST (x)),
-                          gen_lowpart_for_combine
+                          gen_lowpart
                           (GET_MODE (SUBREG_REG (SET_DEST (x))),
                            SET_SRC (x)));
          continue;
@@ -6001,7 +6016,7 @@ expand_field_assignment (x)
            break;
 
          compute_mode = imode;
-         inner = gen_lowpart_for_combine (imode, inner);
+         inner = gen_lowpart (imode, inner);
        }
 
       /* Compute a mask of LEN bits, if we can do this on the host machine.  */
@@ -6025,7 +6040,7 @@ expand_field_assignment (x)
                                 inner),
                     gen_binary (ASHIFT, compute_mode,
                                 gen_binary (AND, compute_mode,
-                                            gen_lowpart_for_combine
+                                            gen_lowpart
                                             (compute_mode, SET_SRC (x)),
                                             mask),
                                 pos)));
@@ -6062,15 +6077,9 @@ expand_field_assignment (x)
    can't handle it.  */
 
 static rtx
-make_extraction (mode, inner, pos, pos_rtx, len,
-                unsignedp, in_dest, in_compare)
-     enum machine_mode mode;
-     rtx inner;
-     HOST_WIDE_INT pos;
-     rtx pos_rtx;
-     unsigned HOST_WIDE_INT len;
-     int unsignedp;
-     int in_dest, in_compare;
+make_extraction (enum machine_mode mode, rtx inner, HOST_WIDE_INT pos,
+                rtx pos_rtx, unsigned HOST_WIDE_INT len, int unsignedp,
+                int in_dest, int in_compare)
 {
   /* This mode describes the size of the storage area
      to fetch the overall value from.  Within that, we
@@ -6100,7 +6109,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
         The subreg adds or removes high bits; its mode is
         irrelevant to the meaning of this extraction,
         since POS and LEN count from the lsb.  */
-      if (GET_CODE (SUBREG_REG (inner)) == MEM)
+      if (MEM_P (SUBREG_REG (inner)))
        is_mode = GET_MODE (SUBREG_REG (inner));
       inner = SUBREG_REG (inner);
     }
@@ -6141,11 +6150,11 @@ make_extraction (mode, inner, pos, pos_rtx, len,
   if (tmode != BLKmode
       && ! (spans_byte && inner_mode != tmode)
       && ((pos_rtx == 0 && (pos % BITS_PER_WORD) == 0
-          && GET_CODE (inner) != MEM
+          && !MEM_P (inner)
           && (! in_dest
-              || (GET_CODE (inner) == REG
+              || (REG_P (inner)
                   && have_insn_for (STRICT_LOW_PART, tmode))))
-         || (GET_CODE (inner) == MEM && pos_rtx == 0
+         || (MEM_P (inner) && pos_rtx == 0
              && (pos
                  % (STRICT_ALIGNMENT ? GET_MODE_ALIGNMENT (tmode)
                     : BITS_PER_UNIT)) == 0
@@ -6163,7 +6172,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
         If INNER is not a MEM, get a piece consisting of just the field
         of interest (in this case POS % BITS_PER_WORD must be 0).  */
 
-      if (GET_CODE (inner) == MEM)
+      if (MEM_P (inner))
        {
          HOST_WIDE_INT offset;
 
@@ -6175,32 +6184,38 @@ make_extraction (mode, inner, pos, pos_rtx, len,
 
          new = adjust_address_nv (inner, tmode, offset);
        }
-      else if (GET_CODE (inner) == REG)
+      else if (REG_P (inner))
        {
-         /* We can't call gen_lowpart_for_combine here since we always want
-            a SUBREG and it would sometimes return a new hard register.  */
          if (tmode != inner_mode)
            {
-             HOST_WIDE_INT final_word = pos / BITS_PER_WORD;
-
-             if (WORDS_BIG_ENDIAN
-                 && GET_MODE_SIZE (inner_mode) > UNITS_PER_WORD)
-               final_word = ((GET_MODE_SIZE (inner_mode)
-                              - GET_MODE_SIZE (tmode))
-                             / UNITS_PER_WORD) - final_word;
-
-             final_word *= UNITS_PER_WORD;
-             if (BYTES_BIG_ENDIAN &&
-                 GET_MODE_SIZE (inner_mode) > GET_MODE_SIZE (tmode))
-               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);
+             /* We can't call gen_lowpart in a DEST since we
+                always want a SUBREG (see below) and it would sometimes
+                return a new hard register.  */
+             if (pos || in_dest)
+               {
+                 HOST_WIDE_INT final_word = pos / BITS_PER_WORD;
+
+                 if (WORDS_BIG_ENDIAN
+                     && GET_MODE_SIZE (inner_mode) > UNITS_PER_WORD)
+                   final_word = ((GET_MODE_SIZE (inner_mode)
+                                  - GET_MODE_SIZE (tmode))
+                                 / UNITS_PER_WORD) - final_word;
+
+                 final_word *= UNITS_PER_WORD;
+                 if (BYTES_BIG_ENDIAN &&
+                     GET_MODE_SIZE (inner_mode) > GET_MODE_SIZE (tmode))
+                   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
+               new = gen_lowpart (tmode, inner);
            }
          else
            new = inner;
@@ -6216,7 +6231,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
         make a STRICT_LOW_PART unless we made a MEM.  */
 
       if (in_dest)
-       return (GET_CODE (new) == MEM ? new
+       return (MEM_P (new) ? new
                : (GET_CODE (new) != SUBREG
                   ? gen_rtx_CLOBBER (tmode, const0_rtx)
                   : gen_rtx_STRICT_LOW_PART (VOIDmode, new)));
@@ -6267,7 +6282,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
      length is not 1.  In all other cases, we would only be going outside
      our object in cases when an original shift would have been
      undefined.  */
-  if (! spans_byte && GET_CODE (inner) == MEM
+  if (! spans_byte && MEM_P (inner)
       && ((pos_rtx == 0 && pos + len > GET_MODE_BITSIZE (is_mode))
          || (pos_rtx != 0 && len != 1)))
     return 0;
@@ -6310,7 +6325,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
   /* If this is not from memory, the desired mode is wanted_inner_reg_mode;
      if we have to change the mode of memory and cannot, the desired mode is
      EXTRACTION_MODE.  */
-  if (GET_CODE (inner) != MEM)
+  if (!MEM_P (inner))
     wanted_inner_mode = wanted_inner_reg_mode;
   else if (inner_mode != wanted_inner_mode
           && (mode_dependent_address_p (XEXP (inner, 0))
@@ -6328,7 +6343,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
         If it's a MEM we need to recompute POS relative to that.
         However, if we're extracting from (or inserting into) a register,
         we want to recompute POS relative to wanted_inner_mode.  */
-      int width = (GET_CODE (inner) == MEM
+      int width = (MEM_P (inner)
                   ? GET_MODE_BITSIZE (is_mode)
                   : GET_MODE_BITSIZE (wanted_inner_mode));
 
@@ -6338,7 +6353,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
        pos_rtx
          = gen_rtx_MINUS (GET_MODE (pos_rtx), GEN_INT (width - len), pos_rtx);
       /* POS may be less than 0 now, but we check for that below.
-        Note that it can only be less than 0 if GET_CODE (inner) != MEM.  */
+        Note that it can only be less than 0 if !MEM_P (inner).  */
     }
 
   /* If INNER has a wider mode, make it smaller.  If this is a constant
@@ -6346,7 +6361,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
      the value.  */
   if (wanted_inner_mode != VOIDmode
       && GET_MODE_SIZE (wanted_inner_mode) < GET_MODE_SIZE (is_mode)
-      && ((GET_CODE (inner) == MEM
+      && ((MEM_P (inner)
           && (inner_mode == wanted_inner_mode
               || (! mode_dependent_address_p (XEXP (inner, 0))
                   && ! MEM_VOLATILE_P (inner))))))
@@ -6384,7 +6399,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
   /* If INNER is not memory, we can always get it into the proper mode.  If we
      are changing its mode, POS must be a constant and smaller than the size
      of the new mode.  */
-  else if (GET_CODE (inner) != MEM)
+  else if (!MEM_P (inner))
     {
       if (GET_MODE (inner) != wanted_inner_mode
          && (pos_rtx != 0
@@ -6430,7 +6445,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
     }
   else if (pos_rtx != 0
           && GET_MODE_SIZE (pos_mode) < GET_MODE_SIZE (GET_MODE (pos_rtx)))
-    pos_rtx = gen_lowpart_for_combine (pos_mode, pos_rtx);
+    pos_rtx = gen_lowpart (pos_mode, pos_rtx);
 
   /* Make POS_RTX unless we already have it and it is correct.  If we don't
      have a POS_RTX but we do have an ORIG_POS_RTX, the latter must
@@ -6445,7 +6460,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
   new = gen_rtx_fmt_eee (unsignedp ? ZERO_EXTRACT : SIGN_EXTRACT,
                         extraction_mode, inner, GEN_INT (len), pos_rtx);
   if (! in_dest)
-    new = gen_lowpart_for_combine (mode, new);
+    new = gen_lowpart (mode, new);
 
   return new;
 }
@@ -6454,9 +6469,7 @@ make_extraction (mode, inner, pos, pos_rtx, len,
    with any other operations in X.  Return X without that shift if so.  */
 
 static rtx
-extract_left_shift (x, count)
-     rtx x;
-     int count;
+extract_left_shift (rtx x, int count)
 {
   enum rtx_code code = GET_CODE (x);
   enum machine_mode mode = GET_MODE (x);
@@ -6517,9 +6530,7 @@ extract_left_shift (x, count)
    or a COMPARE against zero, it is COMPARE.  */
 
 static rtx
-make_compound_operation (x, in_code)
-     rtx x;
-     enum rtx_code in_code;
+make_compound_operation (rtx x, enum rtx_code in_code)
 {
   enum rtx_code code = GET_CODE (x);
   enum machine_mode mode = GET_MODE (x);
@@ -6536,7 +6547,7 @@ make_compound_operation (x, in_code)
      but once inside, go back to our default of SET.  */
 
   next_code = (code == MEM || code == PLUS || code == MINUS ? MEM
-              : ((code == COMPARE || GET_RTX_CLASS (code) == '<')
+              : ((code == COMPARE || COMPARISON_P (x))
                  && XEXP (x, 1) == const0_rtx) ? COMPARE
               : in_code == COMPARE ? SET : in_code);
 
@@ -6702,9 +6713,9 @@ make_compound_operation (x, in_code)
         also do this for some cases of SIGN_EXTRACT, but it doesn't
         seem worth the effort; the case checked for occurs on Alpha.  */
 
-      if (GET_RTX_CLASS (GET_CODE (lhs)) != 'o'
+      if (!OBJECT_P (lhs)
          && ! (GET_CODE (lhs) == SUBREG
-               && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (lhs))) == 'o'))
+               && (OBJECT_P (SUBREG_REG (lhs))))
          && GET_CODE (rhs) == CONST_INT
          && INTVAL (rhs) < HOST_BITS_PER_WIDE_INT
          && (new = extract_left_shift (lhs, INTVAL (rhs))) != 0)
@@ -6752,7 +6763,7 @@ make_compound_operation (x, in_code)
              tem = gen_rtx_fmt_e (GET_CODE (tem), mode, XEXP (tem, 0));
            }
          else
-           tem = gen_lowpart_for_combine (mode, XEXP (tem, 0));
+           tem = gen_lowpart (mode, XEXP (tem, 0));
          return tem;
        }
       break;
@@ -6763,7 +6774,7 @@ make_compound_operation (x, in_code)
 
   if (new)
     {
-      x = gen_lowpart_for_combine (mode, new);
+      x = gen_lowpart (mode, new);
       code = GET_CODE (x);
     }
 
@@ -6787,23 +6798,19 @@ make_compound_operation (x, in_code)
    *PLEN is set to the length of the field.  */
 
 static int
-get_pos_from_mask (m, plen)
-     unsigned HOST_WIDE_INT m;
-     unsigned HOST_WIDE_INT *plen;
+get_pos_from_mask (unsigned HOST_WIDE_INT m, unsigned HOST_WIDE_INT *plen)
 {
   /* Get the bit number of the first 1 bit from the right, -1 if none.  */
   int pos = exact_log2 (m & -m);
-  int len;
-
-  if (pos < 0)
-    return -1;
+  int len = 0;
 
-  /* Now shift off the low-order zero bits and see if we have a power of
-     two minus 1.  */
-  len = exact_log2 ((m >> pos) + 1);
+  if (pos >= 0)
+    /* Now shift off the low-order zero bits and see if we have a
+       power of two minus 1.  */
+    len = exact_log2 ((m >> pos) + 1);
 
   if (len <= 0)
-    return -1;
+    pos = -1;
 
   *plen = len;
   return pos;
@@ -6826,12 +6833,8 @@ get_pos_from_mask (m, plen)
    NOT, NEG, or XOR.  */
 
 static rtx
-force_to_mode (x, mode, mask, reg, just_select)
-     rtx x;
-     enum machine_mode mode;
-     unsigned HOST_WIDE_INT mask;
-     rtx reg;
-     int just_select;
+force_to_mode (rtx x, enum machine_mode mode, unsigned HOST_WIDE_INT mask,
+              rtx reg, int just_select)
 {
   enum rtx_code code = GET_CODE (x);
   int next_select = just_select || code == XOR || code == NOT || code == NEG;
@@ -6844,7 +6847,7 @@ force_to_mode (x, mode, mask, reg, just_select)
      expression is VOIDmode.
 
      Also do nothing if X is a CLOBBER; this can happen if X was
-     the return value from a call to gen_lowpart_for_combine.  */
+     the return value from a call to gen_lowpart.  */
   if (code == CALL || code == ASM_OPERANDS || code == CLOBBER)
     return x;
 
@@ -6866,15 +6869,13 @@ force_to_mode (x, mode, mask, reg, just_select)
     mask &= GET_MODE_MASK (op_mode);
 
   /* When we have an arithmetic operation, or a shift whose count we
-     do not know, we need to assume that all bit the up to the highest-order
+     do not know, we need to assume that all bits up to the highest-order
      bit in MASK will be needed.  This is how we form such a mask.  */
-  if (op_mode)
-    fuller_mask = (GET_MODE_BITSIZE (op_mode) >= HOST_BITS_PER_WIDE_INT
-                  ? GET_MODE_MASK (op_mode)
-                  : (((unsigned HOST_WIDE_INT) 1 << (floor_log2 (mask) + 1))
-                     - 1));
+  if (mask & ((unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1)))
+    fuller_mask = ~(unsigned HOST_WIDE_INT) 0;
   else
-    fuller_mask = ~(HOST_WIDE_INT) 0;
+    fuller_mask = (((unsigned HOST_WIDE_INT) 1 << (floor_log2 (mask) + 1))
+                  - 1);
 
   /* Determine what bits of X are guaranteed to be (non)zero.  */
   nonzero = nonzero_bits (x, mode);
@@ -6900,7 +6901,7 @@ force_to_mode (x, mode, mask, reg, just_select)
      get X in the proper mode.  */
   if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode)
       && (GET_MODE_MASK (GET_MODE (x)) & ~mask) == 0)
-    return gen_lowpart_for_combine (mode, x);
+    return gen_lowpart (mode, x);
 
   /* If we aren't changing the mode, X is not a SUBREG, and all zero bits in
      MASK are already known to be zero in X, we need not do anything.  */
@@ -6984,7 +6985,7 @@ force_to_mode (x, mode, mask, reg, just_select)
              int width = GET_MODE_BITSIZE (GET_MODE (x));
              rtx y;
 
-             /* If MODE is narrower that HOST_WIDE_INT and CVAL is a negative
+             /* If MODE is narrower than 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)
@@ -7093,12 +7094,12 @@ force_to_mode (x, mode, mask, reg, just_select)
       /* For most binary operations, just propagate into the operation and
         change the mode if we have an operation of that mode.  */
 
-      op0 = gen_lowpart_for_combine (op_mode,
-                                    force_to_mode (XEXP (x, 0), mode, mask,
-                                                   reg, next_select));
-      op1 = gen_lowpart_for_combine (op_mode,
-                                    force_to_mode (XEXP (x, 1), mode, mask,
-                                                   reg, next_select));
+      op0 = gen_lowpart (op_mode,
+                        force_to_mode (XEXP (x, 0), mode, mask,
+                                       reg, next_select));
+      op1 = gen_lowpart (op_mode,
+                        force_to_mode (XEXP (x, 1), mode, mask,
+                                       reg, next_select));
 
       if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
        x = gen_binary (code, op_mode, op0, op1);
@@ -7130,9 +7131,9 @@ force_to_mode (x, mode, mask, reg, just_select)
       else
        mask = fuller_mask;
 
-      op0 = gen_lowpart_for_combine (op_mode,
-                                    force_to_mode (XEXP (x, 0), op_mode,
-                                                   mask, reg, next_select));
+      op0 = gen_lowpart (op_mode,
+                        force_to_mode (XEXP (x, 0), op_mode,
+                                       mask, reg, next_select));
 
       if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0))
        x = gen_binary (code, op_mode, op0, XEXP (x, 1));
@@ -7155,9 +7156,8 @@ force_to_mode (x, mode, mask, reg, just_select)
 
          /* We can only change the mode of the shift if we can do arithmetic
             in the mode of the shift and INNER_MASK is no wider than the
-            width of OP_MODE.  */
-         if (GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT
-             || (inner_mask & ~GET_MODE_MASK (op_mode)) != 0)
+            width of X's mode.  */
+         if ((inner_mask & ~GET_MODE_MASK (GET_MODE (x))) != 0)
            op_mode = GET_MODE (x);
 
          inner = force_to_mode (inner, op_mode, inner_mask, reg, next_select);
@@ -7266,8 +7266,7 @@ force_to_mode (x, mode, mask, reg, just_select)
          && (INTVAL (XEXP (x, 1))
              <= GET_MODE_BITSIZE (GET_MODE (x)) - (floor_log2 (mask) + 1))
          && GET_CODE (XEXP (x, 0)) == ASHIFT
-         && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
-         && INTVAL (XEXP (XEXP (x, 0), 1)) == INTVAL (XEXP (x, 1)))
+         && XEXP (XEXP (x, 0), 1) == XEXP (x, 1))
        return force_to_mode (XEXP (XEXP (x, 0), 0), mode, mask,
                              reg, next_select);
 
@@ -7329,9 +7328,9 @@ force_to_mode (x, mode, mask, reg, just_select)
       mask = fuller_mask;
 
     unop:
-      op0 = gen_lowpart_for_combine (op_mode,
-                                    force_to_mode (XEXP (x, 0), mode, mask,
-                                                   reg, next_select));
+      op0 = gen_lowpart (op_mode,
+                        force_to_mode (XEXP (x, 0), mode, mask,
+                                       reg, next_select));
       if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0))
        x = simplify_gen_unary (code, op_mode, op0, op_mode);
       break;
@@ -7353,11 +7352,11 @@ force_to_mode (x, mode, mask, reg, just_select)
         written in a narrower mode.  We play it safe and do not do so.  */
 
       SUBST (XEXP (x, 1),
-            gen_lowpart_for_combine (GET_MODE (x),
+            gen_lowpart (GET_MODE (x),
                                      force_to_mode (XEXP (x, 1), mode,
                                                     mask, reg, next_select)));
       SUBST (XEXP (x, 2),
-            gen_lowpart_for_combine (GET_MODE (x),
+            gen_lowpart (GET_MODE (x),
                                      force_to_mode (XEXP (x, 2), mode,
                                                     mask, reg, next_select)));
       break;
@@ -7367,7 +7366,7 @@ force_to_mode (x, mode, mask, reg, just_select)
     }
 
   /* Ensure we return a value of the proper mode.  */
-  return gen_lowpart_for_combine (mode, x);
+  return gen_lowpart (mode, x);
 }
 \f
 /* Return nonzero if X is an expression that has one of two values depending on
@@ -7378,9 +7377,7 @@ force_to_mode (x, mode, mask, reg, just_select)
    If we return zero, we set *PTRUE and *PFALSE to X.  */
 
 static rtx
-if_then_else_cond (x, ptrue, pfalse)
-     rtx x;
-     rtx *ptrue, *pfalse;
+if_then_else_cond (rtx x, rtx *ptrue, rtx *pfalse)
 {
   enum machine_mode mode = GET_MODE (x);
   enum rtx_code code = GET_CODE (x);
@@ -7389,7 +7386,7 @@ if_then_else_cond (x, ptrue, pfalse)
 
   /* If we are comparing a value against zero, we are done.  */
   if ((code == NE || code == EQ)
-      && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
+      && XEXP (x, 1) == const0_rtx)
     {
       *ptrue = (code == NE) ? const_true_rtx : const0_rtx;
       *pfalse = (code == NE) ? const0_rtx : const_true_rtx;
@@ -7398,7 +7395,7 @@ if_then_else_cond (x, ptrue, pfalse)
 
   /* If this is a unary operation whose operand has one of two values, apply
      our opcode to compute those values.  */
-  else if (GET_RTX_CLASS (code) == '1'
+  else if (UNARY_P (x)
           && (cond0 = if_then_else_cond (XEXP (x, 0), &true0, &false0)) != 0)
     {
       *ptrue = simplify_gen_unary (code, mode, true0, GET_MODE (XEXP (x, 0)));
@@ -7415,8 +7412,7 @@ if_then_else_cond (x, ptrue, pfalse)
   /* If this is a binary operation, see if either side has only one of two
      values.  If either one does or if both do and they are conditional on
      the same value, compute the new true and false values.  */
-  else if (GET_RTX_CLASS (code) == 'c' || GET_RTX_CLASS (code) == '2'
-          || GET_RTX_CLASS (code) == '<')
+  else if (BINARY_P (x))
     {
       cond0 = if_then_else_cond (XEXP (x, 0), &true0, &false0);
       cond1 = if_then_else_cond (XEXP (x, 1), &true1, &false1);
@@ -7452,8 +7448,8 @@ if_then_else_cond (x, ptrue, pfalse)
          cond0 = XEXP (XEXP (x, 0), 0);
          cond1 = XEXP (XEXP (x, 1), 0);
 
-         if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
-             && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
+         if (COMPARISON_P (cond0)
+             && COMPARISON_P (cond1)
              && ((GET_CODE (cond0) == combine_reversed_comparison_code (cond1)
                   && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
                   && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
@@ -7483,8 +7479,8 @@ if_then_else_cond (x, ptrue, pfalse)
          cond0 = XEXP (XEXP (x, 0), 0);
          cond1 = XEXP (XEXP (x, 1), 0);
 
-         if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
-             && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
+         if (COMPARISON_P (cond0)
+             && COMPARISON_P (cond1)
              && ((GET_CODE (cond0) == combine_reversed_comparison_code (cond1)
                   && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
                   && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
@@ -7523,12 +7519,16 @@ if_then_else_cond (x, ptrue, pfalse)
           && 0 != (cond0 = if_then_else_cond (SUBREG_REG (x),
                                               &true0, &false0)))
     {
-      *ptrue = simplify_gen_subreg (mode, true0,
+      true0 = simplify_gen_subreg (mode, true0,
+                                  GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
+      false0 = simplify_gen_subreg (mode, false0,
                                    GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
-      *pfalse = simplify_gen_subreg (mode, false0,
-                                    GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
-
-      return cond0;
+      if (true0 && false0)
+       {
+         *ptrue = true0;
+         *pfalse = false0;
+         return cond0;
+       }
     }
 
   /* If X is a constant, this isn't special and will cause confusions
@@ -7556,7 +7556,7 @@ if_then_else_cond (x, ptrue, pfalse)
     }
 
   /* Likewise for 0 or a single bit.  */
-  else if (mode != VOIDmode
+  else if (SCALAR_INT_MODE_P (mode)
           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
           && exact_log2 (nz = nonzero_bits (x, mode)) >= 0)
     {
@@ -7578,10 +7578,7 @@ if_then_else_cond (x, ptrue, pfalse)
    arise with IF_THEN_ELSE expressions.  */
 
 static rtx
-known_cond (x, cond, reg, val)
-     rtx x;
-     enum rtx_code cond;
-     rtx reg, val;
+known_cond (rtx x, enum rtx_code cond, rtx reg, rtx val)
 {
   enum rtx_code code = GET_CODE (x);
   rtx temp;
@@ -7621,14 +7618,14 @@ known_cond (x, cond, reg, val)
   /* The only other cases we handle are MIN, MAX, and comparisons if the
      operands are the same as REG and VAL.  */
 
-  else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c')
+  else if (COMPARISON_P (x) || COMMUTATIVE_ARITH_P (x))
     {
       if (rtx_equal_p (XEXP (x, 0), val))
        cond = swap_condition (cond), temp = val, val = reg, reg = temp;
 
       if (rtx_equal_p (XEXP (x, 0), reg) && rtx_equal_p (XEXP (x, 1), val))
        {
-         if (GET_RTX_CLASS (code) == '<')
+         if (COMPARISON_P (x))
            {
              if (comparison_dominates_p (cond, code))
                return const_true_rtx;
@@ -7732,9 +7729,7 @@ known_cond (x, cond, reg, val)
    assignment as a field assignment.  */
 
 static int
-rtx_equal_for_field_assignment_p (x, y)
-     rtx x;
-     rtx y;
+rtx_equal_for_field_assignment_p (rtx x, rtx y)
 {
   if (x == y || rtx_equal_p (x, y))
     return 1;
@@ -7745,16 +7740,16 @@ rtx_equal_for_field_assignment_p (x, y)
   /* Check for a paradoxical SUBREG of a MEM compared with the MEM.
      Note that all SUBREGs of MEM are paradoxical; otherwise they
      would have been rewritten.  */
-  if (GET_CODE (x) == MEM && GET_CODE (y) == SUBREG
-      && GET_CODE (SUBREG_REG (y)) == MEM
+  if (MEM_P (x) && GET_CODE (y) == SUBREG
+      && MEM_P (SUBREG_REG (y))
       && rtx_equal_p (SUBREG_REG (y),
-                     gen_lowpart_for_combine (GET_MODE (SUBREG_REG (y)), x)))
+                     gen_lowpart (GET_MODE (SUBREG_REG (y)), x)))
     return 1;
 
-  if (GET_CODE (y) == MEM && GET_CODE (x) == SUBREG
-      && GET_CODE (SUBREG_REG (x)) == MEM
+  if (MEM_P (y) && GET_CODE (x) == SUBREG
+      && MEM_P (SUBREG_REG (x))
       && rtx_equal_p (SUBREG_REG (x),
-                     gen_lowpart_for_combine (GET_MODE (SUBREG_REG (x)), y)))
+                     gen_lowpart (GET_MODE (SUBREG_REG (x)), y)))
     return 1;
 
   /* We used to see if get_last_value of X and Y were the same but that's
@@ -7771,8 +7766,7 @@ rtx_equal_for_field_assignment_p (x, y)
    We only handle the most common cases.  */
 
 static rtx
-make_field_assignment (x)
-     rtx x;
+make_field_assignment (rtx x)
 {
   rtx dest = SET_DEST (x);
   rtx src = SET_SRC (x);
@@ -7806,6 +7800,7 @@ make_field_assignment (x)
           && (GET_MODE_SIZE (GET_MODE (XEXP (src, 0)))
               < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (src, 0)))))
           && GET_CODE (SUBREG_REG (XEXP (src, 0))) == ROTATE
+          && GET_CODE (XEXP (SUBREG_REG (XEXP (src, 0)), 0)) == CONST_INT
           && INTVAL (XEXP (SUBREG_REG (XEXP (src, 0)), 0)) == -2
           && rtx_equal_for_field_assignment_p (dest, XEXP (src, 1)))
     {
@@ -7899,18 +7894,17 @@ make_field_assignment (x)
    if so.  */
 
 static rtx
-apply_distributive_law (x)
-     rtx x;
+apply_distributive_law (rtx x)
 {
   enum rtx_code code = GET_CODE (x);
+  enum rtx_code inner_code;
   rtx lhs, rhs, other;
   rtx tem;
-  enum rtx_code inner_code;
 
-  /* Distributivity is not true for floating point.
-     It can change the value.  So don't do it.
-     -- rms and moshier@world.std.com.  */
-  if (FLOAT_MODE_P (GET_MODE (x)))
+  /* Distributivity is not true for floating point as it can change the
+     value.  So we don't do it unless -funsafe-math-optimizations.  */
+  if (FLOAT_MODE_P (GET_MODE (x))
+      && ! flag_unsafe_math_optimizations)
     return x;
 
   /* The outer operation can only be one of the following:  */
@@ -7918,12 +7912,12 @@ apply_distributive_law (x)
       && code != PLUS && code != MINUS)
     return x;
 
-  lhs = XEXP (x, 0), rhs = XEXP (x, 1);
+  lhs = XEXP (x, 0);
+  rhs = XEXP (x, 1);
 
   /* If either operand is a primitive we can't do anything, so get out
      fast.  */
-  if (GET_RTX_CLASS (GET_CODE (lhs)) == 'o'
-      || GET_RTX_CLASS (GET_CODE (rhs)) == 'o')
+  if (OBJECT_P (lhs) || OBJECT_P (rhs))
     return x;
 
   lhs = expand_compound_operation (lhs);
@@ -7977,7 +7971,7 @@ apply_distributive_law (x)
 
       tem = gen_binary (code, GET_MODE (SUBREG_REG (lhs)),
                        SUBREG_REG (lhs), SUBREG_REG (rhs));
-      return gen_lowpart_for_combine (GET_MODE (x), tem);
+      return gen_lowpart (GET_MODE (x), tem);
 
     default:
       return x;
@@ -7985,1110 +7979,275 @@ apply_distributive_law (x)
 
   /* Set LHS and RHS to the inner operands (A and B in the example
      above) and set OTHER to the common operand (C in the example).
-     These is only one way to do this unless the inner operation is
+     There is only one way to do this unless the inner operation is
      commutative.  */
-  if (GET_RTX_CLASS (inner_code) == 'c'
+  if (COMMUTATIVE_ARITH_P (lhs)
       && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 0)))
     other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 1);
-  else if (GET_RTX_CLASS (inner_code) == 'c'
+  else if (COMMUTATIVE_ARITH_P (lhs)
           && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 1)))
     other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 0);
-  else if (GET_RTX_CLASS (inner_code) == 'c'
+  else if (COMMUTATIVE_ARITH_P (lhs)
           && rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 0)))
     other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 1);
   else if (rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 1)))
-    other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 0);
-  else
-    return x;
-
-  /* Form the new inner operation, seeing if it simplifies first.  */
-  tem = gen_binary (code, GET_MODE (x), lhs, rhs);
-
-  /* There is one exception to the general way of distributing:
-     (a ^ b) | (a ^ c) -> (~a) & (b ^ c)  */
-  if (code == XOR && inner_code == IOR)
-    {
-      inner_code = AND;
-      other = simplify_gen_unary (NOT, GET_MODE (x), other, GET_MODE (x));
-    }
-
-  /* We may be able to continuing distributing the result, so call
-     ourselves recursively on the inner operation before forming the
-     outer operation, which we return.  */
-  return gen_binary (inner_code, GET_MODE (x),
-                    apply_distributive_law (tem), other);
-}
-\f
-/* We have X, a logical `and' of VAROP with the constant CONSTOP, to be done
-   in MODE.
-
-   Return an equivalent form, if different from X.  Otherwise, return X.  If
-   X is zero, we are to always construct the equivalent form.  */
-
-static rtx
-simplify_and_const_int (x, mode, varop, constop)
-     rtx x;
-     enum machine_mode mode;
-     rtx varop;
-     unsigned HOST_WIDE_INT constop;
-{
-  unsigned HOST_WIDE_INT nonzero;
-  int i;
-
-  /* Simplify VAROP knowing that we will be only looking at some of the
-     bits in it.
-
-     Note by passing in CONSTOP, we guarantee that the bits not set in
-     CONSTOP are not significant and will never be examined.  We must
-     ensure that is the case by explicitly masking out those bits
-     before returning.  */
-  varop = force_to_mode (varop, mode, constop, NULL_RTX, 0);
-
-  /* If VAROP is a CLOBBER, we will fail so return it.  */
-  if (GET_CODE (varop) == CLOBBER)
-    return varop;
-
-  /* If VAROP is a CONST_INT, then we need to apply the mask in CONSTOP
-     to VAROP and return the new constant.  */
-  if (GET_CODE (varop) == CONST_INT)
-    return GEN_INT (trunc_int_for_mode (INTVAL (varop) & constop, mode));
-
-  /* See what bits may be nonzero in VAROP.  Unlike the general case of
-     a call to nonzero_bits, here we don't care about bits outside
-     MODE.  */
-
-  nonzero = nonzero_bits (varop, mode) & GET_MODE_MASK (mode);
-
-  /* Turn off all bits in the constant that are known to already be zero.
-     Thus, if the AND isn't needed at all, we will have CONSTOP == NONZERO_BITS
-     which is tested below.  */
-
-  constop &= nonzero;
-
-  /* If we don't have any bits left, return zero.  */
-  if (constop == 0)
-    return const0_rtx;
-
-  /* If VAROP is a NEG of something known to be zero or 1 and CONSTOP is
-     a power of two, we can replace this with an ASHIFT.  */
-  if (GET_CODE (varop) == NEG && nonzero_bits (XEXP (varop, 0), mode) == 1
-      && (i = exact_log2 (constop)) >= 0)
-    return simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (varop, 0), i);
-
-  /* If VAROP is an IOR or XOR, apply the AND to both branches of the IOR
-     or XOR, then try to apply the distributive law.  This may eliminate
-     operations if either branch can be simplified because of the AND.
-     It may also make some cases more complex, but those cases probably
-     won't match a pattern either with or without this.  */
-
-  if (GET_CODE (varop) == IOR || GET_CODE (varop) == XOR)
-    return
-      gen_lowpart_for_combine
-       (mode,
-        apply_distributive_law
-        (gen_binary (GET_CODE (varop), GET_MODE (varop),
-                     simplify_and_const_int (NULL_RTX, GET_MODE (varop),
-                                             XEXP (varop, 0), constop),
-                     simplify_and_const_int (NULL_RTX, GET_MODE (varop),
-                                             XEXP (varop, 1), constop))));
-
-  /* If VAROP is PLUS, and the constant is a mask of low bite, distribute
-     the AND and see if one of the operands simplifies to zero.  If so, we
-     may eliminate it.  */
-
-  if (GET_CODE (varop) == PLUS
-      && exact_log2 (constop + 1) >= 0)
-    {
-      rtx o0, o1;
-
-      o0 = simplify_and_const_int (NULL_RTX, mode, XEXP (varop, 0), constop);
-      o1 = simplify_and_const_int (NULL_RTX, mode, XEXP (varop, 1), constop);
-      if (o0 == const0_rtx)
-       return o1;
-      if (o1 == const0_rtx)
-       return o0;
-    }
-
-  /* Get VAROP in MODE.  Try to get a SUBREG if not.  Don't make a new SUBREG
-     if we already had one (just check for the simplest cases).  */
-  if (x && GET_CODE (XEXP (x, 0)) == SUBREG
-      && GET_MODE (XEXP (x, 0)) == mode
-      && SUBREG_REG (XEXP (x, 0)) == varop)
-    varop = XEXP (x, 0);
-  else
-    varop = gen_lowpart_for_combine (mode, varop);
-
-  /* If we can't make the SUBREG, try to return what we were given.  */
-  if (GET_CODE (varop) == CLOBBER)
-    return x ? x : varop;
-
-  /* If we are only masking insignificant bits, return VAROP.  */
-  if (constop == nonzero)
-    x = varop;
-  else
-    {
-      /* Otherwise, return an AND.  */
-      constop = trunc_int_for_mode (constop, mode);
-      /* See how much, if any, of X we can use.  */
-      if (x == 0 || GET_CODE (x) != AND || GET_MODE (x) != mode)
-       x = gen_binary (AND, mode, varop, GEN_INT (constop));
-
-      else
-       {
-         if (GET_CODE (XEXP (x, 1)) != CONST_INT
-             || (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) != constop)
-           SUBST (XEXP (x, 1), GEN_INT (constop));
-
-         SUBST (XEXP (x, 0), varop);
-       }
-    }
-
-  return x;
-}
-\f
-#define nonzero_bits_with_known(X, MODE) \
-  cached_nonzero_bits (X, MODE, known_x, known_mode, known_ret)
-
-/* The function cached_nonzero_bits is a wrapper around nonzero_bits1.
-   It avoids exponential behavior in nonzero_bits1 when X has
-   identical subexpressions on the first or the second level.  */
-
-static unsigned HOST_WIDE_INT
-cached_nonzero_bits (x, mode, known_x, known_mode, known_ret)
-     rtx x;
-     enum machine_mode mode;
-     rtx known_x;
-     enum machine_mode known_mode;
-     unsigned HOST_WIDE_INT known_ret;
-{
-  if (x == known_x && mode == known_mode)
-    return known_ret;
-
-  /* Try to find identical subexpressions.  If found call
-     nonzero_bits1 on X with the subexpressions as KNOWN_X and the
-     precomputed value for the subexpression as KNOWN_RET.  */
-
-  if (GET_RTX_CLASS (GET_CODE (x)) == '2'
-      || GET_RTX_CLASS (GET_CODE (x)) == 'c')
-    {
-      rtx x0 = XEXP (x, 0);
-      rtx x1 = XEXP (x, 1);
-
-      /* Check the first level.  */
-      if (x0 == x1)
-       return nonzero_bits1 (x, mode, x0, mode,
-                             nonzero_bits_with_known (x0, mode));
-
-      /* Check the second level.  */
-      if ((GET_RTX_CLASS (GET_CODE (x0)) == '2'
-          || GET_RTX_CLASS (GET_CODE (x0)) == 'c')
-         && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
-       return nonzero_bits1 (x, mode, x1, mode,
-                             nonzero_bits_with_known (x1, mode));
-
-      if ((GET_RTX_CLASS (GET_CODE (x1)) == '2'
-          || GET_RTX_CLASS (GET_CODE (x1)) == 'c')
-         && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
-       return nonzero_bits1 (x, mode, x0, mode,
-                        nonzero_bits_with_known (x0, mode));
-    }
-
-  return nonzero_bits1 (x, mode, known_x, known_mode, known_ret);
-}
-
-/* We let num_sign_bit_copies recur into nonzero_bits as that is useful.
-   We don't let nonzero_bits recur into num_sign_bit_copies, because that
-   is less useful.  We can't allow both, because that results in exponential
-   run time recursion.  There is a nullstone testcase that triggered
-   this.  This macro avoids accidental uses of num_sign_bit_copies.  */
-#define cached_num_sign_bit_copies()
-
-/* 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
-   a shift, AND, or zero_extract, we can do better.  */
-
-static unsigned HOST_WIDE_INT
-nonzero_bits1 (x, mode, known_x, known_mode, known_ret)
-     rtx x;
-     enum machine_mode mode;
-     rtx known_x;
-     enum machine_mode known_mode;
-     unsigned HOST_WIDE_INT known_ret;
-{
-  unsigned HOST_WIDE_INT nonzero = GET_MODE_MASK (mode);
-  unsigned HOST_WIDE_INT inner_nz;
-  enum rtx_code code;
-  unsigned int mode_width = GET_MODE_BITSIZE (mode);
-  rtx tem;
-
-  /* For floating-point values, assume all bits are needed.  */
-  if (FLOAT_MODE_P (GET_MODE (x)) || FLOAT_MODE_P (mode))
-    return nonzero;
-
-  /* If X is wider than MODE, use its mode instead.  */
-  if (GET_MODE_BITSIZE (GET_MODE (x)) > mode_width)
-    {
-      mode = GET_MODE (x);
-      nonzero = GET_MODE_MASK (mode);
-      mode_width = GET_MODE_BITSIZE (mode);
-    }
-
-  if (mode_width > HOST_BITS_PER_WIDE_INT)
-    /* Our only callers in this case look for single bit values.  So
-       just return the mode mask.  Those tests will then be false.  */
-    return nonzero;
-
-#ifndef WORD_REGISTER_OPERATIONS
-  /* If MODE is wider than X, but both are a single word for both the host
-     and target machines, we can compute this from which bits of the
-     object might be nonzero in its own mode, taking into account the fact
-     that on many CISC machines, accessing an object in a wider mode
-     causes the high-order bits to become undefined.  So they are
-     not known to be zero.  */
-
-  if (GET_MODE (x) != VOIDmode && GET_MODE (x) != mode
-      && GET_MODE_BITSIZE (GET_MODE (x)) <= BITS_PER_WORD
-      && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT
-      && GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (GET_MODE (x)))
-    {
-      nonzero &= nonzero_bits_with_known (x, GET_MODE (x));
-      nonzero |= GET_MODE_MASK (mode) & ~GET_MODE_MASK (GET_MODE (x));
-      return nonzero;
-    }
-#endif
-
-  code = GET_CODE (x);
-  switch (code)
-    {
-    case REG:
-#if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
-      /* If pointers extend unsigned and this is a pointer in Pmode, say that
-        all the bits above ptr_mode are known to be zero.  */
-      if (POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
-         && REG_POINTER (x))
-       nonzero &= GET_MODE_MASK (ptr_mode);
-#endif
-
-      /* Include declared information about alignment of pointers.  */
-      /* ??? We don't properly preserve REG_POINTER changes across
-        pointer-to-integer casts, so we can't trust it except for
-        things that we know must be pointers.  See execute/960116-1.c.  */
-      if ((x == stack_pointer_rtx
-          || x == frame_pointer_rtx
-          || x == arg_pointer_rtx)
-         && REGNO_POINTER_ALIGN (REGNO (x)))
-       {
-         unsigned HOST_WIDE_INT alignment
-           = REGNO_POINTER_ALIGN (REGNO (x)) / BITS_PER_UNIT;
-
-#ifdef PUSH_ROUNDING
-         /* If PUSH_ROUNDING is defined, it is possible for the
-            stack to be momentarily aligned only to that amount,
-            so we pick the least alignment.  */
-         if (x == stack_pointer_rtx && PUSH_ARGS)
-           alignment = MIN (PUSH_ROUNDING (1), alignment);
-#endif
-
-         nonzero &= ~(alignment - 1);
-       }
-
-      /* If X is a register whose nonzero bits value is current, use it.
-        Otherwise, if X is a register whose value we can find, use that
-        value.  Otherwise, use the previously-computed global nonzero bits
-        for this register.  */
-
-      if (reg_last_set_value[REGNO (x)] != 0
-         && (reg_last_set_mode[REGNO (x)] == mode
-             || (GET_MODE_CLASS (reg_last_set_mode[REGNO (x)]) == MODE_INT
-                 && GET_MODE_CLASS (mode) == MODE_INT))
-         && (reg_last_set_label[REGNO (x)] == label_tick
-             || (REGNO (x) >= FIRST_PSEUDO_REGISTER
-                 && REG_N_SETS (REGNO (x)) == 1
-                 && ! 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;
-
-      tem = get_last_value (x);
-
-      if (tem)
-       {
-#ifdef SHORT_IMMEDIATES_SIGN_EXTEND
-         /* If X is narrower than MODE and TEM is a non-negative
-            constant that would appear negative in the mode of X,
-            sign-extend it for use in reg_nonzero_bits because some
-            machines (maybe most) will actually do the sign-extension
-            and this is the conservative approach.
-
-            ??? For 2.5, try to tighten up the MD files in this regard
-            instead of this kludge.  */
-
-         if (GET_MODE_BITSIZE (GET_MODE (x)) < mode_width
-             && GET_CODE (tem) == CONST_INT
-             && INTVAL (tem) > 0
-             && 0 != (INTVAL (tem)
-                      & ((HOST_WIDE_INT) 1
-                         << (GET_MODE_BITSIZE (GET_MODE (x)) - 1))))
-           tem = GEN_INT (INTVAL (tem)
-                          | ((HOST_WIDE_INT) (-1)
-                             << GET_MODE_BITSIZE (GET_MODE (x))));
-#endif
-         return nonzero_bits_with_known (tem, mode) & nonzero;
-       }
-      else if (nonzero_sign_valid && reg_nonzero_bits[REGNO (x)])
-       {
-         unsigned HOST_WIDE_INT mask = reg_nonzero_bits[REGNO (x)];
-
-         if (GET_MODE_BITSIZE (GET_MODE (x)) < mode_width)
-           /* We don't know anything about the upper bits.  */
-           mask |= GET_MODE_MASK (mode) ^ GET_MODE_MASK (GET_MODE (x));
-         return nonzero & mask;
-       }
-      else
-       return nonzero;
-
-    case CONST_INT:
-#ifdef SHORT_IMMEDIATES_SIGN_EXTEND
-      /* If X is negative in MODE, sign-extend the value.  */
-      if (INTVAL (x) > 0 && mode_width < BITS_PER_WORD
-         && 0 != (INTVAL (x) & ((HOST_WIDE_INT) 1 << (mode_width - 1))))
-       return (INTVAL (x) | ((HOST_WIDE_INT) (-1) << mode_width));
-#endif
-
-      return INTVAL (x);
-
-    case MEM:
-#ifdef LOAD_EXTEND_OP
-      /* In many, if not most, RISC machines, reading a byte from memory
-        zeros the rest of the register.  Noticing that fact saves a lot
-        of extra zero-extends.  */
-      if (LOAD_EXTEND_OP (GET_MODE (x)) == ZERO_EXTEND)
-       nonzero &= GET_MODE_MASK (GET_MODE (x));
-#endif
-      break;
-
-    case EQ:  case NE:
-    case UNEQ:  case LTGT:
-    case GT:  case GTU:  case UNGT:
-    case LT:  case LTU:  case UNLT:
-    case GE:  case GEU:  case UNGE:
-    case LE:  case LEU:  case UNLE:
-    case UNORDERED: case ORDERED:
-
-      /* If this produces an integer result, we know which bits are set.
-        Code here used to clear bits outside the mode of X, but that is
-        now done above.  */
-
-      if (GET_MODE_CLASS (mode) == MODE_INT
-         && mode_width <= HOST_BITS_PER_WIDE_INT)
-       nonzero = STORE_FLAG_VALUE;
-      break;
-
-    case NEG:
-#if 0
-      /* Disabled to avoid exponential mutual recursion between nonzero_bits
-        and num_sign_bit_copies.  */
-      if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
-         == GET_MODE_BITSIZE (GET_MODE (x)))
-       nonzero = 1;
-#endif
-
-      if (GET_MODE_SIZE (GET_MODE (x)) < mode_width)
-       nonzero |= (GET_MODE_MASK (mode) & ~GET_MODE_MASK (GET_MODE (x)));
-      break;
-
-    case ABS:
-#if 0
-      /* Disabled to avoid exponential mutual recursion between nonzero_bits
-        and num_sign_bit_copies.  */
-      if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
-         == GET_MODE_BITSIZE (GET_MODE (x)))
-       nonzero = 1;
-#endif
-      break;
-
-    case TRUNCATE:
-      nonzero &= (nonzero_bits_with_known (XEXP (x, 0), mode)
-                 & GET_MODE_MASK (mode));
-      break;
-
-    case ZERO_EXTEND:
-      nonzero &= nonzero_bits_with_known (XEXP (x, 0), mode);
-      if (GET_MODE (XEXP (x, 0)) != VOIDmode)
-       nonzero &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
-      break;
-
-    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 nonzero.  */
-      inner_nz = nonzero_bits_with_known (XEXP (x, 0), mode);
-      if (GET_MODE (XEXP (x, 0)) != VOIDmode)
-       {
-         inner_nz &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
-         if (inner_nz
-             & (((HOST_WIDE_INT) 1
-                 << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1))))
-           inner_nz |= (GET_MODE_MASK (mode)
-                        & ~GET_MODE_MASK (GET_MODE (XEXP (x, 0))));
-       }
-
-      nonzero &= inner_nz;
-      break;
-
-    case AND:
-      nonzero &= (nonzero_bits_with_known (XEXP (x, 0), mode)
-                 & nonzero_bits_with_known (XEXP (x, 1), mode));
-      break;
-
-    case XOR:   case IOR:
-    case UMIN:  case UMAX:  case SMIN:  case SMAX:
-      {
-       unsigned HOST_WIDE_INT nonzero0 =
-         nonzero_bits_with_known (XEXP (x, 0), mode);
-
-       /* Don't call nonzero_bits for the second time if it cannot change
-          anything.  */
-       if ((nonzero & nonzero0) != nonzero)
-         nonzero &= (nonzero0
-                     | nonzero_bits_with_known (XEXP (x, 1), mode));
-      }
-      break;
-
-    case PLUS:  case MINUS:
-    case MULT:
-    case DIV:   case UDIV:
-    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 nonzero bit)
-        and the number of low-order zero bits for each value.  */
-      {
-       unsigned HOST_WIDE_INT nz0 =
-         nonzero_bits_with_known (XEXP (x, 0), mode);
-       unsigned HOST_WIDE_INT nz1 =
-         nonzero_bits_with_known (XEXP (x, 1), mode);
-       int sign_index = GET_MODE_BITSIZE (GET_MODE (x)) - 1;
-       int width0 = floor_log2 (nz0) + 1;
-       int width1 = floor_log2 (nz1) + 1;
-       int low0 = floor_log2 (nz0 & -nz0);
-       int low1 = floor_log2 (nz1 & -nz1);
-       HOST_WIDE_INT op0_maybe_minusp
-         = (nz0 & ((HOST_WIDE_INT) 1 << sign_index));
-       HOST_WIDE_INT op1_maybe_minusp
-         = (nz1 & ((HOST_WIDE_INT) 1 << sign_index));
-       unsigned int result_width = mode_width;
-       int result_low = 0;
-
-       switch (code)
-         {
-         case PLUS:
-           result_width = MAX (width0, width1) + 1;
-           result_low = MIN (low0, low1);
-           break;
-         case MINUS:
-           result_low = MIN (low0, low1);
-           break;
-         case MULT:
-           result_width = width0 + width1;
-           result_low = low0 + low1;
-           break;
-         case DIV:
-           if (width1 == 0)
-             break;
-           if (! op0_maybe_minusp && ! op1_maybe_minusp)
-             result_width = width0;
-           break;
-         case UDIV:
-           if (width1 == 0)
-             break;
-           result_width = width0;
-           break;
-         case MOD:
-           if (width1 == 0)
-             break;
-           if (! op0_maybe_minusp && ! op1_maybe_minusp)
-             result_width = MIN (width0, width1);
-           result_low = MIN (low0, low1);
-           break;
-         case UMOD:
-           if (width1 == 0)
-             break;
-           result_width = MIN (width0, width1);
-           result_low = MIN (low0, low1);
-           break;
-         default:
-           abort ();
-         }
-
-       if (result_width < mode_width)
-         nonzero &= ((HOST_WIDE_INT) 1 << result_width) - 1;
-
-       if (result_low > 0)
-         nonzero &= ~(((HOST_WIDE_INT) 1 << result_low) - 1);
-
-#ifdef POINTERS_EXTEND_UNSIGNED
-       /* If pointers extend unsigned and this is an addition or subtraction
-          to a pointer in Pmode, all the bits above ptr_mode are known to be
-          zero.  */
-       if (POINTERS_EXTEND_UNSIGNED > 0 && GET_MODE (x) == Pmode
-           && (code == PLUS || code == MINUS)
-           && GET_CODE (XEXP (x, 0)) == REG && REG_POINTER (XEXP (x, 0)))
-         nonzero &= GET_MODE_MASK (ptr_mode);
-#endif
-      }
-      break;
-
-    case ZERO_EXTRACT:
-      if (GET_CODE (XEXP (x, 1)) == CONST_INT
-         && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
-       nonzero &= ((HOST_WIDE_INT) 1 << INTVAL (XEXP (x, 1))) - 1;
-      break;
-
-    case SUBREG:
-      /* If this is a SUBREG formed for a promoted variable that has
-        been zero-extended, we know that at least the high-order bits
-        are zero, though others might be too.  */
-
-      if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x) > 0)
-       nonzero = (GET_MODE_MASK (GET_MODE (x))
-                  & nonzero_bits_with_known (SUBREG_REG (x), GET_MODE (x)));
-
-      /* If the inner mode is a single word for both the host and target
-        machines, we can compute this from which bits of the inner
-        object might be nonzero.  */
-      if (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) <= BITS_PER_WORD
-         && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
-             <= HOST_BITS_PER_WIDE_INT))
-       {
-         nonzero &= nonzero_bits_with_known (SUBREG_REG (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)
-             || GET_CODE (SUBREG_REG (x)) != MEM)
-#endif
-           {
-             /* On many CISC machines, accessing an object in a wider mode
-                causes the high-order bits to become undefined.  So they are
-                not known to be zero.  */
-             if (GET_MODE_SIZE (GET_MODE (x))
-                 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
-               nonzero |= (GET_MODE_MASK (GET_MODE (x))
-                           & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (x))));
-           }
-       }
-      break;
-
-    case ASHIFTRT:
-    case LSHIFTRT:
-    case ASHIFT:
-    case ROTATE:
-      /* The nonzero bits are in two classes: any bits within MODE
-        that aren't in GET_MODE (x) are always significant.  The rest of the
-        nonzero bits are those that are significant in the operand of
-        the shift when shifted the appropriate number of bits.  This
-        shows that high-order bits are cleared by the right shift and
-        low-order bits by left shifts.  */
-      if (GET_CODE (XEXP (x, 1)) == CONST_INT
-         && INTVAL (XEXP (x, 1)) >= 0
-         && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
-       {
-         enum machine_mode inner_mode = GET_MODE (x);
-         unsigned int width = GET_MODE_BITSIZE (inner_mode);
-         int count = INTVAL (XEXP (x, 1));
-         unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (inner_mode);
-         unsigned HOST_WIDE_INT op_nonzero =
-           nonzero_bits_with_known (XEXP (x, 0), mode);
-         unsigned HOST_WIDE_INT inner = op_nonzero & mode_mask;
-         unsigned HOST_WIDE_INT outer = 0;
-
-         if (mode_width > width)
-           outer = (op_nonzero & nonzero & ~mode_mask);
-
-         if (code == LSHIFTRT)
-           inner >>= count;
-         else if (code == ASHIFTRT)
-           {
-             inner >>= count;
-
-             /* If the sign bit may have been nonzero before the shift, we
-                need to mark all the places it could have been copied to
-                by the shift as possibly nonzero.  */
-             if (inner & ((HOST_WIDE_INT) 1 << (width - 1 - count)))
-               inner |= (((HOST_WIDE_INT) 1 << count) - 1) << (width - count);
-           }
-         else if (code == ASHIFT)
-           inner <<= count;
-         else
-           inner = ((inner << (count % width)
-                     | (inner >> (width - (count % width)))) & mode_mask);
-
-         nonzero &= (outer | inner);
-       }
-      break;
-
-    case FFS:
-    case POPCOUNT:
-      /* This is at most the number of bits in the mode.  */
-      nonzero = ((HOST_WIDE_INT) 2 << (floor_log2 (mode_width))) - 1;
-      break;
-
-    case CLZ:
-      /* If CLZ has a known value at zero, then the nonzero bits are
-        that value, plus the number of bits in the mode minus one.  */
-      if (CLZ_DEFINED_VALUE_AT_ZERO (mode, nonzero))
-       nonzero |= ((HOST_WIDE_INT) 1 << (floor_log2 (mode_width))) - 1;
-      else
-       nonzero = -1;
-      break;
-
-    case CTZ:
-      /* If CTZ has a known value at zero, then the nonzero bits are
-        that value, plus the number of bits in the mode minus one.  */
-      if (CTZ_DEFINED_VALUE_AT_ZERO (mode, nonzero))
-       nonzero |= ((HOST_WIDE_INT) 1 << (floor_log2 (mode_width))) - 1;
-      else
-       nonzero = -1;
-      break;
-
-    case PARITY:
-      nonzero = 1;
-      break;
-
-    case IF_THEN_ELSE:
-      nonzero &= (nonzero_bits_with_known (XEXP (x, 1), mode)
-                 | nonzero_bits_with_known (XEXP (x, 2), mode));
-      break;
-
-    default:
-      break;
-    }
-
-  return nonzero;
-}
-
-/* See the macro definition above.  */
-#undef cached_num_sign_bit_copies
-\f
-#define num_sign_bit_copies_with_known(X, M) \
-  cached_num_sign_bit_copies (X, M, known_x, known_mode, known_ret)
-
-/* The function cached_num_sign_bit_copies is a wrapper around
-   num_sign_bit_copies1.  It avoids exponential behavior in
-   num_sign_bit_copies1 when X has identical subexpressions on the
-   first or the second level.  */
-
-static unsigned int
-cached_num_sign_bit_copies (x, mode, known_x, known_mode, known_ret)
-     rtx x;
-     enum machine_mode mode;
-     rtx known_x;
-     enum machine_mode known_mode;
-     unsigned int known_ret;
-{
-  if (x == known_x && mode == known_mode)
-    return known_ret;
+    other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 0);
+  else
+    return x;
 
-  /* Try to find identical subexpressions.  If found call
-     num_sign_bit_copies1 on X with the subexpressions as KNOWN_X and
-     the precomputed value for the subexpression as KNOWN_RET.  */
+  /* Form the new inner operation, seeing if it simplifies first.  */
+  tem = gen_binary (code, GET_MODE (x), lhs, rhs);
 
-  if (GET_RTX_CLASS (GET_CODE (x)) == '2'
-      || GET_RTX_CLASS (GET_CODE (x)) == 'c')
+  /* There is one exception to the general way of distributing:
+     (a | c) ^ (b | c) -> (a ^ b) & ~c  */
+  if (code == XOR && inner_code == IOR)
     {
-      rtx x0 = XEXP (x, 0);
-      rtx x1 = XEXP (x, 1);
-
-      /* Check the first level.  */
-      if (x0 == x1)
-       return
-         num_sign_bit_copies1 (x, mode, x0, mode,
-                               num_sign_bit_copies_with_known (x0, mode));
-
-      /* Check the second level.  */
-      if ((GET_RTX_CLASS (GET_CODE (x0)) == '2'
-          || GET_RTX_CLASS (GET_CODE (x0)) == 'c')
-         && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
-       return
-         num_sign_bit_copies1 (x, mode, x1, mode,
-                               num_sign_bit_copies_with_known (x1, mode));
-
-      if ((GET_RTX_CLASS (GET_CODE (x1)) == '2'
-          || GET_RTX_CLASS (GET_CODE (x1)) == 'c')
-         && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
-       return
-         num_sign_bit_copies1 (x, mode, x0, mode,
-                               num_sign_bit_copies_with_known (x0, mode));
+      inner_code = AND;
+      other = simplify_gen_unary (NOT, GET_MODE (x), other, GET_MODE (x));
     }
 
-  return num_sign_bit_copies1 (x, mode, known_x, known_mode, known_ret);
+  /* We may be able to continuing distributing the result, so call
+     ourselves recursively on the inner operation before forming the
+     outer operation, which we return.  */
+  return gen_binary (inner_code, GET_MODE (x),
+                    apply_distributive_law (tem), other);
 }
+\f
+/* We have X, a logical `and' of VAROP with the constant CONSTOP, to be done
+   in MODE.
 
-/* Return the number of bits at the high-order end of X that are known to
-   be equal to the sign bit.  X will be used in mode MODE; if MODE is
-   VOIDmode, X will be used in its own mode.  The returned value  will always
-   be between 1 and the number of bits in MODE.  */
+   Return an equivalent form, if different from X.  Otherwise, return X.  If
+   X is zero, we are to always construct the equivalent form.  */
 
-static unsigned int
-num_sign_bit_copies1 (x, mode, known_x, known_mode, known_ret)
-     rtx x;
-     enum machine_mode mode;
-     rtx known_x;
-     enum machine_mode known_mode;
-     unsigned int known_ret;
+static rtx
+simplify_and_const_int (rtx x, enum machine_mode mode, rtx varop,
+                       unsigned HOST_WIDE_INT constop)
 {
-  enum rtx_code code = GET_CODE (x);
-  unsigned int bitwidth;
-  int num0, num1, result;
   unsigned HOST_WIDE_INT nonzero;
-  rtx tem;
-
-  /* If we weren't given a mode, use the mode of X.  If the mode is still
-     VOIDmode, we don't know anything.  Likewise if one of the modes is
-     floating-point.  */
-
-  if (mode == VOIDmode)
-    mode = GET_MODE (x);
+  int i;
 
-  if (mode == VOIDmode || FLOAT_MODE_P (mode) || FLOAT_MODE_P (GET_MODE (x)))
-    return 1;
+  /* Simplify VAROP knowing that we will be only looking at some of the
+     bits in it.
 
-  bitwidth = GET_MODE_BITSIZE (mode);
+     Note by passing in CONSTOP, we guarantee that the bits not set in
+     CONSTOP are not significant and will never be examined.  We must
+     ensure that is the case by explicitly masking out those bits
+     before returning.  */
+  varop = force_to_mode (varop, mode, constop, NULL_RTX, 0);
 
-  /* For a smaller object, just ignore the high bits.  */
-  if (bitwidth < GET_MODE_BITSIZE (GET_MODE (x)))
-    {
-      num0 = num_sign_bit_copies_with_known (x, GET_MODE (x));
-      return MAX (1,
-                 num0 - (int) (GET_MODE_BITSIZE (GET_MODE (x)) - bitwidth));
-    }
+  /* If VAROP is a CLOBBER, we will fail so return it.  */
+  if (GET_CODE (varop) == CLOBBER)
+    return varop;
 
-  if (GET_MODE (x) != VOIDmode && bitwidth > GET_MODE_BITSIZE (GET_MODE (x)))
-    {
-#ifndef WORD_REGISTER_OPERATIONS
-  /* If this machine does not do all register operations on the entire
-     register and MODE is wider than the mode of X, we can say nothing
-     at all about the high-order bits.  */
-      return 1;
-#else
-      /* Likewise on machines that do, if the mode of the object is smaller
-        than a word and loads of that size don't sign extend, we can say
-        nothing about the high order bits.  */
-      if (GET_MODE_BITSIZE (GET_MODE (x)) < BITS_PER_WORD
-#ifdef LOAD_EXTEND_OP
-         && LOAD_EXTEND_OP (GET_MODE (x)) != SIGN_EXTEND
-#endif
-         )
-       return 1;
-#endif
-    }
+  /* If VAROP is a CONST_INT, then we need to apply the mask in CONSTOP
+     to VAROP and return the new constant.  */
+  if (GET_CODE (varop) == CONST_INT)
+    return GEN_INT (trunc_int_for_mode (INTVAL (varop) & constop, mode));
 
-  switch (code)
-    {
-    case REG:
+  /* See what bits may be nonzero in VAROP.  Unlike the general case of
+     a call to nonzero_bits, here we don't care about bits outside
+     MODE.  */
 
-#if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
-      /* If pointers extend signed and this is a pointer in Pmode, say that
-        all the bits above ptr_mode are known to be sign bit copies.  */
-      if (! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode && mode == Pmode
-         && REG_POINTER (x))
-       return GET_MODE_BITSIZE (Pmode) - GET_MODE_BITSIZE (ptr_mode) + 1;
-#endif
+  nonzero = nonzero_bits (varop, mode) & GET_MODE_MASK (mode);
 
-      if (reg_last_set_value[REGNO (x)] != 0
-         && reg_last_set_mode[REGNO (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 (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)];
-
-      tem = get_last_value (x);
-      if (tem != 0)
-       return num_sign_bit_copies_with_known (tem, mode);
-
-      if (nonzero_sign_valid && reg_sign_bit_copies[REGNO (x)] != 0
-         && GET_MODE_BITSIZE (GET_MODE (x)) == bitwidth)
-       return reg_sign_bit_copies[REGNO (x)];
-      break;
+  /* Turn off all bits in the constant that are known to already be zero.
+     Thus, if the AND isn't needed at all, we will have CONSTOP == NONZERO_BITS
+     which is tested below.  */
 
-    case MEM:
-#ifdef LOAD_EXTEND_OP
-      /* Some RISC machines sign-extend all loads of smaller than a word.  */
-      if (LOAD_EXTEND_OP (GET_MODE (x)) == SIGN_EXTEND)
-       return MAX (1, ((int) bitwidth
-                       - (int) GET_MODE_BITSIZE (GET_MODE (x)) + 1));
-#endif
-      break;
+  constop &= nonzero;
 
-    case CONST_INT:
-      /* If the constant is negative, take its 1's complement and remask.
-        Then see how many zero bits we have.  */
-      nonzero = INTVAL (x) & GET_MODE_MASK (mode);
-      if (bitwidth <= HOST_BITS_PER_WIDE_INT
-         && (nonzero & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
-       nonzero = (~nonzero) & GET_MODE_MASK (mode);
+  /* If we don't have any bits left, return zero.  */
+  if (constop == 0)
+    return const0_rtx;
 
-      return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1);
+  /* If VAROP is a NEG of something known to be zero or 1 and CONSTOP is
+     a power of two, we can replace this with an ASHIFT.  */
+  if (GET_CODE (varop) == NEG && nonzero_bits (XEXP (varop, 0), mode) == 1
+      && (i = exact_log2 (constop)) >= 0)
+    return simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (varop, 0), i);
 
-    case SUBREG:
-      /* If this is a SUBREG for a promoted object that is sign-extended
-        and we are looking at it in a wider mode, we know that at least the
-        high-order bits are known to be sign bit copies.  */
+  /* If VAROP is an IOR or XOR, apply the AND to both branches of the IOR
+     or XOR, then try to apply the distributive law.  This may eliminate
+     operations if either branch can be simplified because of the AND.
+     It may also make some cases more complex, but those cases probably
+     won't match a pattern either with or without this.  */
 
-      if (SUBREG_PROMOTED_VAR_P (x) && ! SUBREG_PROMOTED_UNSIGNED_P (x))
-       {
-         num0 = num_sign_bit_copies_with_known (SUBREG_REG (x), mode);
-         return MAX ((int) bitwidth
-                     - (int) GET_MODE_BITSIZE (GET_MODE (x)) + 1,
-                     num0);
-       }
+  if (GET_CODE (varop) == IOR || GET_CODE (varop) == XOR)
+    return
+      gen_lowpart
+       (mode,
+        apply_distributive_law
+        (gen_binary (GET_CODE (varop), GET_MODE (varop),
+                     simplify_and_const_int (NULL_RTX, GET_MODE (varop),
+                                             XEXP (varop, 0), constop),
+                     simplify_and_const_int (NULL_RTX, GET_MODE (varop),
+                                             XEXP (varop, 1), constop))));
 
-      /* For a smaller object, just ignore the high bits.  */
-      if (bitwidth <= GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))))
-       {
-         num0 = num_sign_bit_copies_with_known (SUBREG_REG (x), VOIDmode);
-         return MAX (1, (num0
-                         - (int) (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
-                                  - bitwidth)));
-       }
+  /* If VAROP is PLUS, and the constant is a mask of low bite, distribute
+     the AND and see if one of the operands simplifies to zero.  If so, we
+     may eliminate it.  */
 
-#ifdef WORD_REGISTER_OPERATIONS
-#ifdef LOAD_EXTEND_OP
-      /* For paradoxical SUBREGs on machines where all register operations
-        affect the entire register, just look inside.  Note that we are
-        passing MODE to the recursive call, so the number of sign bit copies
-        will remain relative to that mode, not the inner mode.  */
-
-      /* This works only if loads sign extend.  Otherwise, if we get a
-        reload for the inner part, it may be loaded from the stack, and
-        then we lose all sign bit copies that existed before the store
-        to the stack.  */
-
-      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
-         && GET_CODE (SUBREG_REG (x)) == MEM)
-       return num_sign_bit_copies_with_known (SUBREG_REG (x), mode);
-#endif
-#endif
-      break;
+  if (GET_CODE (varop) == PLUS
+      && exact_log2 (constop + 1) >= 0)
+    {
+      rtx o0, o1;
 
-    case SIGN_EXTRACT:
-      if (GET_CODE (XEXP (x, 1)) == CONST_INT)
-       return MAX (1, (int) bitwidth - INTVAL (XEXP (x, 1)));
-      break;
+      o0 = simplify_and_const_int (NULL_RTX, mode, XEXP (varop, 0), constop);
+      o1 = simplify_and_const_int (NULL_RTX, mode, XEXP (varop, 1), constop);
+      if (o0 == const0_rtx)
+       return o1;
+      if (o1 == const0_rtx)
+       return o0;
+    }
 
-    case SIGN_EXTEND:
-      return (bitwidth - GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
-             + num_sign_bit_copies_with_known (XEXP (x, 0), VOIDmode));
+  /* Get VAROP in MODE.  Try to get a SUBREG if not.  Don't make a new SUBREG
+     if we already had one (just check for the simplest cases).  */
+  if (x && GET_CODE (XEXP (x, 0)) == SUBREG
+      && GET_MODE (XEXP (x, 0)) == mode
+      && SUBREG_REG (XEXP (x, 0)) == varop)
+    varop = XEXP (x, 0);
+  else
+    varop = gen_lowpart (mode, varop);
 
-    case TRUNCATE:
-      /* For a smaller object, just ignore the high bits.  */
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 0), VOIDmode);
-      return MAX (1, (num0 - (int) (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
-                                   - bitwidth)));
+  /* If we can't make the SUBREG, try to return what we were given.  */
+  if (GET_CODE (varop) == CLOBBER)
+    return x ? x : varop;
 
-    case NOT:
-      return num_sign_bit_copies_with_known (XEXP (x, 0), mode);
+  /* If we are only masking insignificant bits, return VAROP.  */
+  if (constop == nonzero)
+    x = varop;
+  else
+    {
+      /* Otherwise, return an AND.  */
+      constop = trunc_int_for_mode (constop, mode);
+      /* See how much, if any, of X we can use.  */
+      if (x == 0 || GET_CODE (x) != AND || GET_MODE (x) != mode)
+       x = gen_binary (AND, mode, varop, GEN_INT (constop));
 
-    case ROTATE:       case ROTATERT:
-      /* If we are rotating left by a number of bits less than the number
-        of sign bit copies, we can just subtract that amount from the
-        number.  */
-      if (GET_CODE (XEXP (x, 1)) == CONST_INT
-         && INTVAL (XEXP (x, 1)) >= 0
-         && INTVAL (XEXP (x, 1)) < (int) bitwidth)
+      else
        {
-         num0 = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-         return MAX (1, num0 - (code == ROTATE ? INTVAL (XEXP (x, 1))
-                                : (int) bitwidth - INTVAL (XEXP (x, 1))));
-       }
-      break;
+         if (GET_CODE (XEXP (x, 1)) != CONST_INT
+             || (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) != constop)
+           SUBST (XEXP (x, 1), GEN_INT (constop));
 
-    case NEG:
-      /* In general, this subtracts one sign bit copy.  But if the value
-        is known to be positive, the number of sign bit copies is the
-        same as that of the input.  Finally, if the input has just one bit
-        that might be nonzero, all the bits are copies of the sign bit.  */
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-      if (bitwidth > HOST_BITS_PER_WIDE_INT)
-       return num0 > 1 ? num0 - 1 : 1;
-
-      nonzero = nonzero_bits (XEXP (x, 0), mode);
-      if (nonzero == 1)
-       return bitwidth;
-
-      if (num0 > 1
-         && (((HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero))
-       num0--;
-
-      return num0;
-
-    case IOR:   case AND:   case XOR:
-    case SMIN:  case SMAX:  case UMIN:  case UMAX:
-      /* Logical operations will preserve the number of sign-bit copies.
-        MIN and MAX operations always return one of the operands.  */
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-      num1 = num_sign_bit_copies_with_known (XEXP (x, 1), mode);
-      return MIN (num0, num1);
-
-    case PLUS:  case MINUS:
-      /* For addition and subtraction, we can have a 1-bit carry.  However,
-        if we are subtracting 1 from a positive number, there will not
-        be such a carry.  Furthermore, if the positive number is known to
-        be 0 or 1, we know the result is either -1 or 0.  */
-
-      if (code == PLUS && XEXP (x, 1) == constm1_rtx
-         && bitwidth <= HOST_BITS_PER_WIDE_INT)
-       {
-         nonzero = nonzero_bits (XEXP (x, 0), mode);
-         if ((((HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero) == 0)
-           return (nonzero == 1 || nonzero == 0 ? bitwidth
-                   : bitwidth - floor_log2 (nonzero) - 1);
-       }
-
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-      num1 = num_sign_bit_copies_with_known (XEXP (x, 1), mode);
-      result = MAX (1, MIN (num0, num1) - 1);
-
-#ifdef POINTERS_EXTEND_UNSIGNED
-      /* If pointers extend signed and this is an addition or subtraction
-        to a pointer in Pmode, all the bits above ptr_mode are known to be
-        sign bit copies.  */
-      if (! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
-         && (code == PLUS || code == MINUS)
-         && GET_CODE (XEXP (x, 0)) == REG && REG_POINTER (XEXP (x, 0)))
-       result = MAX ((int) (GET_MODE_BITSIZE (Pmode)
-                            - GET_MODE_BITSIZE (ptr_mode) + 1),
-                     result);
-#endif
-      return result;
+         SUBST (XEXP (x, 0), varop);
+       }
+    }
 
-    case MULT:
-      /* The number of bits of the product is the sum of the number of
-        bits of both terms.  However, unless one of the terms if known
-        to be positive, we must allow for an additional bit since negating
-        a negative number can remove one sign bit copy.  */
+  return x;
+}
+\f
+/* Given a REG, X, compute which bits in X can be nonzero.
+   We don't care about bits outside of those defined in MODE.
 
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-      num1 = num_sign_bit_copies_with_known (XEXP (x, 1), mode);
+   For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
+   a shift, AND, or zero_extract, we can do better.  */
 
-      result = bitwidth - (bitwidth - num0) - (bitwidth - num1);
-      if (result > 0
-         && (bitwidth > HOST_BITS_PER_WIDE_INT
-             || (((nonzero_bits (XEXP (x, 0), mode)
-                   & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
-                 && ((nonzero_bits (XEXP (x, 1), mode)
-                      & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0))))
-       result--;
+static rtx
+reg_nonzero_bits_for_combine (rtx x, enum machine_mode mode,
+                             rtx known_x ATTRIBUTE_UNUSED,
+                             enum machine_mode known_mode ATTRIBUTE_UNUSED,
+                             unsigned HOST_WIDE_INT known_ret ATTRIBUTE_UNUSED,
+                             unsigned HOST_WIDE_INT *nonzero)
+{
+  rtx tem;
 
-      return MAX (1, result);
+  /* If X is a register whose nonzero bits value is current, use it.
+     Otherwise, if X is a register whose value we can find, use that
+     value.  Otherwise, use the previously-computed global nonzero bits
+     for this register.  */
 
-    case UDIV:
-      /* The result must be <= the first operand.  If the first operand
-         has the high bit set, we know nothing about the number of sign
-         bit copies.  */
-      if (bitwidth > HOST_BITS_PER_WIDE_INT)
-       return 1;
-      else if ((nonzero_bits (XEXP (x, 0), mode)
-               & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
-       return 1;
-      else
-       return num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-
-    case UMOD:
-      /* The result must be <= the second operand.  */
-      return num_sign_bit_copies_with_known (XEXP (x, 1), mode);
-
-    case DIV:
-      /* Similar to unsigned division, except that we have to worry about
-        the case where the divisor is negative, in which case we have
-        to add 1.  */
-      result = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-      if (result > 1
-         && (bitwidth > HOST_BITS_PER_WIDE_INT
-             || (nonzero_bits (XEXP (x, 1), mode)
-                 & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0))
-       result--;
-
-      return result;
-
-    case MOD:
-      result = num_sign_bit_copies_with_known (XEXP (x, 1), mode);
-      if (result > 1
-         && (bitwidth > HOST_BITS_PER_WIDE_INT
-             || (nonzero_bits (XEXP (x, 1), mode)
-                 & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0))
-       result--;
-
-      return result;
+  if (reg_stat[REGNO (x)].last_set_value != 0
+      && (reg_stat[REGNO (x)].last_set_mode == mode
+          || (GET_MODE_CLASS (reg_stat[REGNO (x)].last_set_mode) == MODE_INT
+             && GET_MODE_CLASS (mode) == MODE_INT))
+      && (reg_stat[REGNO (x)].last_set_label == label_tick
+         || (REGNO (x) >= FIRST_PSEUDO_REGISTER
+             && REG_N_SETS (REGNO (x)) == 1
+             && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR->next_bb->global_live_at_start,
+                                   REGNO (x))))
+      && INSN_CUID (reg_stat[REGNO (x)].last_set) < subst_low_cuid)
+    {
+      *nonzero &= reg_stat[REGNO (x)].last_set_nonzero_bits;
+      return NULL;
+    }
 
-    case ASHIFTRT:
-      /* Shifts by a constant add to the number of bits equal to the
-        sign bit.  */
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-      if (GET_CODE (XEXP (x, 1)) == CONST_INT
-         && INTVAL (XEXP (x, 1)) > 0)
-       num0 = MIN ((int) bitwidth, num0 + INTVAL (XEXP (x, 1)));
+  tem = get_last_value (x);
 
-      return num0;
+  if (tem)
+    {
+#ifdef SHORT_IMMEDIATES_SIGN_EXTEND
+      /* If X is narrower than MODE and TEM is a non-negative
+         constant that would appear negative in the mode of X,
+         sign-extend it for use in reg_nonzero_bits because some
+         machines (maybe most) will actually do the sign-extension
+         and this is the conservative approach.
+
+         ??? For 2.5, try to tighten up the MD files in this regard
+         instead of this kludge.  */
+
+      if (GET_MODE_BITSIZE (GET_MODE (x)) < GET_MODE_BITSIZE (mode)
+         && GET_CODE (tem) == CONST_INT
+         && INTVAL (tem) > 0
+         && 0 != (INTVAL (tem)
+                  & ((HOST_WIDE_INT) 1
+                     << (GET_MODE_BITSIZE (GET_MODE (x)) - 1))))
+       tem = GEN_INT (INTVAL (tem)
+                      | ((HOST_WIDE_INT) (-1)
+                         << GET_MODE_BITSIZE (GET_MODE (x))));
+#endif
+      return tem;
+    }
+  else if (nonzero_sign_valid && reg_stat[REGNO (x)].nonzero_bits)
+    {
+      unsigned HOST_WIDE_INT mask = reg_stat[REGNO (x)].nonzero_bits;
 
-    case ASHIFT:
-      /* Left shifts destroy copies.  */
-      if (GET_CODE (XEXP (x, 1)) != CONST_INT
-         || INTVAL (XEXP (x, 1)) < 0
-         || INTVAL (XEXP (x, 1)) >= (int) bitwidth)
-       return 1;
+      if (GET_MODE_BITSIZE (GET_MODE (x)) < GET_MODE_BITSIZE (mode))
+        /* We don't know anything about the upper bits.  */
+        mask |= GET_MODE_MASK (mode) ^ GET_MODE_MASK (GET_MODE (x));
+      *nonzero &= mask;
+    }
 
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 0), mode);
-      return MAX (1, num0 - INTVAL (XEXP (x, 1)));
+  return NULL;
+}
 
-    case IF_THEN_ELSE:
-      num0 = num_sign_bit_copies_with_known (XEXP (x, 1), mode);
-      num1 = num_sign_bit_copies_with_known (XEXP (x, 2), mode);
-      return MIN (num0, num1);
+/* Return the number of bits at the high-order end of X that are known to
+   be equal to the sign bit.  X will be used in mode MODE; if MODE is
+   VOIDmode, X will be used in its own mode.  The returned value  will always
+   be between 1 and the number of bits in MODE.  */
 
-    case EQ:  case NE:  case GE:  case GT:  case LE:  case LT:
-    case UNEQ:  case LTGT:  case UNGE:  case UNGT:  case UNLE:  case UNLT:
-    case GEU: case GTU: case LEU: case LTU:
-    case UNORDERED: case ORDERED:
-      /* If the constant is negative, take its 1's complement and remask.
-        Then see how many zero bits we have.  */
-      nonzero = STORE_FLAG_VALUE;
-      if (bitwidth <= HOST_BITS_PER_WIDE_INT
-         && (nonzero & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
-       nonzero = (~nonzero) & GET_MODE_MASK (mode);
-
-      return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1);
-      break;
+static rtx
+reg_num_sign_bit_copies_for_combine (rtx x, enum machine_mode mode,
+                                    rtx known_x ATTRIBUTE_UNUSED,
+                                    enum machine_mode known_mode
+                                    ATTRIBUTE_UNUSED,
+                                    unsigned int known_ret ATTRIBUTE_UNUSED,
+                                    unsigned int *result)
+{
+  rtx tem;
 
-    default:
-      break;
+  if (reg_stat[REGNO (x)].last_set_value != 0
+      && reg_stat[REGNO (x)].last_set_mode == mode
+      && (reg_stat[REGNO (x)].last_set_label == label_tick
+          || (REGNO (x) >= FIRST_PSEUDO_REGISTER
+             && REG_N_SETS (REGNO (x)) == 1
+             && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR->next_bb->global_live_at_start,
+                                   REGNO (x))))
+      && INSN_CUID (reg_stat[REGNO (x)].last_set) < subst_low_cuid)
+    {
+      *result = reg_stat[REGNO (x)].last_set_sign_bit_copies;
+      return NULL;
     }
 
-  /* If we haven't been able to figure it out by one of the above rules,
-     see if some of the high-order bits are known to be zero.  If so,
-     count those bits and return one less than that amount.  If we can't
-     safely compute the mask for this mode, always return BITWIDTH.  */
-
-  if (bitwidth > HOST_BITS_PER_WIDE_INT)
-    return 1;
+  tem = get_last_value (x);
+  if (tem != 0)
+    return tem;
 
-  nonzero = nonzero_bits (x, mode);
-  return (nonzero & ((HOST_WIDE_INT) 1 << (bitwidth - 1))
-         ? 1 : bitwidth - floor_log2 (nonzero) - 1);
+  if (nonzero_sign_valid && reg_stat[REGNO (x)].sign_bit_copies != 0
+      && GET_MODE_BITSIZE (GET_MODE (x)) == GET_MODE_BITSIZE (mode))
+    *result = reg_stat[REGNO (x)].sign_bit_copies;
+      
+  return NULL;
 }
 \f
 /* Return the number of "extended" bits there are in X, when interpreted
@@ -9103,10 +8262,7 @@ num_sign_bit_copies1 (x, mode, known_x, known_mode, known_ret)
    implies that it must be called from a define_split.  */
 
 unsigned int
-extended_count (x, mode, unsignedp)
-     rtx x;
-     enum machine_mode mode;
-     int unsignedp;
+extended_count (rtx x, enum machine_mode mode, int unsignedp)
 {
   if (nonzero_sign_valid == 0)
     return 0;
@@ -9133,7 +8289,7 @@ extended_count (x, mode, unsignedp)
    the width of this mode matter.  It is assumed that the width of this mode
    is smaller than or equal to HOST_BITS_PER_WIDE_INT.
 
-   If *POP0 or OP1 are NIL, it means no operation is required.  Only NEG, PLUS,
+   If *POP0 or OP1 are UNKNOWN, it means no operation is required.  Only NEG, PLUS,
    IOR, XOR, and AND are supported.  We may set *POP0 to SET if the proper
    result is simply *PCONST0.
 
@@ -9141,13 +8297,7 @@ extended_count (x, mode, unsignedp)
    return 0 and do not change *POP0, *PCONST0, and *PCOMP_P.  */
 
 static int
-merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
-     enum rtx_code *pop0;
-     HOST_WIDE_INT *pconst0;
-     enum rtx_code op1;
-     HOST_WIDE_INT const1;
-     enum machine_mode mode;
-     int *pcomp_p;
+merge_outer_ops (enum rtx_code *pop0, HOST_WIDE_INT *pconst0, enum rtx_code op1, HOST_WIDE_INT const1, enum machine_mode mode, int *pcomp_p)
 {
   enum rtx_code op0 = *pop0;
   HOST_WIDE_INT const0 = *pconst0;
@@ -9159,13 +8309,13 @@ merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
   if (op0 == AND)
     const1 &= const0;
 
-  /* If OP0 or OP1 is NIL, this is easy.  Similarly if they are the same or
+  /* If OP0 or OP1 is UNKNOWN, this is easy.  Similarly if they are the same or
      if OP0 is SET.  */
 
-  if (op1 == NIL || op0 == SET)
+  if (op1 == UNKNOWN || op0 == SET)
     return 1;
 
-  else if (op0 == NIL)
+  else if (op0 == UNKNOWN)
     op0 = op1, const0 = const1;
 
   else if (op0 == op1)
@@ -9185,7 +8335,7 @@ merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
          const0 += const1;
          break;
        case NEG:
-         op0 = NIL;
+         op0 = UNKNOWN;
          break;
        default:
          break;
@@ -9238,12 +8388,12 @@ merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
   const0 &= GET_MODE_MASK (mode);
   if (const0 == 0
       && (op0 == IOR || op0 == XOR || op0 == PLUS))
-    op0 = NIL;
+    op0 = UNKNOWN;
   else if (const0 == 0 && op0 == AND)
     op0 = SET;
   else if ((unsigned HOST_WIDE_INT) const0 == GET_MODE_MASK (mode)
           && op0 == AND)
-    op0 = NIL;
+    op0 = UNKNOWN;
 
   /* ??? Slightly redundant with the above mask, but not entirely.
      Moving this above means we'd have to sign-extend the mode mask
@@ -9265,12 +8415,9 @@ merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
    are ASHIFTRT and ROTATE, which are always done in their original mode,  */
 
 static rtx
-simplify_shift_const (x, code, result_mode, varop, orig_count)
-     rtx x;
-     enum rtx_code code;
-     enum machine_mode result_mode;
-     rtx varop;
-     int orig_count;
+simplify_shift_const (rtx x, enum rtx_code code,
+                     enum machine_mode result_mode, rtx varop,
+                     int orig_count)
 {
   enum rtx_code orig_code = code;
   unsigned int count;
@@ -9280,7 +8427,7 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
   unsigned int mode_words
     = (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
   /* We form (outer_op (code varop count) (outer_const)).  */
-  enum rtx_code outer_op = NIL;
+  enum rtx_code outer_op = UNKNOWN;
   HOST_WIDE_INT outer_const = 0;
   rtx const_rtx;
   int complement_p = 0;
@@ -9289,10 +8436,8 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
   /* Make sure and truncate the "natural" shift on the way in.  We don't
      want to do this inside the loop as it makes it more difficult to
      combine shifts.  */
-#ifdef SHIFT_COUNT_TRUNCATED
   if (SHIFT_COUNT_TRUNCATED)
     orig_count &= GET_MODE_BITSIZE (mode) - 1;
-#endif
 
   /* If we were given an invalid count, don't do anything except exactly
      what was requested.  */
@@ -9734,6 +8879,11 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
             (and (shift)) insns.  */
 
          if (GET_CODE (XEXP (varop, 1)) == CONST_INT
+             /* We can't do this if we have (ashiftrt (xor))  and the
+                constant has its sign bit set in shift_mode.  */
+             && !(code == ASHIFTRT && GET_CODE (varop) == XOR
+                  && 0 > trunc_int_for_mode (INTVAL (XEXP (varop, 1)),
+                                             shift_mode))
              && (new = simplify_binary_operation (code, result_mode,
                                                   XEXP (varop, 1),
                                                   GEN_INT (count))) != 0
@@ -9747,22 +8897,28 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
 
          /* If we can't do that, try to simplify the shift in each arm of the
             logical expression, make a new logical expression, and apply
-            the inverse distributive law.  */
-         {
-           rtx lhs = simplify_shift_const (NULL_RTX, code, shift_mode,
-                                           XEXP (varop, 0), count);
-           rtx rhs = simplify_shift_const (NULL_RTX, code, shift_mode,
-                                           XEXP (varop, 1), count);
+            the inverse distributive law.  This also can't be done
+            for some (ashiftrt (xor)).  */
+         if (GET_CODE (XEXP (varop, 1)) == CONST_INT
+            && !(code == ASHIFTRT && GET_CODE (varop) == XOR
+                 && 0 > trunc_int_for_mode (INTVAL (XEXP (varop, 1)),
+                                            shift_mode)))
+           {
+             rtx lhs = simplify_shift_const (NULL_RTX, code, shift_mode,
+                                             XEXP (varop, 0), count);
+             rtx rhs = simplify_shift_const (NULL_RTX, code, shift_mode,
+                                             XEXP (varop, 1), count);
 
-           varop = gen_binary (GET_CODE (varop), shift_mode, lhs, rhs);
-           varop = apply_distributive_law (varop);
+             varop = gen_binary (GET_CODE (varop), shift_mode, lhs, rhs);
+             varop = apply_distributive_law (varop);
 
-           count = 0;
-         }
+             count = 0;
+             continue; 
+           }
          break;
 
        case EQ:
-         /* convert (lshiftrt (eq FOO 0) C) to (xor FOO 1) if STORE_FLAG_VALUE
+         /* Convert (lshiftrt (eq FOO 0) C) to (xor FOO 1) if STORE_FLAG_VALUE
             says that the sign bit can be tested, FOO has mode MODE, C is
             GET_MODE_BITSIZE (MODE) - 1, and FOO has only its low-order bit
             that may be nonzero.  */
@@ -9939,14 +9095,14 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
 
   /* We have now finished analyzing the shift.  The result should be
      a shift of type CODE with SHIFT_MODE shifting VAROP COUNT places.  If
-     OUTER_OP is non-NIL, it is an operation that needs to be applied
+     OUTER_OP is non-UNKNOWN, it is an operation that needs to be applied
      to the result of the shift.  OUTER_CONST is the relevant constant,
      but we must turn off all bits turned off in the shift.
 
      If we were passed a value for X, see if we can use any pieces of
      it.  If not, make new rtx.  */
 
-  if (x && GET_RTX_CLASS (GET_CODE (x)) == '2'
+  if (x && GET_RTX_CLASS (GET_CODE (x)) == RTX_BIN_ARITH
       && GET_CODE (XEXP (x, 1)) == CONST_INT
       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) == count)
     const_rtx = XEXP (x, 1);
@@ -9958,7 +9114,7 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
       && SUBREG_REG (XEXP (x, 0)) == varop)
     varop = XEXP (x, 0);
   else if (GET_MODE (varop) != shift_mode)
-    varop = gen_lowpart_for_combine (shift_mode, varop);
+    varop = gen_lowpart (shift_mode, varop);
 
   /* If we can't make the SUBREG, try to return what we were given.  */
   if (GET_CODE (varop) == CLOBBER)
@@ -9975,7 +9131,7 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
      for the outer operation.  So try to do the simplification
      recursively.  */
 
-  if (outer_op != NIL && GET_CODE (x) == code
+  if (outer_op != UNKNOWN && GET_CODE (x) == code
       && GET_CODE (XEXP (x, 1)) == CONST_INT)
     x = simplify_shift_const (x, code, shift_mode, XEXP (x, 0),
                              INTVAL (XEXP (x, 1)));
@@ -9987,14 +9143,14 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
                                GET_MODE_MASK (result_mode) >> orig_count);
 
   /* Do the remainder of the processing in RESULT_MODE.  */
-  x = gen_lowpart_for_combine (result_mode, x);
+  x = gen_lowpart (result_mode, x);
 
   /* If COMPLEMENT_P is set, we have to complement X before doing the outer
      operation.  */
   if (complement_p)
     x = simplify_gen_unary (NOT, result_mode, x, result_mode);
 
-  if (outer_op != NIL)
+  if (outer_op != UNKNOWN)
     {
       if (GET_MODE_BITSIZE (result_mode) < HOST_BITS_PER_WIDE_INT)
        outer_const = trunc_int_for_mode (outer_const, result_mode);
@@ -10005,7 +9161,7 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
        /* This means that we have determined that the result is
           equivalent to a constant.  This should be rare.  */
        x = GEN_INT (outer_const);
-      else if (GET_RTX_CLASS (outer_op) == '1')
+      else if (GET_RTX_CLASS (outer_op) == RTX_UNARY)
        x = simplify_gen_unary (outer_op, result_mode, x, result_mode);
       else
        x = gen_binary (outer_op, result_mode, x, GEN_INT (outer_const));
@@ -10028,17 +9184,14 @@ simplify_shift_const (x, code, result_mode, varop, orig_count)
    or -1.  */
 
 static int
-recog_for_combine (pnewpat, insn, pnotes)
-     rtx *pnewpat;
-     rtx insn;
-     rtx *pnotes;
+recog_for_combine (rtx *pnewpat, rtx insn, rtx *pnotes)
 {
   rtx pat = *pnewpat;
   int insn_code_number;
   int num_clobbers_to_add = 0;
   int i;
   rtx notes = 0;
-  rtx dummy_insn;
+  rtx old_notes, old_pat;
 
   /* If PAT is a PARALLEL, check to see if it contains the CLOBBER
      we use to indicate that something didn't match.  If we find such a
@@ -10049,13 +9202,12 @@ recog_for_combine (pnewpat, insn, pnotes)
          && XEXP (XVECEXP (pat, 0, i), 0) == const0_rtx)
        return -1;
 
-  /* *pnewpat does not have to be actual PATTERN (insn), so make a dummy
-     instruction for pattern recognition.  */
-  dummy_insn = shallow_copy_rtx (insn);
-  PATTERN (dummy_insn) = pat;
-  REG_NOTES (dummy_insn) = 0;
+  old_pat = PATTERN (insn);
+  old_notes = REG_NOTES (insn);
+  PATTERN (insn) = pat;
+  REG_NOTES (insn) = 0;
 
-  insn_code_number = recog (pat, dummy_insn, &num_clobbers_to_add);
+  insn_code_number = recog (pat, insn, &num_clobbers_to_add);
 
   /* If it isn't, there is the possibility that we previously had an insn
      that clobbered some register as a side effect, but the combined
@@ -10080,9 +9232,11 @@ recog_for_combine (pnewpat, insn, pnotes)
       if (pos == 1)
        pat = XVECEXP (pat, 0, 0);
 
-      PATTERN (dummy_insn) = pat;
-      insn_code_number = recog (pat, dummy_insn, &num_clobbers_to_add);
+      PATTERN (insn) = pat;
+      insn_code_number = recog (pat, insn, &num_clobbers_to_add);
     }
+  PATTERN (insn) = old_pat;
+  REG_NOTES (insn) = old_notes;
 
   /* Recognize all noop sets, these will be killed by followup pass.  */
   if (insn_code_number < 0 && GET_CODE (pat) == SET && set_noop_p (pat))
@@ -10109,7 +9263,7 @@ recog_for_combine (pnewpat, insn, pnotes)
       for (i = XVECLEN (newpat, 0) - num_clobbers_to_add;
           i < XVECLEN (newpat, 0); i++)
        {
-         if (GET_CODE (XEXP (XVECEXP (newpat, 0, i), 0)) == REG
+         if (REG_P (XEXP (XVECEXP (newpat, 0, i), 0))
              && ! reg_dead_at_p (XEXP (XVECEXP (newpat, 0, i), 0), insn))
            return -1;
          notes = gen_rtx_EXPR_LIST (REG_UNUSED,
@@ -10124,21 +9278,18 @@ recog_for_combine (pnewpat, insn, pnotes)
   return insn_code_number;
 }
 \f
-/* Like gen_lowpart but for use by combine.  In combine it is not possible
-   to create any new pseudoregs.  However, it is safe to create
-   invalid memory addresses, because combine will try to recognize
-   them and all they will do is make the combine attempt fail.
+/* Like gen_lowpart_general but for use by combine.  In combine it
+   is not possible to create any new pseudoregs.  However, it is
+   safe to create invalid memory addresses, because combine will
+   try to recognize them and all they will do is make the combine
+   attempt fail.
 
    If for some reason this cannot do its job, an rtx
    (clobber (const_int 0)) is returned.
    An insn containing that will not be recognized.  */
 
-#undef gen_lowpart
-
 static rtx
-gen_lowpart_for_combine (mode, x)
-     enum machine_mode mode;
-     rtx x;
+gen_lowpart_for_combine (enum machine_mode mode, rtx x)
 {
   rtx result;
 
@@ -10166,7 +9317,7 @@ gen_lowpart_for_combine (mode, x)
   /* 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.  */
-  if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
+  if (GET_CODE (x) == SUBREG && MEM_P (SUBREG_REG (x)))
     {
       x = SUBREG_REG (x);
       if (GET_MODE (x) == mode)
@@ -10177,7 +9328,7 @@ gen_lowpart_for_combine (mode, x)
 #ifdef CANNOT_CHANGE_MODE_CLASS
   if (result != 0
       && GET_CODE (result) == SUBREG
-      && GET_CODE (SUBREG_REG (result)) == REG
+      && REG_P (SUBREG_REG (result))
       && REGNO (SUBREG_REG (result)) >= FIRST_PSEUDO_REGISTER)
     bitmap_set_bit (&subregs_of_mode, REGNO (SUBREG_REG (result))
                                      * MAX_MACHINE_MODE
@@ -10187,7 +9338,7 @@ gen_lowpart_for_combine (mode, x)
   if (result)
     return result;
 
-  if (GET_CODE (x) == MEM)
+  if (MEM_P (x))
     {
       int offset = 0;
 
@@ -10197,7 +9348,7 @@ gen_lowpart_for_combine (mode, x)
        return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
 
       /* If we want to refer to something bigger than the original memref,
-        generate a perverse subreg instead.  That will force a reload
+        generate a paradoxical subreg instead.  That will force a reload
         of the original memref X.  */
       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
        return gen_rtx_SUBREG (mode, x, 0);
@@ -10219,7 +9370,7 @@ gen_lowpart_for_combine (mode, x)
 
   /* If X is a comparison operator, rewrite it in a new mode.  This
      probably won't match, but may allow further simplifications.  */
-  else if (GET_RTX_CLASS (GET_CODE (x)) == '<')
+  else if (COMPARISON_P (x))
     return gen_rtx_fmt_ee (GET_CODE (x), mode, XEXP (x, 0), XEXP (x, 1));
 
   /* If we couldn't simplify X any other way, just enclose it in a
@@ -10250,19 +9401,22 @@ gen_lowpart_for_combine (mode, x)
    fold; if not, a new expression is allocated.  */
 
 static rtx
-gen_binary (code, mode, op0, op1)
-     enum rtx_code code;
-     enum machine_mode mode;
-     rtx op0, op1;
+gen_binary (enum rtx_code code, enum machine_mode mode, rtx op0, rtx op1)
 {
   rtx result;
   rtx tem;
 
-  if (GET_RTX_CLASS (code) == 'c'
+  if (GET_CODE (op0) == CLOBBER)
+    return op0;
+  else if (GET_CODE (op1) == CLOBBER)
+    return op1;
+  
+  if (GET_RTX_CLASS (code) == RTX_COMM_ARITH
       && swap_commutative_operands_p (op0, op1))
     tem = op0, op0 = op1, op1 = tem;
 
-  if (GET_RTX_CLASS (code) == '<')
+  if (GET_RTX_CLASS (code) == RTX_COMPARE
+      || GET_RTX_CLASS (code) == RTX_COMM_COMPARE)
     {
       enum machine_mode op_mode = GET_MODE (op0);
 
@@ -10277,7 +9431,7 @@ gen_binary (code, mode, op0, op1)
 
       if (op_mode == VOIDmode)
        op_mode = GET_MODE (op1);
-      result = simplify_relational_operation (code, op_mode, op0, op1);
+      result = simplify_relational_operation (code, mode, op_mode, op0, op1);
     }
   else
     result = simplify_binary_operation (code, mode, op0, op1);
@@ -10286,7 +9440,7 @@ gen_binary (code, mode, op0, op1)
     return result;
 
   /* Put complex operands first and constants second.  */
-  if (GET_RTX_CLASS (code) == 'c'
+  if (GET_RTX_CLASS (code) == RTX_COMM_ARITH
       && swap_commutative_operands_p (op0, op1))
     return gen_rtx_fmt_ee (code, mode, op1, op0);
 
@@ -10312,10 +9466,7 @@ gen_binary (code, mode, op0, op1)
    should have been detected earlier.  Hence we ignore all such cases.  */
 
 static enum rtx_code
-simplify_comparison (code, pop0, pop1)
-     enum rtx_code code;
-     rtx *pop0;
-     rtx *pop1;
+simplify_comparison (enum rtx_code code, rtx *pop0, rtx *pop1)
 {
   rtx op0 = *pop0;
   rtx op1 = *pop1;
@@ -10338,12 +9489,9 @@ simplify_comparison (code, pop0, pop1)
          && (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0)))
              == GET_MODE (SUBREG_REG (XEXP (XEXP (op1, 0), 0))))
          && GET_CODE (XEXP (op0, 1)) == CONST_INT
-         && GET_CODE (XEXP (op1, 1)) == CONST_INT
-         && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
-         && GET_CODE (XEXP (XEXP (op1, 0), 1)) == CONST_INT
-         && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (op1, 1))
-         && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (XEXP (op0, 0), 1))
-         && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (XEXP (op1, 0), 1))
+         && XEXP (op0, 1) == XEXP (op1, 1)
+         && XEXP (op0, 1) == XEXP (XEXP (op0, 0), 1)
+         && XEXP (op0, 1) == XEXP (XEXP (op1, 0), 1)
          && (INTVAL (XEXP (op0, 1))
              == (GET_MODE_BITSIZE (GET_MODE (op0))
                  - (GET_MODE_BITSIZE
@@ -10438,8 +9586,8 @@ simplify_comparison (code, pop0, pop1)
                 tmode != GET_MODE (op0); tmode = GET_MODE_WIDER_MODE (tmode))
              if ((unsigned HOST_WIDE_INT) c0 == GET_MODE_MASK (tmode))
                {
-                 op0 = gen_lowpart_for_combine (tmode, inner_op0);
-                 op1 = gen_lowpart_for_combine (tmode, inner_op1);
+                 op0 = gen_lowpart (tmode, inner_op0);
+                 op1 = gen_lowpart (tmode, inner_op1);
                  code = unsigned_condition (code);
                  changed = 1;
                  break;
@@ -10492,8 +9640,7 @@ simplify_comparison (code, pop0, pop1)
 
       if (GET_MODE_CLASS (mode) != MODE_INT
          && ! (mode == VOIDmode
-               && (GET_CODE (op0) == COMPARE
-                   || GET_RTX_CLASS (GET_CODE (op0)) == '<')))
+               && (GET_CODE (op0) == COMPARE || COMPARISON_P (op0))))
        break;
 
       /* Get the constant we are comparing against and turn off all bits
@@ -10632,7 +9779,7 @@ simplify_comparison (code, pop0, pop1)
          break;
 
        case GEU:
-         /* >= C is equivalent to < (C - 1).  */
+         /* >= C is equivalent to > (C - 1).  */
          if (const_op > 1)
            {
              const_op -= 1;
@@ -10697,8 +9844,10 @@ simplify_comparison (code, pop0, pop1)
             a constant that has only a single bit set and are comparing it
             with zero, we can convert this into an equality comparison
             between the position and the location of the single bit.  */
-
-         if (GET_CODE (XEXP (op0, 0)) == CONST_INT
+         /* Except we can't if SHIFT_COUNT_TRUNCATED is set, since we might
+            have already reduced the shift count modulo the word size.  */
+         if (!SHIFT_COUNT_TRUNCATED
+             && GET_CODE (XEXP (op0, 0)) == CONST_INT
              && XEXP (op0, 1) == const1_rtx
              && equality_comparison_p && const_op == 0
              && (i = exact_log2 (INTVAL (XEXP (op0, 0)))) >= 0)
@@ -11066,9 +10215,9 @@ simplify_comparison (code, pop0, pop1)
              mask = ((INTVAL (XEXP (op0, 1)) & GET_MODE_MASK (mode))
                      << INTVAL (XEXP (XEXP (op0, 0), 1)));
              if ((~STORE_FLAG_VALUE & mask) == 0
-                 && (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (op0, 0), 0))) == '<'
+                 && (COMPARISON_P (XEXP (XEXP (op0, 0), 0))
                      || ((tem = get_last_value (XEXP (XEXP (op0, 0), 0))) != 0
-                         && GET_RTX_CLASS (GET_CODE (tem)) == '<')))
+                         && COMPARISON_P (tem))))
                {
                  op0 = XEXP (XEXP (op0, 0), 0);
                  continue;
@@ -11102,7 +10251,7 @@ simplify_comparison (code, pop0, pop1)
              && const_op >> i == 0
              && (tmode = mode_for_size (i, MODE_INT, 1)) != BLKmode)
            {
-             op0 = gen_lowpart_for_combine (tmode, XEXP (op0, 0));
+             op0 = gen_lowpart (tmode, XEXP (op0, 0));
              continue;
            }
 
@@ -11142,26 +10291,48 @@ simplify_comparison (code, pop0, pop1)
                  op0 = gen_binary (AND, tmode,
                                    SUBREG_REG (XEXP (op0, 0)),
                                    gen_int_mode (c1, tmode));
-                 op0 = gen_lowpart_for_combine (mode, op0);
+                 op0 = gen_lowpart (mode, op0);
                  continue;
                }
            }
 
-         /* Convert (ne (and (lshiftrt (not X)) 1) 0) to
-            (eq (and (lshiftrt X) 1) 0).  */
+         /* Convert (ne (and (not X) 1) 0) to (eq (and X 1) 0).  */
          if (const_op == 0 && equality_comparison_p
              && XEXP (op0, 1) == const1_rtx
-             && GET_CODE (XEXP (op0, 0)) == LSHIFTRT
-             && GET_CODE (XEXP (XEXP (op0, 0), 0)) == NOT)
+             && GET_CODE (XEXP (op0, 0)) == NOT)
            {
              op0 = simplify_and_const_int
-               (op0, mode,
-                gen_rtx_LSHIFTRT (mode, XEXP (XEXP (XEXP (op0, 0), 0), 0),
-                                  XEXP (XEXP (op0, 0), 1)),
-                (HOST_WIDE_INT) 1);
+               (NULL_RTX, mode, XEXP (XEXP (op0, 0), 0), (HOST_WIDE_INT) 1);
              code = (code == NE ? EQ : NE);
              continue;
            }
+
+         /* Convert (ne (and (lshiftrt (not X)) 1) 0) to
+            (eq (and (lshiftrt X) 1) 0).
+            Also handle the case where (not X) is expressed using xor.  */
+         if (const_op == 0 && equality_comparison_p
+             && XEXP (op0, 1) == const1_rtx
+             && GET_CODE (XEXP (op0, 0)) == LSHIFTRT)
+           {
+             rtx shift_op = XEXP (XEXP (op0, 0), 0);
+             rtx shift_count = XEXP (XEXP (op0, 0), 1);
+
+             if (GET_CODE (shift_op) == NOT
+                 || (GET_CODE (shift_op) == XOR
+                     && GET_CODE (XEXP (shift_op, 1)) == CONST_INT
+                     && GET_CODE (shift_count) == CONST_INT
+                     && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
+                     && (INTVAL (XEXP (shift_op, 1))
+                         == (HOST_WIDE_INT) 1 << INTVAL (shift_count))))
+               {
+                 op0 = simplify_and_const_int
+                   (NULL_RTX, mode,
+                    gen_rtx_LSHIFTRT (mode, XEXP (shift_op, 0), shift_count),
+                    (HOST_WIDE_INT) 1);
+                 code = (code == NE ? EQ : NE);
+                 continue;
+               }
+           }
          break;
 
        case ASHIFT:
@@ -11242,7 +10413,7 @@ simplify_comparison (code, pop0, pop1)
                   + (GET_MODE_MASK (tmode) >> 1) + 1)
                  <= GET_MODE_MASK (tmode)))
            {
-             op0 = gen_lowpart_for_combine (tmode, XEXP (XEXP (op0, 0), 0));
+             op0 = gen_lowpart (tmode, XEXP (XEXP (op0, 0), 0));
              continue;
            }
 
@@ -11267,7 +10438,7 @@ simplify_comparison (code, pop0, pop1)
                                          XEXP (op0, 1));
 
              op0 = gen_binary (PLUS, tmode,
-                               gen_lowpart_for_combine (tmode, inner),
+                               gen_lowpart (tmode, inner),
                                new_const);
              continue;
            }
@@ -11339,7 +10510,7 @@ simplify_comparison (code, pop0, pop1)
      those bits.
 
      3. SUBREG_REG (op0) is a memory and LOAD_EXTEND_OP is defined and not
-     NIL.  In that case we know those bits are zeros or ones.  We must
+     UNKNOWN.  In that case we know those bits are zeros or ones.  We must
      also be sure that they are the same as the upper bits of op1.
 
      We can never remove a SUBREG for a non-equality comparison because
@@ -11349,9 +10520,6 @@ simplify_comparison (code, pop0, pop1)
   op1 = make_compound_operation (op1, SET);
 
   if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0)
-      /* Case 3 above, to sometimes allow (subreg (mem x)), isn't
-        implemented.  */
-      && GET_CODE (SUBREG_REG (op0)) == REG
       && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op0))) == MODE_INT
       && (code == NE || code == EQ))
@@ -11359,8 +10527,13 @@ simplify_comparison (code, pop0, pop1)
       if (GET_MODE_SIZE (GET_MODE (op0))
          > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0))))
        {
-         op0 = SUBREG_REG (op0);
-         op1 = gen_lowpart_for_combine (GET_MODE (op0), op1);
+         /* For paradoxical subregs, allow case 1 as above.  Case 3 isn't
+            implemented.  */
+          if (REG_P (SUBREG_REG (op0)))
+           {
+             op0 = SUBREG_REG (op0);
+             op1 = gen_lowpart (GET_MODE (op0), op1);
+           }
        }
       else if ((GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
                <= HOST_BITS_PER_WIDE_INT)
@@ -11368,7 +10541,7 @@ simplify_comparison (code, pop0, pop1)
                                 GET_MODE (SUBREG_REG (op0)))
                   & ~GET_MODE_MASK (GET_MODE (op0))) == 0)
        {
-         tem = gen_lowpart_for_combine (GET_MODE (SUBREG_REG (op0)), op1);
+         tem = gen_lowpart (GET_MODE (SUBREG_REG (op0)), op1);
 
          if ((nonzero_bits (tem, GET_MODE (SUBREG_REG (op0)))
               & ~GET_MODE_MASK (GET_MODE (op0))) == 0)
@@ -11420,15 +10593,15 @@ simplify_comparison (code, pop0, pop1)
              if (GET_CODE (op0) == AND
                  && !have_insn_for (AND, mode))
                op0 = gen_binary (AND, tmode,
-                                 gen_lowpart_for_combine (tmode,
-                                                          XEXP (op0, 0)),
-                                 gen_lowpart_for_combine (tmode,
-                                                          XEXP (op0, 1)));
+                                 gen_lowpart (tmode,
+                                              XEXP (op0, 0)),
+                                 gen_lowpart (tmode,
+                                              XEXP (op0, 1)));
 
-             op0 = gen_lowpart_for_combine (tmode, op0);
+             op0 = gen_lowpart (tmode, op0);
              if (zero_extended && GET_CODE (op1) == CONST_INT)
                op1 = GEN_INT (INTVAL (op1) & GET_MODE_MASK (mode));
-             op1 = gen_lowpart_for_combine (tmode, op1);
+             op1 = gen_lowpart (tmode, op1);
              break;
            }
 
@@ -11439,7 +10612,7 @@ simplify_comparison (code, pop0, pop1)
              && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
            {
              op0 = gen_binary (AND, tmode,
-                               gen_lowpart_for_combine (tmode, op0),
+                               gen_lowpart (tmode, op0),
                                GEN_INT ((HOST_WIDE_INT) 1
                                         << (GET_MODE_BITSIZE (mode) - 1)));
              code = (code == LT) ? NE : EQ;
@@ -11462,8 +10635,7 @@ simplify_comparison (code, pop0, pop1)
 /* Like jump.c' reversed_comparison_code, but use combine infrastructure for
    searching backward.  */
 static enum rtx_code
-combine_reversed_comparison_code (exp)
-     rtx exp;
+combine_reversed_comparison_code (rtx exp)
 {
   enum rtx_code code1 = reversed_comparison_code (exp, NULL);
   rtx x;
@@ -11483,9 +10655,7 @@ combine_reversed_comparison_code (exp)
 /* Return comparison with reversed code of EXP and operands OP0 and OP1.
    Return NULL_RTX in case we fail to do the reversal.  */
 static rtx
-reversed_comparison (exp, mode, op0, op1)
-     rtx exp, op0, op1;
-     enum machine_mode mode;
+reversed_comparison (rtx exp, enum machine_mode mode, rtx op0, rtx op1)
 {
   enum rtx_code reversed_code = combine_reversed_comparison_code (exp);
   if (reversed_code == UNKNOWN)
@@ -11495,12 +10665,11 @@ reversed_comparison (exp, mode, op0, op1)
 }
 \f
 /* Utility function for following routine.  Called when X is part of a value
-   being stored into reg_last_set_value.  Sets reg_last_set_table_tick
+   being stored into last_set_value.  Sets last_set_table_tick
    for each register mentioned.  Similar to mention_regs in cse.c  */
 
 static void
-update_table_tick (x)
-     rtx x;
+update_table_tick (rtx x)
 {
   enum rtx_code code = GET_CODE (x);
   const char *fmt = GET_RTX_FORMAT (code);
@@ -11511,11 +10680,11 @@ update_table_tick (x)
       unsigned int regno = REGNO (x);
       unsigned int endregno
        = regno + (regno < FIRST_PSEUDO_REGISTER
-                  ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
+                  ? hard_regno_nregs[regno][GET_MODE (x)] : 1);
       unsigned int r;
 
       for (r = regno; r < endregno; r++)
-       reg_last_set_table_tick[r] = label_tick;
+       reg_stat[r].last_set_table_tick = label_tick;
 
       return;
     }
@@ -11528,9 +10697,7 @@ update_table_tick (x)
        /* Check for identical subexpressions.  If x contains
           identical subexpression we only have to traverse one of
           them.  */
-       if (i == 0
-           && (GET_RTX_CLASS (code) == '2'
-               || GET_RTX_CLASS (code) == 'c'))
+       if (i == 0 && ARITHMETIC_P (x))
          {
            /* Note that at this point x1 has already been
               processed.  */
@@ -11545,15 +10712,13 @@ update_table_tick (x)
            /* If x0 is identical to a subexpression of x1 then while
               processing x1, x0 has already been processed.  Thus we
               are done with x.  */
-           if ((GET_RTX_CLASS (GET_CODE (x1)) == '2'
-                || GET_RTX_CLASS (GET_CODE (x1)) == 'c')
+           if (ARITHMETIC_P (x1)
                && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
              break;
 
            /* If x1 is identical to a subexpression of x0 then we
               still have to process the rest of x0.  */
-           if ((GET_RTX_CLASS (GET_CODE (x0)) == '2'
-                || GET_RTX_CLASS (GET_CODE (x0)) == 'c')
+           if (ARITHMETIC_P (x0)
                && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
              {
                update_table_tick (XEXP (x0, x1 == XEXP (x0, 0) ? 1 : 0));
@@ -11567,19 +10732,17 @@ update_table_tick (x)
 
 /* Record that REG is set to VALUE in insn INSN.  If VALUE is zero, we
    are saying that the register is clobbered and we no longer know its
-   value.  If INSN is zero, don't update reg_last_set; this is only permitted
-   with VALUE also zero and is used to invalidate the register.  */
+   value.  If INSN is zero, don't update reg_stat[].last_set; this is
+   only permitted with VALUE also zero and is used to invalidate the
+   register.  */
 
 static void
-record_value_for_reg (reg, insn, value)
-     rtx reg;
-     rtx insn;
-     rtx value;
+record_value_for_reg (rtx reg, rtx insn, rtx value)
 {
   unsigned int regno = REGNO (reg);
   unsigned int endregno
     = regno + (regno < FIRST_PSEUDO_REGISTER
-              ? HARD_REGNO_NREGS (regno, GET_MODE (reg)) : 1);
+              ? hard_regno_nregs[regno][GET_MODE (reg)] : 1);
   unsigned int i;
 
   /* If VALUE contains REG and we have a previous value for REG, substitute
@@ -11599,8 +10762,7 @@ record_value_for_reg (reg, insn, value)
 
       if (tem)
        {
-         if ((GET_RTX_CLASS (GET_CODE (tem)) == '2'
-              || GET_RTX_CLASS (GET_CODE (tem)) == 'c')
+         if (ARITHMETIC_P (tem)
              && GET_CODE (XEXP (tem, 0)) == CLOBBER
              && GET_CODE (XEXP (tem, 1)) == CLOBBER)
            tem = XEXP (tem, 0);
@@ -11616,13 +10778,13 @@ record_value_for_reg (reg, insn, value)
   for (i = regno; i < endregno; i++)
     {
       if (insn)
-       reg_last_set[i] = insn;
+       reg_stat[i].last_set = insn;
 
-      reg_last_set_value[i] = 0;
-      reg_last_set_mode[i] = 0;
-      reg_last_set_nonzero_bits[i] = 0;
-      reg_last_set_sign_bit_copies[i] = 0;
-      reg_last_death[i] = 0;
+      reg_stat[i].last_set_value = 0;
+      reg_stat[i].last_set_mode = 0;
+      reg_stat[i].last_set_nonzero_bits = 0;
+      reg_stat[i].last_set_sign_bit_copies = 0;
+      reg_stat[i].last_death = 0;
     }
 
   /* Mark registers that are being referenced in this value.  */
@@ -11638,40 +10800,40 @@ record_value_for_reg (reg, insn, value)
 
   for (i = regno; i < endregno; i++)
     {
-      reg_last_set_label[i] = label_tick;
-      if (value && reg_last_set_table_tick[i] == label_tick)
-       reg_last_set_invalid[i] = 1;
+      reg_stat[i].last_set_label = label_tick;
+      if (value && reg_stat[i].last_set_table_tick == label_tick)
+       reg_stat[i].last_set_invalid = 1;
       else
-       reg_last_set_invalid[i] = 0;
+       reg_stat[i].last_set_invalid = 0;
     }
 
   /* The value being assigned might refer to X (like in "x++;").  In that
      case, we must replace it with (clobber (const_int 0)) to prevent
      infinite loops.  */
   if (value && ! get_last_value_validate (&value, insn,
-                                         reg_last_set_label[regno], 0))
+                                         reg_stat[regno].last_set_label, 0))
     {
       value = copy_rtx (value);
       if (! get_last_value_validate (&value, insn,
-                                    reg_last_set_label[regno], 1))
+                                    reg_stat[regno].last_set_label, 1))
        value = 0;
     }
 
   /* For the main register being modified, update the value, the mode, the
      nonzero bits, and the number of sign bit copies.  */
 
-  reg_last_set_value[regno] = value;
+  reg_stat[regno].last_set_value = value;
 
   if (value)
     {
       enum machine_mode mode = GET_MODE (reg);
       subst_low_cuid = INSN_CUID (insn);
-      reg_last_set_mode[regno] = mode;
+      reg_stat[regno].last_set_mode = mode;
       if (GET_MODE_CLASS (mode) == MODE_INT
          && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
        mode = nonzero_bits_mode;
-      reg_last_set_nonzero_bits[regno] = nonzero_bits (value, mode);
-      reg_last_set_sign_bit_copies[regno]
+      reg_stat[regno].last_set_nonzero_bits = nonzero_bits (value, mode);
+      reg_stat[regno].last_set_sign_bit_copies
        = num_sign_bit_copies (value, GET_MODE (reg));
     }
 }
@@ -11681,16 +10843,14 @@ record_value_for_reg (reg, insn, value)
    set is occurring.  */
 
 static void
-record_dead_and_set_regs_1 (dest, setter, data)
-     rtx dest, setter;
-     void *data;
+record_dead_and_set_regs_1 (rtx dest, rtx setter, void *data)
 {
   rtx record_dead_insn = (rtx) data;
 
   if (GET_CODE (dest) == SUBREG)
     dest = SUBREG_REG (dest);
 
-  if (GET_CODE (dest) == REG)
+  if (REG_P (dest))
     {
       /* If we are setting the whole register, we know its value.  Otherwise
         show that we don't know the value.  We can handle SUBREG in
@@ -11703,12 +10863,12 @@ record_dead_and_set_regs_1 (dest, setter, data)
               && GET_MODE_BITSIZE (GET_MODE (dest)) <= BITS_PER_WORD
               && subreg_lowpart_p (SET_DEST (setter)))
        record_value_for_reg (dest, record_dead_insn,
-                             gen_lowpart_for_combine (GET_MODE (dest),
+                             gen_lowpart (GET_MODE (dest),
                                                       SET_SRC (setter)));
       else
        record_value_for_reg (dest, record_dead_insn, NULL_RTX);
     }
-  else if (GET_CODE (dest) == MEM
+  else if (MEM_P (dest)
           /* Ignore pushes, they clobber nothing.  */
           && ! push_operand (dest, GET_MODE (dest)))
     mem_last_set = INSN_CUID (record_dead_insn);
@@ -11718,15 +10878,14 @@ record_dead_and_set_regs_1 (dest, setter, data)
    for the things done by INSN.  This is the last thing done in processing
    INSN in the combiner loop.
 
-   We update reg_last_set, reg_last_set_value, reg_last_set_mode,
-   reg_last_set_nonzero_bits, reg_last_set_sign_bit_copies, reg_last_death,
-   and also the similar information mem_last_set (which insn most recently
-   modified memory) and last_call_cuid (which insn was the most recent
-   subroutine call).  */
+   We update reg_stat[], in particular fields last_set, last_set_value,
+   last_set_mode, last_set_nonzero_bits, last_set_sign_bit_copies,
+   last_death, and also the similar information mem_last_set (which insn
+   most recently modified memory) and last_call_cuid (which insn was the
+   most recent subroutine call).  */
 
 static void
-record_dead_and_set_regs (insn)
-     rtx insn;
+record_dead_and_set_regs (rtx insn)
 {
   rtx link;
   unsigned int i;
@@ -11734,31 +10893,31 @@ record_dead_and_set_regs (insn)
   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
     {
       if (REG_NOTE_KIND (link) == REG_DEAD
-         && GET_CODE (XEXP (link, 0)) == REG)
+         && REG_P (XEXP (link, 0)))
        {
          unsigned int regno = REGNO (XEXP (link, 0));
          unsigned int endregno
            = regno + (regno < FIRST_PSEUDO_REGISTER
-                      ? HARD_REGNO_NREGS (regno, GET_MODE (XEXP (link, 0)))
+                      ? hard_regno_nregs[regno][GET_MODE (XEXP (link, 0))]
                       : 1);
 
          for (i = regno; i < endregno; i++)
-           reg_last_death[i] = insn;
+           reg_stat[i].last_death = insn;
        }
       else if (REG_NOTE_KIND (link) == REG_INC)
        record_value_for_reg (XEXP (link, 0), insn, NULL_RTX);
     }
 
-  if (GET_CODE (insn) == CALL_INSN)
+  if (CALL_P (insn))
     {
       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
        if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
          {
-           reg_last_set_value[i] = 0;
-           reg_last_set_mode[i] = 0;
-           reg_last_set_nonzero_bits[i] = 0;
-           reg_last_set_sign_bit_copies[i] = 0;
-           reg_last_death[i] = 0;
+           reg_stat[i].last_set_value = 0;
+           reg_stat[i].last_set_mode = 0;
+           reg_stat[i].last_set_nonzero_bits = 0;
+           reg_stat[i].last_set_sign_bit_copies = 0;
+           reg_stat[i].last_death = 0;
          }
 
       last_call_cuid = mem_last_set = INSN_CUID (insn);
@@ -11784,9 +10943,7 @@ record_dead_and_set_regs (insn)
    missed because of that.  */
 
 static void
-record_promoted_value (insn, subreg)
-     rtx insn;
-     rtx subreg;
+record_promoted_value (rtx insn, rtx subreg)
 {
   rtx links, set;
   unsigned int regno = REGNO (SUBREG_REG (subreg));
@@ -11800,7 +10957,7 @@ record_promoted_value (insn, subreg)
       insn = XEXP (links, 0);
       set = single_set (insn);
 
-      if (! set || GET_CODE (SET_DEST (set)) != REG
+      if (! set || !REG_P (SET_DEST (set))
          || REGNO (SET_DEST (set)) != regno
          || GET_MODE (SET_DEST (set)) != GET_MODE (SUBREG_REG (subreg)))
        {
@@ -11808,13 +10965,13 @@ record_promoted_value (insn, subreg)
          continue;
        }
 
-      if (reg_last_set[regno] == insn)
+      if (reg_stat[regno].last_set == insn)
        {
          if (SUBREG_PROMOTED_UNSIGNED_P (subreg) > 0)
-           reg_last_set_nonzero_bits[regno] &= GET_MODE_MASK (mode);
+           reg_stat[regno].last_set_nonzero_bits &= GET_MODE_MASK (mode);
        }
 
-      if (GET_CODE (SET_SRC (set)) == REG)
+      if (REG_P (SET_SRC (set)))
        {
          regno = REGNO (SET_SRC (set));
          links = LOG_LINKS (insn);
@@ -11828,12 +10985,10 @@ record_promoted_value (insn, subreg)
    note what it implies to the registers used in it.  */
 
 static void
-check_promoted_subreg (insn, x)
-     rtx insn;
-     rtx x;
+check_promoted_subreg (rtx insn, rtx x)
 {
   if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
-      && GET_CODE (SUBREG_REG (x)) == REG)
+      && REG_P (SUBREG_REG (x)))
     record_promoted_value (insn, x);
   else
     {
@@ -11867,34 +11022,30 @@ check_promoted_subreg (insn, x)
    we don't know exactly what registers it was produced from.  */
 
 static int
-get_last_value_validate (loc, insn, tick, replace)
-     rtx *loc;
-     rtx insn;
-     int tick;
-     int replace;
+get_last_value_validate (rtx *loc, rtx insn, int tick, int replace)
 {
   rtx x = *loc;
   const char *fmt = GET_RTX_FORMAT (GET_CODE (x));
   int len = GET_RTX_LENGTH (GET_CODE (x));
   int i;
 
-  if (GET_CODE (x) == REG)
+  if (REG_P (x))
     {
       unsigned int regno = REGNO (x);
       unsigned int endregno
        = regno + (regno < FIRST_PSEUDO_REGISTER
-                  ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
+                  ? hard_regno_nregs[regno][GET_MODE (x)] : 1);
       unsigned int j;
 
       for (j = regno; j < endregno; j++)
-       if (reg_last_set_invalid[j]
+       if (reg_stat[j].last_set_invalid
            /* If this is a pseudo-register that was only set once and not
               live at the beginning of the function, it is always valid.  */
            || (! (regno >= FIRST_PSEUDO_REGISTER
                   && REG_N_SETS (regno) == 1
                   && (! REGNO_REG_SET_P
                       (ENTRY_BLOCK_PTR->next_bb->global_live_at_start, regno)))
-               && reg_last_set_label[j] > tick))
+               && reg_stat[j].last_set_label > tick))
          {
            if (replace)
              *loc = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
@@ -11906,7 +11057,7 @@ get_last_value_validate (loc, insn, tick, replace)
   /* If this is a memory reference, make sure that there were
      no stores after it that might have clobbered the value.  We don't
      have alias info, so we assume any store invalidates it.  */
-  else if (GET_CODE (x) == MEM && ! RTX_UNCHANGING_P (x)
+  else if (MEM_P (x) && !MEM_READONLY_P (x)
           && INSN_CUID (insn) <= mem_last_set)
     {
       if (replace)
@@ -11921,9 +11072,7 @@ get_last_value_validate (loc, insn, tick, replace)
          /* Check for identical subexpressions.  If x contains
             identical subexpression we only have to traverse one of
             them.  */
-         if (i == 1
-             && (GET_RTX_CLASS (GET_CODE (x)) == '2'
-                 || GET_RTX_CLASS (GET_CODE (x)) == 'c'))
+         if (i == 1 && ARITHMETIC_P (x))
            {
              /* Note that at this point x0 has already been checked
                 and found valid.  */
@@ -11937,15 +11086,13 @@ get_last_value_validate (loc, insn, tick, replace)
              /* If x1 is identical to a subexpression of x0 then
                 while checking x0, x1 has already been checked.  Thus
                 it is valid and so as x.  */
-             if ((GET_RTX_CLASS (GET_CODE (x0)) == '2'
-                  || GET_RTX_CLASS (GET_CODE (x0)) == 'c')
+             if (ARITHMETIC_P (x0)
                  && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
                return 1;
 
              /* If x0 is identical to a subexpression of x1 then x is
                 valid iff the rest of x1 is valid.  */
-             if ((GET_RTX_CLASS (GET_CODE (x1)) == '2'
-                  || GET_RTX_CLASS (GET_CODE (x1)) == 'c')
+             if (ARITHMETIC_P (x1)
                  && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
                return
                  get_last_value_validate (&XEXP (x1,
@@ -11971,8 +11118,7 @@ get_last_value_validate (loc, insn, tick, replace)
    is known longer known reliably.  */
 
 static rtx
-get_last_value (x)
-     rtx x;
+get_last_value (rtx x)
 {
   unsigned int regno;
   rtx value;
@@ -11985,13 +11131,13 @@ get_last_value (x)
       && (GET_MODE_SIZE (GET_MODE (x))
          <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
       && (value = get_last_value (SUBREG_REG (x))) != 0)
-    return gen_lowpart_for_combine (GET_MODE (x), value);
+    return gen_lowpart (GET_MODE (x), value);
 
-  if (GET_CODE (x) != REG)
+  if (!REG_P (x))
     return 0;
 
   regno = REGNO (x);
-  value = reg_last_set_value[regno];
+  value = reg_stat[regno].last_set_value;
 
   /* If we don't have a value, or if it isn't for this basic block and
      it's either a hard register, set more than once, or it's a live
@@ -12004,7 +11150,7 @@ get_last_value (x)
      block.  */
 
   if (value == 0
-      || (reg_last_set_label[regno] != label_tick
+      || (reg_stat[regno].last_set_label != label_tick
          && (regno < FIRST_PSEUDO_REGISTER
              || REG_N_SETS (regno) != 1
              || (REGNO_REG_SET_P
@@ -12013,20 +11159,20 @@ get_last_value (x)
 
   /* If the value was set in a later insn than the ones we are processing,
      we can't use it even if the register was only set once.  */
-  if (INSN_CUID (reg_last_set[regno]) >= subst_low_cuid)
+  if (INSN_CUID (reg_stat[regno].last_set) >= subst_low_cuid)
     return 0;
 
   /* If the value has all its registers valid, return it.  */
-  if (get_last_value_validate (&value, reg_last_set[regno],
-                              reg_last_set_label[regno], 0))
+  if (get_last_value_validate (&value, reg_stat[regno].last_set,
+                              reg_stat[regno].last_set_label, 0))
     return value;
 
   /* Otherwise, make a copy and replace any invalid register with
      (clobber (const_int 0)).  If that fails for some reason, return 0.  */
 
   value = copy_rtx (value);
-  if (get_last_value_validate (&value, reg_last_set[regno],
-                              reg_last_set_label[regno], 1))
+  if (get_last_value_validate (&value, reg_stat[regno].last_set,
+                              reg_stat[regno].last_set_label, 1))
     return value;
 
   return 0;
@@ -12036,9 +11182,7 @@ get_last_value (x)
    that is set in an instruction more recent than FROM_CUID.  */
 
 static int
-use_crosses_set_p (x, from_cuid)
-     rtx x;
-     int from_cuid;
+use_crosses_set_p (rtx x, int from_cuid)
 {
   const char *fmt;
   int i;
@@ -12048,7 +11192,7 @@ use_crosses_set_p (x, from_cuid)
     {
       unsigned int regno = REGNO (x);
       unsigned endreg = regno + (regno < FIRST_PSEUDO_REGISTER
-                                ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
+                                ? hard_regno_nregs[regno][GET_MODE (x)] : 1);
 
 #ifdef PUSH_ROUNDING
       /* Don't allow uses of the stack pointer to be moved,
@@ -12057,8 +11201,8 @@ use_crosses_set_p (x, from_cuid)
        return 1;
 #endif
       for (; regno < endreg; regno++)
-       if (reg_last_set[regno]
-           && INSN_CUID (reg_last_set[regno]) > from_cuid)
+       if (reg_stat[regno].last_set
+           && INSN_CUID (reg_stat[regno].last_set) > from_cuid)
          return 1;
       return 0;
     }
@@ -12096,19 +11240,16 @@ static int reg_dead_flag;
    reg_dead_flag to 1 if X is a CLOBBER and to -1 it is a SET.  */
 
 static void
-reg_dead_at_p_1 (dest, x, data)
-     rtx dest;
-     rtx x;
-     void *data ATTRIBUTE_UNUSED;
+reg_dead_at_p_1 (rtx dest, rtx x, void *data ATTRIBUTE_UNUSED)
 {
   unsigned int regno, endregno;
 
-  if (GET_CODE (dest) != REG)
+  if (!REG_P (dest))
     return;
 
   regno = REGNO (dest);
   endregno = regno + (regno < FIRST_PSEUDO_REGISTER
-                     ? HARD_REGNO_NREGS (regno, GET_MODE (dest)) : 1);
+                     ? hard_regno_nregs[regno][GET_MODE (dest)] : 1);
 
   if (reg_dead_endregno > regno && reg_dead_regno < endregno)
     reg_dead_flag = (GET_CODE (x) == CLOBBER) ? 1 : -1;
@@ -12123,9 +11264,7 @@ reg_dead_at_p_1 (dest, x, data)
    must be assumed to be always live.  */
 
 static int
-reg_dead_at_p (reg, insn)
-     rtx reg;
-     rtx insn;
+reg_dead_at_p (rtx reg, rtx insn)
 {
   basic_block block;
   unsigned int i;
@@ -12133,23 +11272,25 @@ reg_dead_at_p (reg, insn)
   /* Set variables for reg_dead_at_p_1.  */
   reg_dead_regno = REGNO (reg);
   reg_dead_endregno = reg_dead_regno + (reg_dead_regno < FIRST_PSEUDO_REGISTER
-                                       ? HARD_REGNO_NREGS (reg_dead_regno,
-                                                           GET_MODE (reg))
+                                       ? hard_regno_nregs[reg_dead_regno]
+                                                         [GET_MODE (reg)]
                                        : 1);
 
   reg_dead_flag = 0;
 
-  /* Check that reg isn't mentioned in NEWPAT_USED_REGS.  */
+  /* Check that reg isn't mentioned in NEWPAT_USED_REGS.  For fixed registers
+     we allow the machine description to decide whether use-and-clobber
+     patterns are OK.  */
   if (reg_dead_regno < FIRST_PSEUDO_REGISTER)
     {
       for (i = reg_dead_regno; i < reg_dead_endregno; i++)
-       if (TEST_HARD_REG_BIT (newpat_used_regs, i))
+       if (!fixed_regs[i] && TEST_HARD_REG_BIT (newpat_used_regs, i))
          return 0;
     }
 
   /* Scan backwards until we find a REG_DEAD note, SET, CLOBBER, label, or
      beginning of function.  */
-  for (; insn && GET_CODE (insn) != CODE_LABEL && GET_CODE (insn) != BARRIER;
+  for (; insn && !LABEL_P (insn) && !BARRIER_P (insn);
        insn = prev_nonnote_insn (insn))
     {
       note_stores (PATTERN (insn), reg_dead_at_p_1, NULL);
@@ -12166,7 +11307,7 @@ reg_dead_at_p (reg, insn)
   else
     {
       FOR_EACH_BB (block)
-       if (insn == block->head)
+       if (insn == BB_HEAD (block))
          break;
 
       if (block == EXIT_BLOCK_PTR)
@@ -12184,8 +11325,7 @@ reg_dead_at_p (reg, insn)
    that in flow.c, but much simpler since we don't care about pseudos.  */
 
 static void
-mark_used_regs_combine (x)
-     rtx x;
+mark_used_regs_combine (rtx x)
 {
   RTX_CODE code = GET_CODE (x);
   unsigned int regno;
@@ -12213,7 +11353,7 @@ mark_used_regs_combine (x)
     case CLOBBER:
       /* If we are clobbering a MEM, mark any hard registers inside the
         address as used.  */
-      if (GET_CODE (XEXP (x, 0)) == MEM)
+      if (MEM_P (XEXP (x, 0)))
        mark_used_regs_combine (XEXP (XEXP (x, 0), 0));
       return;
 
@@ -12236,7 +11376,7 @@ mark_used_regs_combine (x)
              || regno == FRAME_POINTER_REGNUM)
            return;
 
-         endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
+         endregno = regno + hard_regno_nregs[regno][GET_MODE (x)];
          for (r = regno; r < endregno; r++)
            SET_HARD_REG_BIT (newpat_used_regs, r);
        }
@@ -12254,7 +11394,7 @@ mark_used_regs_combine (x)
               || GET_CODE (testreg) == STRICT_LOW_PART)
          testreg = XEXP (testreg, 0);
 
-       if (GET_CODE (testreg) == MEM)
+       if (MEM_P (testreg))
          mark_used_regs_combine (XEXP (testreg, 0));
 
        mark_used_regs_combine (SET_SRC (x));
@@ -12290,9 +11430,7 @@ mark_used_regs_combine (x)
    Return the note used to record the death, if there was one.  */
 
 rtx
-remove_death (regno, insn)
-     unsigned int regno;
-     rtx insn;
+remove_death (unsigned int regno, rtx insn)
 {
   rtx note = find_regno_note (insn, REG_DEAD, regno);
 
@@ -12316,12 +11454,8 @@ remove_death (regno, insn)
    notes will then be distributed as needed.  */
 
 static void
-move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
-     rtx x;
-     rtx maybe_kill_insn;
-     int from_cuid;
-     rtx to_insn;
-     rtx *pnotes;
+move_deaths (rtx x, rtx maybe_kill_insn, int from_cuid, rtx to_insn,
+            rtx *pnotes)
 {
   const char *fmt;
   int len, i;
@@ -12330,7 +11464,7 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
   if (code == REG)
     {
       unsigned int regno = REGNO (x);
-      rtx where_dead = reg_last_death[regno];
+      rtx where_dead = reg_stat[regno].last_death;
       rtx before_dead, after_dead;
 
       /* Don't move the register if it gets killed in between from and to.  */
@@ -12357,7 +11491,7 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
          rtx note = remove_death (regno, where_dead);
 
          /* It is possible for the call above to return 0.  This can occur
-            when reg_last_death points to I2 or I1 that we combined with.
+            when last_death points to I2 or I1 that we combined with.
             In that case make a new note.
 
             We must also check for the case where X is a hard register
@@ -12371,10 +11505,10 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
            {
              unsigned int deadregno = REGNO (XEXP (note, 0));
              unsigned int deadend
-               = (deadregno + HARD_REGNO_NREGS (deadregno,
-                                                GET_MODE (XEXP (note, 0))));
+               = (deadregno + hard_regno_nregs[deadregno]
+                                              [GET_MODE (XEXP (note, 0))]);
              unsigned int ourend
-               = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
+               = regno + hard_regno_nregs[regno][GET_MODE (x)];
              unsigned int i;
 
              for (i = deadregno; i < deadend; i++)
@@ -12395,15 +11529,15 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
                        && (GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
                            < GET_MODE_SIZE (GET_MODE (x)))))
                   && regno < FIRST_PSEUDO_REGISTER
-                  && HARD_REGNO_NREGS (regno, GET_MODE (x)) > 1)
+                  && hard_regno_nregs[regno][GET_MODE (x)] > 1)
            {
              unsigned int ourend
-               = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
+               = regno + hard_regno_nregs[regno][GET_MODE (x)];
              unsigned int i, offset;
              rtx oldnotes = 0;
 
              if (note)
-               offset = HARD_REGNO_NREGS (regno, GET_MODE (XEXP (note, 0)));
+               offset = hard_regno_nregs[regno][GET_MODE (XEXP (note, 0))];
              else
                offset = 1;
 
@@ -12459,7 +11593,7 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
         For a REG (the only other possibility), the entire value is
         being replaced so the old value is not used in this insn.  */
 
-      if (GET_CODE (dest) == MEM)
+      if (MEM_P (dest))
        move_deaths (XEXP (dest, 0), maybe_kill_insn, from_cuid,
                     to_insn, pnotes);
       return;
@@ -12489,9 +11623,7 @@ move_deaths (x, maybe_kill_insn, from_cuid, to_insn, pnotes)
    pattern of an insn.  X must be a REG.  */
 
 static int
-reg_bitfield_target_p (x, body)
-     rtx x;
-     rtx body;
+reg_bitfield_target_p (rtx x, rtx body)
 {
   int i;
 
@@ -12511,15 +11643,15 @@ reg_bitfield_target_p (x, body)
       if (GET_CODE (target) == SUBREG)
        target = SUBREG_REG (target);
 
-      if (GET_CODE (target) != REG)
+      if (!REG_P (target))
        return 0;
 
       tregno = REGNO (target), regno = REGNO (x);
       if (tregno >= FIRST_PSEUDO_REGISTER || regno >= FIRST_PSEUDO_REGISTER)
        return target == x;
 
-      endtregno = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (target));
-      endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
+      endtregno = tregno + hard_regno_nregs[tregno][GET_MODE (target)];
+      endregno = regno + hard_regno_nregs[regno][GET_MODE (x)];
 
       return endregno > tregno && regno < endtregno;
     }
@@ -12540,10 +11672,7 @@ reg_bitfield_target_p (x, body)
    on the type of note.  */
 
 static void
-distribute_notes (notes, from_insn, i3, i2)
-     rtx notes;
-     rtx from_insn;
-     rtx i3, i2;
+distribute_notes (rtx notes, rtx from_insn, rtx i3, rtx i2)
 {
   rtx note, next_note;
   rtx tem;
@@ -12554,7 +11683,7 @@ distribute_notes (notes, from_insn, i3, i2)
 
       /* If this NOTE references a pseudo register, ensure it references
         the latest copy of that register.  */
-      if (XEXP (note, 0) && GET_CODE (XEXP (note, 0)) == REG
+      if (XEXP (note, 0) && REG_P (XEXP (note, 0))
          && REGNO (XEXP (note, 0)) >= FIRST_PSEUDO_REGISTER)
        XEXP (note, 0) = regno_reg_rtx[REGNO (XEXP (note, 0))];
 
@@ -12569,16 +11698,14 @@ distribute_notes (notes, from_insn, i3, i2)
          place = i3;
          break;
 
-       case REG_VTABLE_REF:
-         /* ??? Should remain with *a particular* memory load.  Given the
-            nature of vtable data, the last insn seems relatively safe.  */
-         place = i3;
+       case REG_VALUE_PROFILE:
+         /* Just get rid of this note, as it is unused later anyway.  */
          break;
 
        case REG_NON_LOCAL_GOTO:
-         if (GET_CODE (i3) == JUMP_INSN)
+         if (JUMP_P (i3))
            place = i3;
-         else if (i2 && GET_CODE (i2) == JUMP_INSN)
+         else if (i2 && JUMP_P (i2))
            place = i2;
          else
            abort ();
@@ -12586,9 +11713,9 @@ distribute_notes (notes, from_insn, i3, i2)
 
        case REG_EH_REGION:
          /* These notes must remain with the call or trapping instruction.  */
-         if (GET_CODE (i3) == CALL_INSN)
+         if (CALL_P (i3))
            place = i3;
-         else if (i2 && GET_CODE (i2) == CALL_INSN)
+         else if (i2 && CALL_P (i2))
            place = i2;
          else if (flag_non_call_exceptions)
            {
@@ -12604,13 +11731,14 @@ distribute_notes (notes, from_insn, i3, i2)
            abort ();
          break;
 
+       case REG_ALWAYS_RETURN:
        case REG_NORETURN:
        case REG_SETJMP:
          /* These notes must remain with the call.  It should not be
             possible for both I2 and I3 to be a call.  */
-         if (GET_CODE (i3) == CALL_INSN)
+         if (CALL_P (i3))
            place = i3;
-         else if (i2 && GET_CODE (i2) == CALL_INSN)
+         else if (i2 && CALL_P (i2))
            place = i2;
          else
            abort ();
@@ -12639,7 +11767,7 @@ distribute_notes (notes, from_insn, i3, i2)
              if (from_insn != i3)
                break;
 
-             if (! (GET_CODE (XEXP (note, 0)) == REG
+             if (! (REG_P (XEXP (note, 0))
                     ? find_regno_note (i3, REG_UNUSED, REGNO (XEXP (note, 0)))
                     : find_reg_note (i3, REG_UNUSED, XEXP (note, 0))))
                place = i3;
@@ -12648,7 +11776,7 @@ distribute_notes (notes, from_insn, i3, i2)
             now dies here, so we must put a REG_DEAD note here unless there
             is one already.  */
          else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3))
-                  && ! (GET_CODE (XEXP (note, 0)) == REG
+                  && ! (REG_P (XEXP (note, 0))
                         ? find_regno_note (i3, REG_DEAD,
                                            REGNO (XEXP (note, 0)))
                         : find_reg_note (i3, REG_DEAD, XEXP (note, 0))))
@@ -12716,29 +11844,32 @@ distribute_notes (notes, from_insn, i3, i2)
                place = i2;
            }
 
-         /* Don't attach REG_LABEL note to a JUMP_INSN which has
-            JUMP_LABEL already.  Instead, decrement LABEL_NUSES.  */
-         if (place && GET_CODE (place) == JUMP_INSN && JUMP_LABEL (place))
+         /* Don't attach REG_LABEL note to a JUMP_INSN.  Add
+            a JUMP_LABEL instead or decrement LABEL_NUSES.  */
+         if (place && JUMP_P (place))
            {
-             if (JUMP_LABEL (place) != XEXP (note, 0))
+             if (!JUMP_LABEL (place))
+               JUMP_LABEL (place) = XEXP (note, 0);
+             else if (JUMP_LABEL (place) != XEXP (note, 0))
                abort ();
-             if (GET_CODE (JUMP_LABEL (place)) == CODE_LABEL)
+             else if (LABEL_P (JUMP_LABEL (place)))
                LABEL_NUSES (JUMP_LABEL (place))--;
              place = 0;
            }
-         if (place2 && GET_CODE (place2) == JUMP_INSN && JUMP_LABEL (place2))
+         if (place2 && JUMP_P (place2))
            {
-             if (JUMP_LABEL (place2) != XEXP (note, 0))
+             if (!JUMP_LABEL (place2))
+               JUMP_LABEL (place2) = XEXP (note, 0);
+             else if (JUMP_LABEL (place2) != XEXP (note, 0))
                abort ();
-             if (GET_CODE (JUMP_LABEL (place2)) == CODE_LABEL)
+             else if (LABEL_P (JUMP_LABEL (place2)))
                LABEL_NUSES (JUMP_LABEL (place2))--;
              place2 = 0;
            }
          break;
 
        case REG_NONNEG:
-       case REG_WAS_0:
-         /* These notes say something about the value of a register prior
+         /* This note says something about the value of a register prior
             to the execution of an insn.  It is too much trouble to see
             if the note is still correct in all situations.  It is better
             to simply delete it.  */
@@ -12748,7 +11879,7 @@ distribute_notes (notes, from_insn, i3, i2)
          /* If the insn previously containing this note still exists,
             put it back where it was.  Otherwise move it to the previous
             insn.  Adjust the corresponding REG_LIBCALL note.  */
-         if (GET_CODE (from_insn) != NOTE)
+         if (!NOTE_P (from_insn))
            place = from_insn;
          else
            {
@@ -12760,12 +11891,15 @@ distribute_notes (notes, from_insn, i3, i2)
                 libcall sequence, don't add the notes.  */
              else if (XEXP (note, 0) == from_insn)
                tem = place = 0;
+             /* Don't add the dangling REG_RETVAL note.  */
+             else if (! tem)
+               place = 0;
            }
          break;
 
        case REG_LIBCALL:
          /* This is handled similarly to REG_RETVAL.  */
-         if (GET_CODE (from_insn) != NOTE)
+         if (!NOTE_P (from_insn))
            place = from_insn;
          else
            {
@@ -12777,6 +11911,9 @@ distribute_notes (notes, from_insn, i3, i2)
                 libcall sequence, don't add the notes.  */
              else if (XEXP (note, 0) == from_insn)
                tem = place = 0;
+             /* Don't add the dangling REG_LIBCALL note.  */
+             else if (! tem)
+               place = 0;
            }
          break;
 
@@ -12796,7 +11933,7 @@ distribute_notes (notes, from_insn, i3, i2)
             use of A and put the death note there.  */
 
          if (from_insn
-             && GET_CODE (from_insn) == CALL_INSN
+             && CALL_P (from_insn)
              && find_reg_fusage (from_insn, USE, XEXP (note, 0)))
            place = from_insn;
          else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3)))
@@ -12813,15 +11950,18 @@ distribute_notes (notes, from_insn, i3, i2)
                {
                  if (! INSN_P (tem))
                    {
-                     if (tem == bb->head)
+                     if (tem == BB_HEAD (bb))
                        break;
                      continue;
                    }
 
                  /* If the register is being set at TEM, see if that is all
                     TEM is doing.  If so, delete TEM.  Otherwise, make this
-                    into a REG_UNUSED note instead.  */
-                 if (reg_set_p (XEXP (note, 0), PATTERN (tem)))
+                    into a REG_UNUSED note instead. Don't delete sets to
+                    global register vars.  */
+                 if ((REGNO (XEXP (note, 0)) >= FIRST_PSEUDO_REGISTER
+                      || !global_regs[REGNO (XEXP (note, 0))])
+                     && reg_set_p (XEXP (note, 0), PATTERN (tem)))
                    {
                      rtx set = single_set (tem);
                      rtx inner_dest = 0;
@@ -12858,55 +11998,42 @@ distribute_notes (notes, from_insn, i3, i2)
                             This might delete other dead insns recursively.
                             First set the pattern to something that won't use
                             any register.  */
+                         rtx old_notes = REG_NOTES (tem);
 
                          PATTERN (tem) = pc_rtx;
+                         REG_NOTES (tem) = NULL;
 
-                         distribute_notes (REG_NOTES (tem), tem, tem,
-                                           NULL_RTX);
+                         distribute_notes (old_notes, tem, tem, NULL_RTX);
                          distribute_links (LOG_LINKS (tem));
 
-                         PUT_CODE (tem, NOTE);
-                         NOTE_LINE_NUMBER (tem) = NOTE_INSN_DELETED;
-                         NOTE_SOURCE_FILE (tem) = 0;
+                         SET_INSN_DELETED (tem);
 
 #ifdef HAVE_cc0
                          /* Delete the setter too.  */
                          if (cc0_setter)
                            {
                              PATTERN (cc0_setter) = pc_rtx;
+                             old_notes = REG_NOTES (cc0_setter);
+                             REG_NOTES (cc0_setter) = NULL;
 
-                             distribute_notes (REG_NOTES (cc0_setter),
-                                               cc0_setter, cc0_setter,
-                                               NULL_RTX);
+                             distribute_notes (old_notes, cc0_setter,
+                                               cc0_setter, NULL_RTX);
                              distribute_links (LOG_LINKS (cc0_setter));
 
-                             PUT_CODE (cc0_setter, NOTE);
-                             NOTE_LINE_NUMBER (cc0_setter)
-                               = NOTE_INSN_DELETED;
-                             NOTE_SOURCE_FILE (cc0_setter) = 0;
+                             SET_INSN_DELETED (cc0_setter);
                            }
 #endif
                        }
-                     /* If the register is both set and used here, put the
-                        REG_DEAD note here, but place a REG_UNUSED note
-                        here too unless there already is one.  */
-                     else if (reg_referenced_p (XEXP (note, 0),
-                                                PATTERN (tem)))
-                       {
-                         place = tem;
-
-                         if (! find_regno_note (tem, REG_UNUSED,
-                                                REGNO (XEXP (note, 0))))
-                           REG_NOTES (tem)
-                             = gen_rtx_EXPR_LIST (REG_UNUSED, XEXP (note, 0),
-                                                  REG_NOTES (tem));
-                       }
                      else
                        {
                          PUT_REG_NOTE_KIND (note, REG_UNUSED);
 
                          /*  If there isn't already a REG_UNUSED note, put one
-                             here.  */
+                             here.  Do not place a REG_DEAD note, even if
+                             the register is also used here; that would not
+                             match the algorithm used in lifetime analysis
+                             and can cause the consistency check in the
+                             scheduler to fail.  */
                          if (! find_regno_note (tem, REG_UNUSED,
                                                 REGNO (XEXP (note, 0))))
                            place = tem;
@@ -12914,7 +12041,7 @@ distribute_notes (notes, from_insn, i3, i2)
                        }
                    }
                  else if (reg_referenced_p (XEXP (note, 0), PATTERN (tem))
-                          || (GET_CODE (tem) == CALL_INSN
+                          || (CALL_P (tem)
                               && find_reg_fusage (tem, USE, XEXP (note, 0))))
                    {
                      place = tem;
@@ -12938,7 +12065,7 @@ distribute_notes (notes, from_insn, i3, i2)
                      break;
                    }
 
-                 if (tem == bb->head)
+                 if (tem == BB_HEAD (bb))
                    break;
                }
 
@@ -12955,7 +12082,7 @@ distribute_notes (notes, from_insn, i3, i2)
 
          /* If the register is set or already dead at PLACE, we needn't do
             anything with this note if it is still a REG_DEAD note.
-            We can here if it is set at all, not if is it totally replace,
+            We check here if it is set at all, not if is it totally replaced,
             which is what `dead_or_set_p' checks, so also check for it being
             set partially.  */
 
@@ -12973,14 +12100,14 @@ distribute_notes (notes, from_insn, i3, i2)
                  || reg_bitfield_target_p (XEXP (note, 0), PATTERN (place)))
                {
                  /* Unless the register previously died in PLACE, clear
-                    reg_last_death.  [I no longer understand why this is
+                    last_death.  [I no longer understand why this is
                     being done.] */
-                 if (reg_last_death[regno] != place)
-                   reg_last_death[regno] = 0;
+                 if (reg_stat[regno].last_death != place)
+                   reg_stat[regno].last_death = 0;
                  place = 0;
                }
              else
-               reg_last_death[regno] = place;
+               reg_stat[regno].last_death = place;
 
              /* If this is a death note for a hard reg that is occupying
                 multiple registers, ensure that we are still using all
@@ -12992,11 +12119,11 @@ distribute_notes (notes, from_insn, i3, i2)
                 the previous insn that used this register.  */
 
              if (place && regno < FIRST_PSEUDO_REGISTER
-                 && HARD_REGNO_NREGS (regno, GET_MODE (XEXP (note, 0))) > 1)
+                 && hard_regno_nregs[regno][GET_MODE (XEXP (note, 0))] > 1)
                {
                  unsigned int endregno
-                   = regno + HARD_REGNO_NREGS (regno,
-                                               GET_MODE (XEXP (note, 0)));
+                   = regno + hard_regno_nregs[regno]
+                                             [GET_MODE (XEXP (note, 0))];
                  int all_used = 1;
                  unsigned int i;
 
@@ -13012,7 +12139,7 @@ distribute_notes (notes, from_insn, i3, i2)
                         not already dead or set.  */
 
                      for (i = regno; i < endregno;
-                          i += HARD_REGNO_NREGS (i, reg_raw_mode[i]))
+                          i += hard_regno_nregs[i][reg_raw_mode[i]])
                        {
                          rtx piece = regno_reg_rtx[i];
                          basic_block bb = this_basic_block;
@@ -13035,7 +12162,7 @@ distribute_notes (notes, from_insn, i3, i2)
                              {
                                if (! INSN_P (tem))
                                  {
-                                   if (tem == bb->head)
+                                   if (tem == BB_HEAD (bb))
                                      {
                                        SET_BIT (refresh_blocks,
                                                 this_basic_block->index);
@@ -13075,14 +12202,14 @@ distribute_notes (notes, from_insn, i3, i2)
        }
       else if ((REG_NOTE_KIND (note) == REG_DEAD
                || REG_NOTE_KIND (note) == REG_UNUSED)
-              && GET_CODE (XEXP (note, 0)) == REG)
+              && REG_P (XEXP (note, 0)))
        REG_N_DEATHS (REGNO (XEXP (note, 0)))--;
 
       if (place2)
        {
          if ((REG_NOTE_KIND (note) == REG_DEAD
               || REG_NOTE_KIND (note) == REG_UNUSED)
-             && GET_CODE (XEXP (note, 0)) == REG)
+             && REG_P (XEXP (note, 0)))
            REG_N_DEATHS (REGNO (XEXP (note, 0)))++;
 
          REG_NOTES (place2) = gen_rtx_fmt_ee (GET_CODE (note),
@@ -13094,12 +12221,11 @@ distribute_notes (notes, from_insn, i3, i2)
 }
 \f
 /* Similarly to above, distribute the LOG_LINKS that used to be present on
-   I3, I2, and I1 to new locations.  This is also called in one case to
-   add a link pointing at I3 when I3's destination is changed.  */
+   I3, I2, and I1 to new locations.  This is also called to add a link
+   pointing at I3 when I3's destination is changed.  */
 
 static void
-distribute_links (links)
-     rtx links;
+distribute_links (rtx links)
 {
   rtx link, next_link;
 
@@ -13122,7 +12248,7 @@ distribute_links (links)
         replace I3, I2, and I1 by I3 and I2.  But in that case the
         destination of I2 also remains unchanged.  */
 
-      if (GET_CODE (XEXP (link, 0)) == NOTE
+      if (NOTE_P (XEXP (link, 0))
          || (set = single_set (XEXP (link, 0))) == 0)
        continue;
 
@@ -13143,7 +12269,7 @@ distribute_links (links)
 
       for (insn = NEXT_INSN (XEXP (link, 0));
           (insn && (this_basic_block->next_bb == EXIT_BLOCK_PTR
-                    || this_basic_block->next_bb->head != insn));
+                    || BB_HEAD (this_basic_block->next_bb) != insn));
           insn = NEXT_INSN (insn))
        if (INSN_P (insn) && reg_overlap_mentioned_p (reg, PATTERN (insn)))
          {
@@ -13151,12 +12277,14 @@ distribute_links (links)
              place = insn;
            break;
          }
-       else if (GET_CODE (insn) == CALL_INSN
+       else if (CALL_P (insn)
                 && find_reg_fusage (insn, USE, reg))
          {
            place = insn;
            break;
          }
+       else if (INSN_P (insn) && reg_set_p (reg, insn))
+         break;
 
       /* If we found a place to put the link, place it there unless there
         is already a link to the same insn as LINK at that point.  */
@@ -13184,14 +12312,40 @@ distribute_links (links)
     }
 }
 \f
+/* Subroutine of unmentioned_reg_p and callback from for_each_rtx.
+   Check whether the expression pointer to by LOC is a register or
+   memory, and if so return 1 if it isn't mentioned in the rtx EXPR.
+   Otherwise return zero.  */
+
+static int
+unmentioned_reg_p_1 (rtx *loc, void *expr)
+{
+  rtx x = *loc;
+
+  if (x != NULL_RTX
+      && (REG_P (x) || MEM_P (x))
+      && ! reg_mentioned_p (x, (rtx) expr))
+    return 1;
+  return 0;
+}
+
+/* Check for any register or memory mentioned in EQUIV that is not
+   mentioned in EXPR.  This is used to restrict EQUIV to "specializations"
+   of EXPR where some registers may have been replaced by constants.  */
+
+static bool
+unmentioned_reg_p (rtx equiv, rtx expr)
+{
+  return for_each_rtx (&equiv, unmentioned_reg_p_1, expr);
+}
+\f
 /* Compute INSN_CUID for INSN, which is an insn made by combine.  */
 
 static int
-insn_cuid (insn)
-     rtx insn;
+insn_cuid (rtx insn)
 {
   while (insn != 0 && INSN_UID (insn) > max_uid_cuid
-        && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == USE)
+        && NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == USE)
     insn = NEXT_INSN (insn);
 
   if (INSN_UID (insn) > max_uid_cuid)
@@ -13201,8 +12355,7 @@ insn_cuid (insn)
 }
 \f
 void
-dump_combine_stats (file)
-     FILE *file;
+dump_combine_stats (FILE *file)
 {
   fnotice
     (file,
@@ -13211,8 +12364,7 @@ dump_combine_stats (file)
 }
 
 void
-dump_combine_total_stats (file)
-     FILE *file;
+dump_combine_total_stats (FILE *file)
 {
   fnotice
     (file,