OSDN Git Service

* cse.c (cse_insn): Emit barrier after unconditional jump.
[pf3gnuchains/gcc-fork.git] / gcc / cse.c
index 4e52bb4..3e872e2 100644 (file)
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -1,5 +1,6 @@
 /* Common subexpression elimination for GNU compiler.
-   Copyright (C) 1987, 88, 89, 92-7, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998
+   1999, 2000 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -25,15 +26,18 @@ Boston, MA 02111-1307, USA.  */
 #include <setjmp.h>
 
 #include "rtl.h"
+#include "tm_p.h"
 #include "regs.h"
 #include "hard-reg-set.h"
 #include "flags.h"
 #include "real.h"
 #include "insn-config.h"
 #include "recog.h"
+#include "function.h"
 #include "expr.h"
 #include "toplev.h"
 #include "output.h"
+#include "ggc.h"
 
 /* The basic idea of common subexpression elimination is to go
    through the code, keeping a record of expressions that would
@@ -41,16 +45,18 @@ Boston, MA 02111-1307, USA.  */
    expressions encountered with the cheapest equivalent expression.
 
    It is too complicated to keep track of the different possibilities
-   when control paths merge; so, at each label, we forget all that is
-   known and start fresh.  This can be described as processing each
-   basic block separately.  Note, however, that these are not quite
-   the same as the basic blocks found by a later pass and used for
-   data flow analysis and register packing.  We do not need to start fresh
-   after a conditional jump instruction if there is no label there.
+   when control paths merge in this code; so, at each label, we forget all
+   that is known and start fresh.  This can be described as processing each
+   extended basic block separately.  We have a separate pass to perform
+   global CSE.
+
+   Note CSE can turn a conditional or computed jump into a nop or
+   an unconditional jump.  When this occurs we arrange to run the jump
+   optimizer after CSE to delete the unreachable code.
 
    We use two data structures to record the equivalent expressions:
-   a hash table for most expressions, and several vectors together
-   with "quantity numbers" to record equivalent (pseudo) registers.
+   a hash table for most expressions, and a vector of "quantity
+   numbers" to record equivalent (pseudo) registers.
 
    The use of the special data structure for registers is desirable
    because it is faster.  It is possible because registers references
@@ -75,19 +81,19 @@ Registers and "quantity numbers":
    All real quantity numbers are greater than or equal to `max_reg'.
    If register N has not been assigned a quantity, reg_qty[N] will equal N.
 
-   Quantity numbers below `max_reg' do not exist and none of the `qty_...'
-   variables should be referenced with an index below `max_reg'.
+   Quantity numbers below `max_reg' do not exist and none of the `qty_table'
+   entries should be referenced with an index below `max_reg'.
 
    We also maintain a bidirectional chain of registers for each
-   quantity number.  `qty_first_reg', `qty_last_reg',
-   `reg_next_eqv' and `reg_prev_eqv' hold these chains.
+   quantity number.  The `qty_table` members `first_reg' and `last_reg',
+   and `reg_eqv_table' members `next' and `prev' hold these chains.
 
    The first register in a chain is the one whose lifespan is least local.
    Among equals, it is the one that was seen first.
    We replace any equivalent register with that one.
 
    If two registers have the same quantity number, it must be true that
-   REG expressions with `qty_mode' must be in the hash table for both
+   REG expressions with qty_table `mode' must be in the hash table for both
    registers and must be in the same class.
 
    The converse is not true.  Since hard registers may be referenced in
@@ -98,7 +104,7 @@ Registers and "quantity numbers":
 Constants and quantity numbers
 
    When a quantity has a known constant value, that value is stored
-   in the appropriate element of qty_const.  This is in addition to
+   in the appropriate qty_table `const_rtx'.  This is in addition to
    putting the constant in the hash table as is usual for non-regs.
 
    Whether a reg or a constant is preferred is determined by the configuration
@@ -106,8 +112,8 @@ Constants and quantity numbers
    event, expressions containing constants can be simplified, by fold_rtx.
 
    When a quantity has a known nearly constant value (such as an address
-   of a stack slot), that value is stored in the appropriate element
-   of qty_const.
+   of a stack slot), that value is stored in the appropriate qty_table
+   `const_rtx'.
 
    Integer constants don't have a machine mode.  However, cse
    determines the intended machine mode from the destination
@@ -127,7 +133,7 @@ Other expressions:
    currently have equivalent values.
 
    Register references in an expression are canonicalized before hashing
-   the expression.  This is done using `reg_qty' and `qty_first_reg'.
+   the expression.  This is done using `reg_qty' and qty_table `first_reg'.
    The hash code of a register reference is computed using the quantity
    number, not the register number.
 
@@ -199,8 +205,8 @@ static int max_reg;
 
 static int max_insn_uid;
 
-/* Length of vectors indexed by quantity number.
-   We know in advance we will not need a quantity number this big.  */
+/* Length of qty_table vector.  We know in advance we will not need
+   a quantity number this big.  */
 
 static int max_qty;
 
@@ -209,48 +215,44 @@ static int max_qty;
 
 static int next_qty;
 
-/* Indexed by quantity number, gives the first (or last) register 
-   in the chain of registers that currently contain this quantity.  */
-
-static int *qty_first_reg;
-static int *qty_last_reg;
-
-/* Index by quantity number, gives the mode of the quantity.  */
-
-static enum machine_mode *qty_mode;
-
-/* Indexed by quantity number, gives the rtx of the constant value of the
-   quantity, or zero if it does not have a known value.
-   A sum of the frame pointer (or arg pointer) plus a constant
-   can also be entered here.  */
-
-static rtx *qty_const;
-
-/* Indexed by qty number, gives the insn that stored the constant value
-   recorded in `qty_const'.  */
-
-static rtx *qty_const_insn;
+/* Per-qty information tracking.
 
-/* The next three variables are used to track when a comparison between a
-   quantity and some constant or register has been passed.  In that case, we
-   know the results of the comparison in case we see it again.  These variables
-   record a comparison that is known to be true.  */
+   `first_reg' and `last_reg' track the head and tail of the
+   chain of registers which currently contain this quantity.
 
-/* Indexed by qty number, gives the rtx code of a comparison with a known
-   result involving this quantity.  If none, it is UNKNOWN.  */
-static enum rtx_code *qty_comparison_code;
+   `mode' contains the machine mode of this quantity.
 
-/* Indexed by qty number, gives the constant being compared against in a
-   comparison of known result.  If no such comparison, it is undefined.
-   If the comparison is not with a constant, it is zero.  */
+   `const_rtx' holds the rtx of the constant value of this
+   quantity, if known.  A summations of the frame/arg pointer
+   and a constant can also be entered here.  When this holds
+   a known value, `const_insn' is the insn which stored the
+   constant value.
 
-static rtx *qty_comparison_const;
+   `comparison_{code,const,qty}' are used to track when a
+   comparison between a quantity and some constant or register has
+   been passed.  In such a case, we know the results of the comparison
+   in case we see it again.  These members record a comparison that
+   is known to be true.  `comparison_code' holds the rtx code of such
+   a comparison, else it is set to UNKNOWN and the other two
+   comparison members are undefined.  `comparison_const' holds
+   the constant being compared against, or zero if the comparison
+   is not against a constant.  `comparison_qty' holds the quantity
+   being compared against when the result is known.  If the comparison
+   is not with a register, `comparison_qty' is -1.  */
 
-/* Indexed by qty number, gives the quantity being compared against in a
-   comparison of known result.  If no such comparison, if it undefined.
-   If the comparison is not with a register, it is -1.  */
+struct qty_table_elem
+{
+  rtx const_rtx;
+  rtx const_insn;
+  rtx comparison_const;
+  int comparison_qty;
+  unsigned int first_reg, last_reg;
+  enum machine_mode mode;
+  enum rtx_code comparison_code;
+};
 
-static int *qty_comparison_qty;
+/* The table of all qtys, indexed by qty number.  */
+static struct qty_table_elem *qty_table;
 
 #ifdef HAVE_cc0
 /* For machines that have a CC0, we do not record its value in the hash
@@ -274,35 +276,68 @@ static rtx prev_insn;
 
 static rtx this_insn;
 
-/* Index by register number, gives the quantity number
-   of the register's current contents.  */
-
-static int *reg_qty;
-
 /* Index by register number, gives the number of the next (or
    previous) register in the chain of registers sharing the same
    value.
 
    Or -1 if this register is at the end of the chain.
 
-   If reg_qty[N] == N, reg_next_eqv[N] is undefined.  */
+   If reg_qty[N] == N, reg_eqv_table[N].next is undefined.  */
+
+/* Per-register equivalence chain.  */
+struct reg_eqv_elem
+{
+  int next, prev;
+};
+
+/* The table of all register equivalence chains.  */
+static struct reg_eqv_elem *reg_eqv_table;
+
+struct cse_reg_info
+{
+  /* Next in hash chain.  */
+  struct cse_reg_info *hash_next;
+
+  /* The next cse_reg_info structure in the free or used list.  */
+  struct cse_reg_info *next;
+
+  /* Search key */
+  unsigned int regno;
+
+  /* The quantity number of the register's current contents.  */
+  int reg_qty;
+
+  /* The number of times the register has been altered in the current
+     basic block.  */
+  int reg_tick;
+
+  /* The REG_TICK value at which rtx's containing this register are
+     valid in the hash table.  If this does not equal the current
+     reg_tick value, such expressions existing in the hash table are
+     invalid.  */
+  int reg_in_table;
+};
 
-static int *reg_next_eqv;
-static int *reg_prev_eqv;
+/* A free list of cse_reg_info entries.  */
+static struct cse_reg_info *cse_reg_info_free_list;
 
-/* Index by register number, gives the number of times
-   that register has been altered in the current basic block.  */
+/* A used list of cse_reg_info entries.  */
+static struct cse_reg_info *cse_reg_info_used_list;
+static struct cse_reg_info *cse_reg_info_used_list_end;
 
-static int *reg_tick;
+/* A mapping from registers to cse_reg_info data structures.  */
+#define REGHASH_SHIFT  7
+#define REGHASH_SIZE   (1 << REGHASH_SHIFT)
+#define REGHASH_MASK   (REGHASH_SIZE - 1)
+static struct cse_reg_info *reg_hash[REGHASH_SIZE];
 
-/* Index by register number, gives the reg_tick value at which
-   rtx's containing this register are valid in the hash table.
-   If this does not equal the current reg_tick value, such expressions
-   existing in the hash table are invalid.
-   If this is -1, no expressions containing this register have been
-   entered in the table.  */
+#define REGHASH_FN(REGNO)      \
+       (((REGNO) ^ ((REGNO) >> REGHASH_SHIFT)) & REGHASH_MASK)
 
-static int *reg_in_table;
+/* The last lookup we did into the cse_reg_info_tree.  This allows us
+   to cache repeated lookups.  */
+static unsigned int cached_regno;
+static struct cse_reg_info *cached_cse_reg_info;
 
 /* A HARD_REG_SET containing all the hard registers for which there is 
    currently a REG expression in the hash table.  Note the difference
@@ -316,14 +351,6 @@ static HARD_REG_SET hard_regs_in_table;
 
 static HARD_REG_SET regs_invalidated_by_call;
 
-/* Two vectors of ints:
-   one containing max_reg -1's; the other max_reg + 500 (an approximation
-   for max_qty) elements where element i contains i.
-   These are used to initialize various other vectors fast.  */
-
-static int *all_minus_one;
-static int *consec_ints;
-
 /* CUID of insn that starts the basic block currently being cse-processed.  */
 
 static int cse_basic_block_start;
@@ -345,6 +372,11 @@ static int max_uid;
 
 #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
 
+/* Nonzero if this pass has made changes, and therefore it's
+   worthwhile to run the garbage collector.  */
+
+static int cse_altered;
+
 /* Nonzero if cse has altered conditional jump insns
    in such a way that jump optimization should be redone.  */
 
@@ -372,15 +404,13 @@ static rtx memory_extend_rtx;
 
 static int hash_arg_in_memory;
 
-/* canon_hash stores 1 in hash_arg_in_struct
-   if it notices a reference to memory that's part of a structure.  */
-
-static int hash_arg_in_struct;
-
 /* The hash table contains buckets which are chains of `struct table_elt's,
    each recording one expression's information.
    That expression is in the `exp' field.
 
+   The canon_exp field contains a canonical (from the point of view of
+   alias analysis) version of the `exp' field.
+
    Those elements with the same hash code are chained in both directions
    through the `next_same_hash' and `prev_same_hash' fields.
 
@@ -398,9 +428,6 @@ static int hash_arg_in_struct;
    the address is either a symbol constant or a constant plus
    the frame pointer or argument pointer.
 
-   The `in_struct' field is nonzero for elements that
-   involve any reference to memory inside a structure or array.
-
    The `related_value' field is used to connect related expressions
    (that differ by adding an integer).
    The related expressions are chained in a circular fashion.
@@ -423,6 +450,7 @@ static int hash_arg_in_struct;
 struct table_elt
 {
   rtx exp;
+  rtx canon_exp;
   struct table_elt *next_same_hash;
   struct table_elt *prev_same_hash;
   struct table_elt *next_same_value;
@@ -432,7 +460,6 @@ struct table_elt
   int cost;
   enum machine_mode mode;
   char in_memory;
-  char in_struct;
   char is_const;
   char flag;
 };
@@ -440,31 +467,25 @@ struct table_elt
 /* We don't want a lot of buckets, because we rarely have very many
    things stored in the hash table, and a lot of buckets slows
    down a lot of loops that happen frequently.  */
-#define NBUCKETS 31
+#define HASH_SHIFT     5
+#define HASH_SIZE      (1 << HASH_SHIFT)
+#define HASH_MASK      (HASH_SIZE - 1)
 
 /* Compute hash code of X in mode M.  Special-case case where X is a pseudo
    register (hard registers may require `do_not_record' to be set).  */
 
 #define HASH(X, M)     \
- (GET_CODE (X) == REG && REGNO (X) >= FIRST_PSEUDO_REGISTER    \
-  ? (((unsigned) REG << 7) + (unsigned) reg_qty[REGNO (X)]) % NBUCKETS \
-  : canon_hash (X, M) % NBUCKETS)
+ ((GET_CODE (X) == REG && REGNO (X) >= FIRST_PSEUDO_REGISTER   \
+  ? (((unsigned) REG << 7) + (unsigned) REG_QTY (REGNO (X)))   \
+  : canon_hash (X, M)) & HASH_MASK)
 
 /* Determine whether register number N is considered a fixed register for CSE.
    It is desirable to replace other regs with fixed regs, to reduce need for
    non-fixed hard regs.
-   A reg wins if it is either the frame pointer or designated as fixed,
-   but not if it is an overlapping register.  */
-#ifdef OVERLAPPING_REGNO_P
-#define FIXED_REGNO_P(N)  \
-  (((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM \
-    || fixed_regs[N] || global_regs[N])          \
-   && ! OVERLAPPING_REGNO_P ((N)))
-#else
+   A reg wins if it is either the frame pointer or designated as fixed.  */
 #define FIXED_REGNO_P(N)  \
   ((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM \
    || fixed_regs[N] || global_regs[N])
-#endif
 
 /* Compute cost of X, as stored in the `cost' field of a table_elt.  Fixed
    hard registers and pointers into the frame are the cheapest with a cost
@@ -492,10 +513,29 @@ struct table_elt
       : 2)                                                             \
    : notreg_cost(X))
 
+/* Get the info associated with register N.  */
+
+#define GET_CSE_REG_INFO(N)                    \
+  (((N) == cached_regno && cached_cse_reg_info)        \
+   ? cached_cse_reg_info : get_cse_reg_info ((N)))
+
+/* Get the number of times this register has been updated in this
+   basic block.  */
+
+#define REG_TICK(N) ((GET_CSE_REG_INFO (N))->reg_tick)
+
+/* Get the point at which REG was recorded in the table.  */
+
+#define REG_IN_TABLE(N) ((GET_CSE_REG_INFO (N))->reg_in_table)
+
+/* Get the quantity number for REG.  */
+
+#define REG_QTY(N) ((GET_CSE_REG_INFO (N))->reg_qty)
+
 /* Determine if the quantity number for register X represents a valid index
-   into the `qty_...' variables.  */
+   into the qty_table.  */
 
-#define REGNO_QTY_VALID_P(N) (reg_qty[N] != (N))
+#define REGNO_QTY_VALID_P(N) (REG_QTY (N) != (int) (N))
 
 #ifdef ADDRESS_COST
 /* The ADDRESS_COST macro does not deal with ADDRESSOF nodes.  But,
@@ -507,7 +547,7 @@ struct table_elt
    ? -1 : ADDRESS_COST(RTX))
 #endif 
 
-static struct table_elt *table[NBUCKETS];
+static struct table_elt *table[HASH_SIZE];
 
 /* Chain of `struct table_elt's made so far for this function
    but currently removed from the table.  */
@@ -542,7 +582,8 @@ static int constant_pool_entries_cost;
 
 /* This data describes a block that will be processed by cse_basic_block.  */
 
-struct cse_basic_block_data {
+struct cse_basic_block_data
+{
   /* Lowest CUID value of insns in block.  */
   int low_cuid;
   /* Highest CUID value of insns in block.  */
@@ -554,29 +595,36 @@ struct cse_basic_block_data {
   /* Size of current branch path, if any.  */
   int path_size;
   /* Current branch path, indicating which branches will be taken.  */
-  struct branch_path {
-    /* The branch insn.  */
-    rtx branch;
-    /* Whether it should be taken or not.  AROUND is the same as taken
-       except that it is used when the destination label is not preceded
+  struct branch_path
+    {
+      /* The branch insn.  */
+      rtx branch;
+      /* Whether it should be taken or not.  AROUND is the same as taken
+        except that it is used when the destination label is not preceded
        by a BARRIER.  */
-    enum taken {TAKEN, NOT_TAKEN, AROUND} status;
-  } path[PATHLENGTH];
+      enum taken {TAKEN, NOT_TAKEN, AROUND} status;
+    } path[PATHLENGTH];
 };
 
 /* Nonzero if X has the form (PLUS frame-pointer integer).  We check for
    virtual regs here because the simplify_*_operation routines are called
-   by integrate.c, which is called before virtual register instantiation.  */
+   by integrate.c, which is called before virtual register instantiation. 
+
+   ?!? FIXED_BASE_PLUS_P and NONZERO_BASE_PLUS_P need to move into
+   a header file so that their definitions can be shared with the
+   simplification routines in simplify-rtx.c.  Until then, do not
+   change these macros without also changing the copy in simplify-rtx.c.  */
 
 #define FIXED_BASE_PLUS_P(X)                                   \
   ((X) == frame_pointer_rtx || (X) == hard_frame_pointer_rtx   \
-   || (X) == arg_pointer_rtx                                   \
+   || ((X) == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])\
    || (X) == virtual_stack_vars_rtx                            \
    || (X) == virtual_incoming_args_rtx                         \
    || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
        && (XEXP (X, 0) == frame_pointer_rtx                    \
           || XEXP (X, 0) == hard_frame_pointer_rtx             \
-          || XEXP (X, 0) == arg_pointer_rtx                    \
+          || ((X) == arg_pointer_rtx                           \
+              && fixed_regs[ARG_POINTER_REGNUM])               \
           || XEXP (X, 0) == virtual_stack_vars_rtx             \
           || XEXP (X, 0) == virtual_incoming_args_rtx))        \
    || GET_CODE (X) == ADDRESSOF)
@@ -594,7 +642,8 @@ struct cse_basic_block_data {
    || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
        && (XEXP (X, 0) == frame_pointer_rtx                    \
           || XEXP (X, 0) == hard_frame_pointer_rtx             \
-          || XEXP (X, 0) == arg_pointer_rtx                    \
+          || ((X) == arg_pointer_rtx                           \
+              && fixed_regs[ARG_POINTER_REGNUM])               \
           || XEXP (X, 0) == virtual_stack_vars_rtx             \
           || XEXP (X, 0) == virtual_incoming_args_rtx))        \
    || (X) == stack_pointer_rtx                                 \
@@ -606,70 +655,78 @@ struct cse_basic_block_data {
           || XEXP (X, 0) == virtual_outgoing_args_rtx))        \
    || GET_CODE (X) == ADDRESSOF)
 
-static int notreg_cost         PROTO((rtx));
-static void new_basic_block    PROTO((void));
-static void make_new_qty       PROTO((int));
-static void make_regs_eqv      PROTO((int, int));
-static void delete_reg_equiv   PROTO((int));
-static int mention_regs                PROTO((rtx));
-static int insert_regs         PROTO((rtx, struct table_elt *, int));
-static void free_element       PROTO((struct table_elt *));
-static void remove_from_table  PROTO((struct table_elt *, unsigned));
-static struct table_elt *get_element PROTO((void));
-static struct table_elt *lookup        PROTO((rtx, unsigned, enum machine_mode)),
-       *lookup_for_remove PROTO((rtx, unsigned, enum machine_mode));
-static rtx lookup_as_function  PROTO((rtx, enum rtx_code));
-static struct table_elt *insert PROTO((rtx, struct table_elt *, unsigned,
-                                      enum machine_mode));
-static void merge_equiv_classes PROTO((struct table_elt *,
-                                      struct table_elt *));
-static void invalidate         PROTO((rtx, enum machine_mode));
-static int cse_rtx_varies_p    PROTO((rtx));
-static void remove_invalid_refs        PROTO((int));
-static void remove_invalid_subreg_refs PROTO((int, int, enum machine_mode));
-static void rehash_using_reg   PROTO((rtx));
-static void invalidate_memory  PROTO((void));
-static void invalidate_for_call        PROTO((void));
-static rtx use_related_value   PROTO((rtx, struct table_elt *));
-static unsigned canon_hash     PROTO((rtx, enum machine_mode));
-static unsigned safe_hash      PROTO((rtx, enum machine_mode));
-static int exp_equiv_p         PROTO((rtx, rtx, int, int));
-static void set_nonvarying_address_components PROTO((rtx, int, rtx *,
-                                                    HOST_WIDE_INT *,
-                                                    HOST_WIDE_INT *));
-static int refers_to_p         PROTO((rtx, rtx));
-static rtx canon_reg           PROTO((rtx, rtx));
-static void find_best_addr     PROTO((rtx, rtx *));
-static enum rtx_code find_comparison_args PROTO((enum rtx_code, rtx *, rtx *,
-                                                enum machine_mode *,
-                                                enum machine_mode *));
-static rtx cse_gen_binary      PROTO((enum rtx_code, enum machine_mode,
-                                      rtx, rtx));
-static rtx simplify_plus_minus PROTO((enum rtx_code, enum machine_mode,
-                                      rtx, rtx));
-static rtx fold_rtx            PROTO((rtx, rtx));
-static rtx equiv_constant      PROTO((rtx));
-static void record_jump_equiv  PROTO((rtx, int));
-static void record_jump_cond   PROTO((enum rtx_code, enum machine_mode,
-                                      rtx, rtx, int));
-static void cse_insn           PROTO((rtx, rtx));
-static int note_mem_written    PROTO((rtx));
-static void invalidate_from_clobbers PROTO((rtx));
-static rtx cse_process_notes   PROTO((rtx, rtx));
-static void cse_around_loop    PROTO((rtx));
-static void invalidate_skipped_set PROTO((rtx, rtx));
-static void invalidate_skipped_block PROTO((rtx));
-static void cse_check_loop_start PROTO((rtx, rtx));
-static void cse_set_around_loop        PROTO((rtx, rtx, rtx));
-static rtx cse_basic_block     PROTO((rtx, rtx, struct branch_path *, int));
-static void count_reg_usage    PROTO((rtx, int *, rtx, int));
-
-extern int rtx_equal_function_value_matters;
+static int notreg_cost         PARAMS ((rtx));
+static void new_basic_block    PARAMS ((void));
+static void make_new_qty       PARAMS ((unsigned int, enum machine_mode));
+static void make_regs_eqv      PARAMS ((unsigned int, unsigned int));
+static void delete_reg_equiv   PARAMS ((unsigned int));
+static int mention_regs                PARAMS ((rtx));
+static int insert_regs         PARAMS ((rtx, struct table_elt *, int));
+static void remove_from_table  PARAMS ((struct table_elt *, unsigned));
+static struct table_elt *lookup        PARAMS ((rtx, unsigned, enum machine_mode)),
+       *lookup_for_remove PARAMS ((rtx, unsigned, enum machine_mode));
+static rtx lookup_as_function  PARAMS ((rtx, enum rtx_code));
+static struct table_elt *insert PARAMS ((rtx, struct table_elt *, unsigned,
+                                        enum machine_mode));
+static void merge_equiv_classes PARAMS ((struct table_elt *,
+                                        struct table_elt *));
+static void invalidate         PARAMS ((rtx, enum machine_mode));
+static int cse_rtx_varies_p    PARAMS ((rtx));
+static void remove_invalid_refs        PARAMS ((unsigned int));
+static void remove_invalid_subreg_refs PARAMS ((unsigned int, unsigned int,
+                                                enum machine_mode));
+static void rehash_using_reg   PARAMS ((rtx));
+static void invalidate_memory  PARAMS ((void));
+static void invalidate_for_call        PARAMS ((void));
+static rtx use_related_value   PARAMS ((rtx, struct table_elt *));
+static unsigned canon_hash     PARAMS ((rtx, enum machine_mode));
+static unsigned safe_hash      PARAMS ((rtx, enum machine_mode));
+static int exp_equiv_p         PARAMS ((rtx, rtx, int, int));
+static rtx canon_reg           PARAMS ((rtx, rtx));
+static void find_best_addr     PARAMS ((rtx, rtx *));
+static enum rtx_code find_comparison_args PARAMS ((enum rtx_code, rtx *, rtx *,
+                                                  enum machine_mode *,
+                                                  enum machine_mode *));
+static rtx fold_rtx            PARAMS ((rtx, rtx));
+static rtx equiv_constant      PARAMS ((rtx));
+static void record_jump_equiv  PARAMS ((rtx, int));
+static void record_jump_cond   PARAMS ((enum rtx_code, enum machine_mode,
+                                        rtx, rtx, int));
+static void cse_insn           PARAMS ((rtx, rtx));
+static int addr_affects_sp_p   PARAMS ((rtx));
+static void invalidate_from_clobbers PARAMS ((rtx));
+static rtx cse_process_notes   PARAMS ((rtx, rtx));
+static void cse_around_loop    PARAMS ((rtx));
+static void invalidate_skipped_set PARAMS ((rtx, rtx, void *));
+static void invalidate_skipped_block PARAMS ((rtx));
+static void cse_check_loop_start PARAMS ((rtx, rtx, void *));
+static void cse_set_around_loop        PARAMS ((rtx, rtx, rtx));
+static rtx cse_basic_block     PARAMS ((rtx, rtx, struct branch_path *, int));
+static void count_reg_usage    PARAMS ((rtx, int *, rtx, int));
+extern void dump_class          PARAMS ((struct table_elt*));
+static struct cse_reg_info * get_cse_reg_info PARAMS ((unsigned int));
+static int check_dependence    PARAMS ((rtx *, void *));
+
+static void flush_hash_table   PARAMS ((void));
 \f
-/* Return an estimate of the cost of computing rtx X.
-   One use is in cse, to decide which expression to keep in the hash table.
-   Another is in rtl generation, to pick the cheapest way to multiply.
-   Other uses like the latter are expected in the future.  */
+/* Dump the expressions in the equivalence class indicated by CLASSP.
+   This function is used only for debugging.  */
+void
+dump_class (classp)
+     struct table_elt *classp;
+{
+  struct table_elt *elt;
+
+  fprintf (stderr, "Equivalence chain for ");
+  print_rtl (stderr, classp->exp);
+  fprintf (stderr, ": \n");
+  
+  for (elt = classp->first_same_value; elt; elt = elt->next_same_value)
+    {
+      print_rtl (stderr, elt->exp);
+      fprintf (stderr, "\n");
+    }
+}
 
 /* Internal function, to compute cost when X is not a register; called
    from COST macro to keep it simple.  */
@@ -699,6 +756,11 @@ notreg_cost (x)
 
 #define COSTS_N_INSNS(N) ((N) * 4 - 2)
 
+/* Return an estimate of the cost of computing rtx X.
+   One use is in cse, to decide which expression to keep in the hash table.
+   Another is in rtl generation, to pick the cheapest way to multiply.
+   Other uses like the latter are expected in the future.  */
+
 int
 rtx_cost (x, outer_code)
      rtx x;
@@ -706,7 +768,7 @@ rtx_cost (x, outer_code)
 {
   register int i, j;
   register enum rtx_code code;
-  register char *fmt;
+  register const char *fmt;
   register int total;
 
   if (x == 0)
@@ -787,6 +849,51 @@ rtx_cost (x, outer_code)
   return total;
 }
 \f
+static struct cse_reg_info *
+get_cse_reg_info (regno)
+     unsigned int regno;
+{
+  struct cse_reg_info **hash_head = &reg_hash[REGHASH_FN (regno)];
+  struct cse_reg_info *p;
+
+  for (p = *hash_head ; p != NULL; p = p->hash_next)
+    if (p->regno == regno)
+      break;
+
+  if (p == NULL)
+    {
+      /* Get a new cse_reg_info structure.  */
+      if (cse_reg_info_free_list)
+       {
+         p = cse_reg_info_free_list;
+         cse_reg_info_free_list = p->next;
+       }
+      else
+       p = (struct cse_reg_info *) xmalloc (sizeof (struct cse_reg_info));
+
+      /* Insert into hash table.  */
+      p->hash_next = *hash_head;
+      *hash_head = p;
+
+      /* Initialize it.  */
+      p->reg_tick = 1;
+      p->reg_in_table = -1;
+      p->reg_qty = regno;
+      p->regno = regno;
+      p->next = cse_reg_info_used_list;
+      cse_reg_info_used_list = p;
+      if (!cse_reg_info_used_list_end)
+       cse_reg_info_used_list_end = p;
+    }
+
+  /* Cache this lookup; we tend to be looking up information about the
+     same register several times in a row.  */
+  cached_regno = regno;
+  cached_cse_reg_info = p;
+
+  return p;
+}
+
 /* Clear the hash table and initialize each register with its own quantity,
    for a new basic block.  */
 
@@ -797,28 +904,45 @@ new_basic_block ()
 
   next_qty = max_reg;
 
-  bzero ((char *) reg_tick, max_reg * sizeof (int));
+  /* Clear out hash table state for this pass.  */
+
+  bzero ((char *) reg_hash, sizeof reg_hash);
+
+  if (cse_reg_info_used_list)
+    {
+      cse_reg_info_used_list_end->next = cse_reg_info_free_list;
+      cse_reg_info_free_list = cse_reg_info_used_list;
+      cse_reg_info_used_list = cse_reg_info_used_list_end = 0;
+    }
+  cached_cse_reg_info = 0;
 
-  bcopy ((char *) all_minus_one, (char *) reg_in_table,
-        max_reg * sizeof (int));
-  bcopy ((char *) consec_ints, (char *) reg_qty, max_reg * sizeof (int));
   CLEAR_HARD_REG_SET (hard_regs_in_table);
 
   /* The per-quantity values used to be initialized here, but it is
      much faster to initialize each as it is made in `make_new_qty'.  */
 
-  for (i = 0; i < NBUCKETS; i++)
+  for (i = 0; i < HASH_SIZE; i++)
     {
-      register struct table_elt *this, *next;
-      for (this = table[i]; this; this = next)
+      struct table_elt *first;
+
+      first = table[i];
+      if (first != NULL)
        {
-         next = this->next_same_hash;
-         free_element (this);
+         struct table_elt *last = first;
+
+         table[i] = NULL;
+
+         while (last->next_same_hash != NULL)
+           last = last->next_same_hash;
+
+         /* Now relink this hash entire chain into
+            the free element list.  */
+
+         last->next_same_hash = free_element_chain;
+         free_element_chain = first;
        }
     }
 
-  bzero ((char *) table, sizeof table);
-
   prev_insn = 0;
 
 #ifdef HAVE_cc0
@@ -826,25 +950,31 @@ new_basic_block ()
 #endif
 }
 
-/* Say that register REG contains a quantity not in any register before
-   and initialize that quantity.  */
+/* Say that register REG contains a quantity in mode MODE not in any
+   register before and initialize that quantity.  */
 
 static void
-make_new_qty (reg)
-     register int reg;
+make_new_qty (reg, mode)
+     unsigned int reg;
+     enum machine_mode mode;
 {
   register int q;
+  register struct qty_table_elem *ent;
+  register struct reg_eqv_elem *eqv;
 
   if (next_qty >= max_qty)
     abort ();
 
-  q = reg_qty[reg] = next_qty++;
-  qty_first_reg[q] = reg;
-  qty_last_reg[q] = reg;
-  qty_const[q] = qty_const_insn[q] = 0;
-  qty_comparison_code[q] = UNKNOWN;
+  q = REG_QTY (reg) = next_qty++;
+  ent = &qty_table[q];
+  ent->first_reg = reg;
+  ent->last_reg = reg;
+  ent->mode = mode;
+  ent->const_rtx = ent->const_insn = NULL_RTX;
+  ent->comparison_code = UNKNOWN;
 
-  reg_next_eqv[reg] = reg_prev_eqv[reg] = -1;
+  eqv = &reg_eqv_table[reg];
+  eqv->next = eqv->prev = -1;
 }
 
 /* Make reg NEW equivalent to reg OLD.
@@ -852,18 +982,21 @@ make_new_qty (reg)
 
 static void
 make_regs_eqv (new, old)
-     register int new, old;
+     unsigned int new, old;
 {
-  register int lastr, firstr;
-  register int q = reg_qty[old];
+  unsigned int lastr, firstr;
+  int q = REG_QTY (old);
+  struct qty_table_elem *ent;
+
+  ent = &qty_table[q];
 
   /* Nothing should become eqv until it has a "non-invalid" qty number.  */
   if (! REGNO_QTY_VALID_P (old))
     abort ();
 
-  reg_qty[new] = q;
-  firstr = qty_first_reg[q];
-  lastr = qty_last_reg[q];
+  REG_QTY (new) = q;
+  firstr = ent->first_reg;
+  lastr = ent->last_reg;
 
   /* Prefer fixed hard registers to anything.  Prefer pseudo regs to other
      hard regs.  Among pseudos, if NEW will live longer than any other reg
@@ -884,10 +1017,10 @@ make_regs_eqv (new, old)
                      && (uid_cuid[REGNO_LAST_UID (new)]
                          > uid_cuid[REGNO_LAST_UID (firstr)]))))))
     {
-      reg_prev_eqv[firstr] = new;
-      reg_next_eqv[new] = firstr;
-      reg_prev_eqv[new] = -1;
-      qty_first_reg[q] = new;
+      reg_eqv_table[firstr].prev = new;
+      reg_eqv_table[new].next = firstr;
+      reg_eqv_table[new].prev = -1;
+      ent->first_reg = new;
     }
   else
     {
@@ -895,17 +1028,17 @@ make_regs_eqv (new, old)
         Otherwise, insert before any non-fixed hard regs that are at the
         end.  Registers of class NO_REGS cannot be used as an
         equivalent for anything.  */
-      while (lastr < FIRST_PSEUDO_REGISTER && reg_prev_eqv[lastr] >= 0
+      while (lastr < FIRST_PSEUDO_REGISTER && reg_eqv_table[lastr].prev >= 0
             && (REGNO_REG_CLASS (lastr) == NO_REGS || ! FIXED_REGNO_P (lastr))
             && new >= FIRST_PSEUDO_REGISTER)
-       lastr = reg_prev_eqv[lastr];
-      reg_next_eqv[new] = reg_next_eqv[lastr];
-      if (reg_next_eqv[lastr] >= 0)
-       reg_prev_eqv[reg_next_eqv[lastr]] = new;
+       lastr = reg_eqv_table[lastr].prev;
+      reg_eqv_table[new].next = reg_eqv_table[lastr].next;
+      if (reg_eqv_table[lastr].next >= 0)
+       reg_eqv_table[reg_eqv_table[lastr].next].prev = new;
       else
-       qty_last_reg[q] = new;
-      reg_next_eqv[lastr] = new;
-      reg_prev_eqv[new] = lastr;
+       qty_table[q].last_reg = new;
+      reg_eqv_table[lastr].next = new;
+      reg_eqv_table[new].prev = lastr;
     }
 }
 
@@ -913,28 +1046,31 @@ make_regs_eqv (new, old)
 
 static void
 delete_reg_equiv (reg)
-     register int reg;
+     unsigned int reg;
 {
-  register int q = reg_qty[reg];
+  register struct qty_table_elem *ent;
+  register int q = REG_QTY (reg);
   register int p, n;
 
   /* If invalid, do nothing.  */
-  if (q == reg)
+  if (q == (int) reg)
     return;
 
-  p = reg_prev_eqv[reg];
-  n = reg_next_eqv[reg];
+  ent = &qty_table[q];
+
+  p = reg_eqv_table[reg].prev;
+  n = reg_eqv_table[reg].next;
 
   if (n != -1)
-    reg_prev_eqv[n] = p;
+    reg_eqv_table[n].prev = p;
   else
-    qty_last_reg[q] = p;
+    ent->last_reg = p;
   if (p != -1)
-    reg_next_eqv[p] = n;
+    reg_eqv_table[p].next = n;
   else
-    qty_first_reg[q] = n;
+    ent->first_reg = n;
 
-  reg_qty[reg] = reg;
+  REG_QTY (reg) = reg;
 }
 
 /* Remove any invalid expressions from the hash table
@@ -955,7 +1091,7 @@ mention_regs (x)
 {
   register enum rtx_code code;
   register int i, j;
-  register char *fmt;
+  register const char *fmt;
   register int changed = 0;
 
   if (x == 0)
@@ -964,18 +1100,18 @@ mention_regs (x)
   code = GET_CODE (x);
   if (code == REG)
     {
-      register int regno = REGNO (x);
-      register int endregno
+      unsigned int regno = REGNO (x);
+      unsigned int endregno
        = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1
                   : HARD_REGNO_NREGS (regno, GET_MODE (x)));
-      int i;
+      unsigned int i;
 
       for (i = regno; i < endregno; i++)
        {
-         if (reg_in_table[i] >= 0 && reg_in_table[i] != reg_tick[i])
+         if (REG_IN_TABLE (i) >= 0 && REG_IN_TABLE (i) != REG_TICK (i))
            remove_invalid_refs (i);
 
-         reg_in_table[i] = reg_tick[i];
+         REG_IN_TABLE (i) = REG_TICK (i);
        }
 
       return 0;
@@ -987,21 +1123,21 @@ mention_regs (x)
   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG
       && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER)
     {
-      int i = REGNO (SUBREG_REG (x));
+      unsigned int i = REGNO (SUBREG_REG (x));
 
-      if (reg_in_table[i] >= 0 && reg_in_table[i] != reg_tick[i])
+      if (REG_IN_TABLE (i) >= 0 && REG_IN_TABLE (i) != REG_TICK (i))
        {
          /* If reg_tick has been incremented more than once since
             reg_in_table was last set, that means that the entire
             register has been set before, so discard anything memorized
             for the entrire register, including all SUBREG expressions.  */
-         if (reg_in_table[i] != reg_tick[i] - 1)
+         if (REG_IN_TABLE (i) != REG_TICK (i) - 1)
            remove_invalid_refs (i);
          else
            remove_invalid_subreg_refs (i, SUBREG_WORD (x), GET_MODE (x));
        }
 
-      reg_in_table[i] = reg_tick[i];
+      REG_IN_TABLE (i) = REG_TICK (i);
       return 0;
     }
 
@@ -1063,16 +1199,22 @@ insert_regs (x, classp, modified)
 {
   if (GET_CODE (x) == REG)
     {
-      register int regno = REGNO (x);
+      unsigned int regno = REGNO (x);
+      int qty_valid;
 
       /* If REGNO is in the equivalence table already but is of the
         wrong mode for that equivalence, don't do anything here.  */
 
-      if (REGNO_QTY_VALID_P (regno)
-         && qty_mode[reg_qty[regno]] != GET_MODE (x))
-       return 0;
+      qty_valid = REGNO_QTY_VALID_P (regno);
+      if (qty_valid)
+       {
+         struct qty_table_elem *ent = &qty_table[REG_QTY (regno)];
+
+         if (ent->mode != GET_MODE (x))
+           return 0;
+       }
 
-      if (modified || ! REGNO_QTY_VALID_P (regno))
+      if (modified || ! qty_valid)
        {
          if (classp)
            for (classp = classp->first_same_value;
@@ -1085,8 +1227,7 @@ insert_regs (x, classp, modified)
                  return 1;
                }
 
-         make_new_qty (regno);
-         qty_mode[reg_qty[regno]] = GET_MODE (x);
+         make_new_qty (regno, GET_MODE (x));
          return 1;
        }
 
@@ -1102,7 +1243,7 @@ insert_regs (x, classp, modified)
   else if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == REG
           && ! REGNO_QTY_VALID_P (REGNO (SUBREG_REG (x))))
     {
-      int regno = REGNO (SUBREG_REG (x));
+      unsigned int regno = REGNO (SUBREG_REG (x));
 
       insert_regs (SUBREG_REG (x), NULL_PTR, 0);
       /* Mention_regs checks if REG_TICK is exactly one larger than
@@ -1111,9 +1252,9 @@ insert_regs (x, classp, modified)
         for the full register.  Since we don't invalidate the SUBREG
         here first, we might have to bump up REG_TICK so that mention_regs
         will do the right thing.  */
-      if (reg_in_table[regno] >= 0
-         && reg_tick[regno] == reg_in_table[regno] + 1)
-       reg_tick[regno]++;
+      if (REG_IN_TABLE (regno) >= 0
+         && REG_TICK (regno) == REG_IN_TABLE (regno) + 1)
+       REG_TICK (regno)++;
       mention_regs (x);
       return 1;
     }
@@ -1123,31 +1264,6 @@ insert_regs (x, classp, modified)
 \f
 /* Look in or update the hash table.  */
 
-/* Put the element ELT on the list of free elements.  */
-
-static void
-free_element (elt)
-     struct table_elt *elt;
-{
-  elt->next_same_hash = free_element_chain;
-  free_element_chain = elt;
-}
-
-/* Return an element that is free for use.  */
-
-static struct table_elt *
-get_element ()
-{
-  struct table_elt *elt = free_element_chain;
-  if (elt)
-    {
-      free_element_chain = elt->next_same_hash;
-      return elt;
-    }
-  n_elements_made++;
-  return (struct table_elt *) oballoc (sizeof (struct table_elt));
-}
-
 /* Remove table element ELT from use in the table.
    HASH is its hash code, made using the HASH macro.
    It's an argument because often that is known in advance
@@ -1203,7 +1319,7 @@ remove_from_table (elt, hash)
           when two classes were merged by `merge_equiv_classes'.  Search
           for the hash bucket that it heads.  This happens only very
           rarely, so the cost is acceptable.  */
-       for (hash = 0; hash < NBUCKETS; hash++)
+       for (hash = 0; hash < HASH_SIZE; hash++)
          if (table[hash] == elt)
            table[hash] = next;
       }
@@ -1214,6 +1330,7 @@ remove_from_table (elt, hash)
   if (elt->related_value != 0 && elt->related_value != elt)
     {
       register struct table_elt *p = elt->related_value;
+
       while (p->related_value != elt)
        p = p->related_value;
       p->related_value = elt->related_value;
@@ -1221,7 +1338,9 @@ remove_from_table (elt, hash)
        p->related_value = 0;
     }
 
-  free_element (elt);
+  /* Now add it to the free element chain.  */
+  elt->next_same_hash = free_element_chain;
+  free_element_chain = elt;
 }
 
 /* Look up X in the hash table and return its table element,
@@ -1262,7 +1381,8 @@ lookup_for_remove (x, hash, mode)
 
   if (GET_CODE (x) == REG)
     {
-      int regno = REGNO (x);
+      unsigned int regno = REGNO (x);
+
       /* Don't check the machine mode when comparing registers;
         invalidating (REG:SI 0) also invalidates (REG:DF 0).  */
       for (p = table[hash]; p; p = p->next_same_hash)
@@ -1288,8 +1408,9 @@ lookup_as_function (x, code)
      rtx x;
      enum rtx_code code;
 {
-  register struct table_elt *p = lookup (x, safe_hash (x, VOIDmode) % NBUCKETS,
-                                        GET_MODE (x));
+  register struct table_elt *p
+    = lookup (x, safe_hash (x, VOIDmode) & HASH_MASK, GET_MODE (x));
+
   /* If we are looking for a CONST_INT, the mode doesn't really matter, as
      long as we are narrowing.  So if we looked in vain for a mode narrower
      than word_mode before, look for word_mode now.  */
@@ -1298,19 +1419,17 @@ lookup_as_function (x, code)
     {
       x = copy_rtx (x);
       PUT_MODE (x, word_mode);
-      p = lookup (x, safe_hash (x, VOIDmode) % NBUCKETS, word_mode);
+      p = lookup (x, safe_hash (x, VOIDmode) & HASH_MASK, word_mode);
     }
 
   if (p == 0)
     return 0;
 
   for (p = p->first_same_value; p; p = p->next_same_value)
-    {
-      if (GET_CODE (p->exp) == code
-         /* Make sure this is a valid entry in the table.  */
-         && exp_equiv_p (p->exp, p->exp, 1, 0))
-       return p->exp;
-    }
+    if (GET_CODE (p->exp) == code
+       /* Make sure this is a valid entry in the table.  */
+       && exp_equiv_p (p->exp, p->exp, 1, 0))
+      return p->exp;
   
   return 0;
 }
@@ -1358,12 +1477,12 @@ insert (x, classp, hash, mode)
   /* If X is a hard register, show it is being put in the table.  */
   if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
     {
-      int regno = REGNO (x);
-      int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
-      int i;
+      unsigned int regno = REGNO (x);
+      unsigned int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
+      unsigned int i;
 
       for (i = regno; i < endregno; i++)
-           SET_HARD_REG_BIT (hard_regs_in_table, i);
+       SET_HARD_REG_BIT (hard_regs_in_table, i);
     }
 
   /* If X is a label, show we recorded it.  */
@@ -1374,8 +1493,17 @@ insert (x, classp, hash, mode)
 
   /* Put an element for X into the right hash bucket.  */
 
-  elt = get_element ();
+  elt = free_element_chain;
+  if (elt)
+    free_element_chain = elt->next_same_hash;
+  else
+    {
+      n_elements_made++;
+      elt = (struct table_elt *) oballoc (sizeof (struct table_elt));
+    }
+
   elt->exp = x;
+  elt->canon_exp = NULL_RTX;
   elt->cost = COST (x);
   elt->next_same_value = 0;
   elt->prev_same_value = 0;
@@ -1416,12 +1544,15 @@ insert (x, classp, hash, mode)
          /* Insert not at head of the class.  */
          /* Put it after the last element cheaper than X.  */
          register struct table_elt *p, *next;
+
          for (p = classp; (next = p->next_same_value) && CHEAPER (next, elt);
               p = next);
+
          /* Put it after P and before NEXT.  */
          elt->next_same_value = next;
          if (next)
            next->prev_same_value = elt;
+
          elt->prev_same_value = p;
          p->next_same_value = elt;
          elt->first_same_value = classp;
@@ -1442,18 +1573,22 @@ insert (x, classp, hash, mode)
      constant, we must check the entire class.
 
      If this is a register that is already known equivalent to an insn,
-     update `qty_const_insn' to show that `this_insn' is the latest
+     update the qtys `const_insn' to show that `this_insn' is the latest
      insn making that quantity equivalent to the constant.  */
 
   if (elt->is_const && classp && GET_CODE (classp->exp) == REG
       && GET_CODE (x) != REG)
     {
-      qty_const[reg_qty[REGNO (classp->exp)]]
-       = gen_lowpart_if_possible (qty_mode[reg_qty[REGNO (classp->exp)]], x);
-      qty_const_insn[reg_qty[REGNO (classp->exp)]] = this_insn;
+      int exp_q = REG_QTY (REGNO (classp->exp));
+      struct qty_table_elem *exp_ent = &qty_table[exp_q];
+
+      exp_ent->const_rtx = gen_lowpart_if_possible (exp_ent->mode, x);
+      exp_ent->const_insn = this_insn;
     }
 
-  else if (GET_CODE (x) == REG && classp && ! qty_const[reg_qty[REGNO (x)]]
+  else if (GET_CODE (x) == REG
+          && classp
+          && ! qty_table[REG_QTY (REGNO (x))].const_rtx
           && ! elt->is_const)
     {
       register struct table_elt *p;
@@ -1462,17 +1597,21 @@ insert (x, classp, hash, mode)
        {
          if (p->is_const && GET_CODE (p->exp) != REG)
            {
-             qty_const[reg_qty[REGNO (x)]]
+             int x_q = REG_QTY (REGNO (x));
+             struct qty_table_elem *x_ent = &qty_table[x_q];
+
+             x_ent->const_rtx
                = gen_lowpart_if_possible (GET_MODE (x), p->exp);
-             qty_const_insn[reg_qty[REGNO (x)]] = this_insn;
+             x_ent->const_insn = this_insn;
              break;
            }
        }
     }
 
-  else if (GET_CODE (x) == REG && qty_const[reg_qty[REGNO (x)]]
-          && GET_MODE (x) == qty_mode[reg_qty[REGNO (x)]])
-    qty_const_insn[reg_qty[REGNO (x)]] = this_insn;
+  else if (GET_CODE (x) == REG
+          && qty_table[REG_QTY (REGNO (x))].const_rtx
+          && GET_MODE (x) == qty_table[REG_QTY (REGNO (x))].mode)
+    qty_table[REG_QTY (REGNO (x))].const_insn = this_insn;
 
   /* If this is a constant with symbolic value,
      and it has a term with an explicit integer value,
@@ -1486,7 +1625,7 @@ insert (x, classp, hash, mode)
       if (subexp != 0)
        {
          /* Get the integer-free subexpression in the hash table.  */
-         subhash = safe_hash (subexp, mode) % NBUCKETS;
+         subhash = safe_hash (subexp, mode) & HASH_MASK;
          subelt = lookup (subexp, subhash, mode);
          if (subelt == 0)
            subelt = insert (subexp, NULL_PTR, subhash, mode);
@@ -1532,7 +1671,7 @@ merge_equiv_classes (class1, class2)
 
   for (elt = class2; elt; elt = next)
     {
-      unsigned hash;
+      unsigned int hash;
       rtx exp = elt->exp;
       enum machine_mode mode = elt->mode;
 
@@ -1544,7 +1683,6 @@ merge_equiv_classes (class1, class2)
       if (GET_CODE (exp) == REG || exp_equiv_p (exp, exp, 1, 0))
        {
          hash_arg_in_memory = 0;
-         hash_arg_in_struct = 0;
          hash = HASH (exp, mode);
              
          if (GET_CODE (exp) == REG)
@@ -1559,24 +1697,60 @@ merge_equiv_classes (class1, class2)
            }
          new = insert (exp, class1, hash, mode);
          new->in_memory = hash_arg_in_memory;
-         new->in_struct = hash_arg_in_struct;
        }
     }
 }
 \f
-/* Remove from the hash table, or mark as invalid,
-   all expressions whose values could be altered by storing in X.
-   X is a register, a subreg, or a memory reference with nonvarying address
-   (because, when a memory reference with a varying address is stored in,
-   all memory references are removed by invalidate_memory
-   so specific invalidation is superfluous).
-   FULL_MODE, if not VOIDmode, indicates that this much should be invalidated
-   instead of just the amount indicated by the mode of X.  This is only used
-   for bitfield stores into memory.
-
-   A nonvarying address may be just a register or just
-   a symbol reference, or it may be either of those plus
-   a numeric offset.  */
+
+/* Flush the entire hash table.  */
+
+static void
+flush_hash_table ()
+{
+  int i;
+  struct table_elt *p;
+
+  for (i = 0; i < HASH_SIZE; i++)
+    for (p = table[i]; p; p = table[i])
+      {
+       /* Note that invalidate can remove elements
+          after P in the current hash chain.  */
+       if (GET_CODE (p->exp) == REG)
+         invalidate (p->exp, p->mode);
+       else
+         remove_from_table (p, i);
+      }
+}
+\f
+/* Function called for each rtx to check whether true dependence exist.  */
+struct check_dependence_data
+{
+  enum machine_mode mode;
+  rtx exp;
+};
+static int
+check_dependence (x, data)
+     rtx *x;
+     void *data;
+{
+  struct check_dependence_data *d = (struct check_dependence_data *) data;
+  if (*x && GET_CODE (*x) == MEM)
+    return true_dependence (d->exp, d->mode, *x, cse_rtx_varies_p);
+  else
+    return 0;
+}
+\f
+/* Remove from the hash table, or mark as invalid, all expressions whose
+   values could be altered by storing in X.  X is a register, a subreg, or
+   a memory reference with nonvarying address (because, when a memory
+   reference with a varying address is stored in, all memory references are
+   removed by invalidate_memory so specific invalidation is superfluous).
+   FULL_MODE, if not VOIDmode, indicates that this much should be
+   invalidated instead of just the amount indicated by the mode of X.  This
+   is only used for bitfield stores into memory.
+
+   A nonvarying address may be just a register or just a symbol reference,
+   or it may be either of those plus a numeric offset.  */
 
 static void
 invalidate (x, full_mode)
@@ -1586,130 +1760,133 @@ invalidate (x, full_mode)
   register int i;
   register struct table_elt *p;
 
-  /* If X is a register, dependencies on its contents
-     are recorded through the qty number mechanism.
-     Just change the qty number of the register,
-     mark it as invalid for expressions that refer to it,
-     and remove it itself.  */
-
-  if (GET_CODE (x) == REG)
+  switch (GET_CODE (x))
     {
-      register int regno = REGNO (x);
-      register unsigned hash = HASH (x, GET_MODE (x));
-
-      /* Remove REGNO from any quantity list it might be on and indicate
-        that its value might have changed.  If it is a pseudo, remove its
-        entry from the hash table.
-
-        For a hard register, we do the first two actions above for any
-        additional hard registers corresponding to X.  Then, if any of these
-        registers are in the table, we must remove any REG entries that
-        overlap these registers.  */
-
-      delete_reg_equiv (regno);
-      reg_tick[regno]++;
+    case REG:
+      {
+       /* If X is a register, dependencies on its contents are recorded
+          through the qty number mechanism.  Just change the qty number of
+          the register, mark it as invalid for expressions that refer to it,
+          and remove it itself.  */
+       unsigned int regno = REGNO (x);
+       unsigned int hash = HASH (x, GET_MODE (x));
+
+       /* Remove REGNO from any quantity list it might be on and indicate
+          that its value might have changed.  If it is a pseudo, remove its
+          entry from the hash table.
+
+          For a hard register, we do the first two actions above for any
+          additional hard registers corresponding to X.  Then, if any of these
+          registers are in the table, we must remove any REG entries that
+          overlap these registers.  */
 
-      if (regno >= FIRST_PSEUDO_REGISTER)
-       {
-         /* Because a register can be referenced in more than one mode,
-            we might have to remove more than one table entry.  */
+       delete_reg_equiv (regno);
+       REG_TICK (regno)++;
 
-         struct table_elt *elt;
+       if (regno >= FIRST_PSEUDO_REGISTER)
+         {
+           /* Because a register can be referenced in more than one mode,
+              we might have to remove more than one table entry.  */
+           struct table_elt *elt;
 
-         while ((elt = lookup_for_remove (x, hash, GET_MODE (x))))
-           remove_from_table (elt, hash);
-       }
-      else
-       {
-         HOST_WIDE_INT in_table
-           = TEST_HARD_REG_BIT (hard_regs_in_table, regno);
-         int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
-         int tregno, tendregno;
-         register struct table_elt *p, *next;
+           while ((elt = lookup_for_remove (x, hash, GET_MODE (x))))
+             remove_from_table (elt, hash);
+         }
+       else
+         {
+           HOST_WIDE_INT in_table
+             = TEST_HARD_REG_BIT (hard_regs_in_table, regno);
+           unsigned int endregno
+             = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
+           unsigned int tregno, tendregno, rn;
+           register struct table_elt *p, *next;
 
-         CLEAR_HARD_REG_BIT (hard_regs_in_table, regno);
+           CLEAR_HARD_REG_BIT (hard_regs_in_table, regno);
 
-         for (i = regno + 1; i < endregno; i++)
-           {
-             in_table |= TEST_HARD_REG_BIT (hard_regs_in_table, i);
-             CLEAR_HARD_REG_BIT (hard_regs_in_table, i);
-             delete_reg_equiv (i);
-             reg_tick[i]++;
-           }
+           for (rn = regno + 1; rn < endregno; rn++)
+             {
+               in_table |= TEST_HARD_REG_BIT (hard_regs_in_table, rn);
+               CLEAR_HARD_REG_BIT (hard_regs_in_table, rn);
+               delete_reg_equiv (rn);
+               REG_TICK (rn)++;
+             }
 
-         if (in_table)
-           for (hash = 0; hash < NBUCKETS; hash++)
-             for (p = table[hash]; p; p = next)
-               {
-                 next = p->next_same_hash;
+           if (in_table)
+             for (hash = 0; hash < HASH_SIZE; hash++)
+               for (p = table[hash]; p; p = next)
+                 {
+                   next = p->next_same_hash;
 
                  if (GET_CODE (p->exp) != REG
                      || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER)
                    continue;
-
-                 tregno = REGNO (p->exp);
-                 tendregno
-                   = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (p->exp));
-                 if (tendregno > regno && tregno < endregno)
-                   remove_from_table (p, hash);
-               }
-       }
-
+                 
+                   tregno = REGNO (p->exp);
+                   tendregno
+                     = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (p->exp));
+                   if (tendregno > regno && tregno < endregno)
+                     remove_from_table (p, hash);
+                 }
+         }
+      }
       return;
-    }
 
-  if (GET_CODE (x) == SUBREG)
-    {
-      if (GET_CODE (SUBREG_REG (x)) != REG)
-       abort ();
+    case SUBREG:
       invalidate (SUBREG_REG (x), VOIDmode);
       return;
-    }
 
-  /* If X is a parallel, invalidate all of its elements.  */
-
-  if (GET_CODE (x) == PARALLEL)
-    {
+    case PARALLEL:
       for (i = XVECLEN (x, 0) - 1; i >= 0 ; --i)
        invalidate (XVECEXP (x, 0, i), VOIDmode);
       return;
-    }
-
-  /* If X is an expr_list, this is part of a disjoint return value;
-     extract the location in question ignoring the offset.  */
 
-  if (GET_CODE (x) == EXPR_LIST)
-    {
+    case EXPR_LIST:
+      /* This is part of a disjoint return value; extract the location in
+        question ignoring the offset.  */
       invalidate (XEXP (x, 0), VOIDmode);
       return;
-    }
-
-  /* X is not a register; it must be a memory reference with
-     a nonvarying address.  Remove all hash table elements
-     that refer to overlapping pieces of memory.  */
 
-  if (GET_CODE (x) != MEM)
-    abort ();
+    case MEM:
+      /* Calculate the canonical version of X here so that
+        true_dependence doesn't generate new RTL for X on each call.  */
+      x = canon_rtx (x);
 
-  if (full_mode == VOIDmode)
-    full_mode = GET_MODE (x);
+      /* Remove all hash table elements that refer to overlapping pieces of
+        memory.  */
+      if (full_mode == VOIDmode)
+       full_mode = GET_MODE (x);
 
-  for (i = 0; i < NBUCKETS; i++)
-    {
-      register struct table_elt *next;
-      for (p = table[i]; p; p = next)
+      for (i = 0; i < HASH_SIZE; i++)
        {
-         next = p->next_same_hash;
-         /* Invalidate ASM_OPERANDS which reference memory (this is easier
-            than checking all the aliases).  */
-         if (p->in_memory
-             && (GET_CODE (p->exp) != MEM
-                 || true_dependence (x, full_mode, p->exp, cse_rtx_varies_p)))
-           remove_from_table (p, i);
+         register struct table_elt *next;
+
+         for (p = table[i]; p; p = next)
+           {
+             next = p->next_same_hash;
+             if (p->in_memory)
+               {
+                 struct check_dependence_data d;
+
+                 /* Just canonicalize the expression once;
+                    otherwise each time we call invalidate
+                    true_dependence will canonicalize the
+                    expression again.  */
+                 if (!p->canon_exp)
+                   p->canon_exp = canon_rtx (p->exp);
+                 d.exp = x;
+                 d.mode = full_mode;
+                 if (for_each_rtx (&p->canon_exp, check_dependence, &d))
+                   remove_from_table (p, i);
+               }
+           }
        }
+      return;
+
+    default:
+      abort ();
     }
 }
-
+\f
 /* Remove all expressions that refer to register REGNO,
    since they are already invalid, and we are about to
    mark that register valid again and don't want the old
@@ -1717,12 +1894,12 @@ invalidate (x, full_mode)
 
 static void
 remove_invalid_refs (regno)
-     int regno;
+     unsigned int regno;
 {
-  register int i;
-  register struct table_elt *p, *next;
+  unsigned int i;
+  struct table_elt *p, *next;
 
-  for (i = 0; i < NBUCKETS; i++)
+  for (i = 0; i < HASH_SIZE; i++)
     for (p = table[i]; p; p = next)
       {
        next = p->next_same_hash;
@@ -1735,15 +1912,15 @@ remove_invalid_refs (regno)
 /* Likewise for a subreg with subreg_reg WORD and mode MODE.  */
 static void
 remove_invalid_subreg_refs (regno, word, mode)
-     int regno;
-     int word;
+     unsigned int regno;
+     unsigned int word;
      enum machine_mode mode;
 {
-  register int i;
-  register struct table_elt *p, *next;
-  int end = word + (GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD;
+  unsigned int i;
+  struct table_elt *p, *next;
+  unsigned int end = word + (GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD;
 
-  for (i = 0; i < NBUCKETS; i++)
+  for (i = 0; i < HASH_SIZE; i++)
     for (p = table[i]; p; p = next)
       {
        rtx exp;
@@ -1783,21 +1960,21 @@ rehash_using_reg (x)
      valid entries in the table, we have no work to do.  */
 
   if (GET_CODE (x) != REG
-      || reg_in_table[REGNO (x)] < 0
-      || reg_in_table[REGNO (x)] != reg_tick[REGNO (x)])
+      || REG_IN_TABLE (REGNO (x)) < 0
+      || REG_IN_TABLE (REGNO (x)) != REG_TICK (REGNO (x)))
     return;
 
   /* Scan all hash chains looking for valid entries that mention X.
      If we find one and it is in the wrong hash chain, move it.  We can skip
      objects that are registers, since they are handled specially.  */
 
-  for (i = 0; i < NBUCKETS; i++)
+  for (i = 0; i < HASH_SIZE; i++)
     for (p = table[i]; p; p = next)
       {
        next = p->next_same_hash;
        if (GET_CODE (p->exp) != REG && reg_mentioned_p (x, p->exp)
            && exp_equiv_p (p->exp, p->exp, 1, 0)
-           && i != (hash = safe_hash (p->exp, p->mode) % NBUCKETS))
+           && i != (hash = safe_hash (p->exp, p->mode) & HASH_MASK))
          {
            if (p->next_same_hash)
              p->next_same_hash->prev_same_hash = p->prev_same_hash;
@@ -1822,8 +1999,8 @@ rehash_using_reg (x)
 static void
 invalidate_for_call ()
 {
-  int regno, endregno;
-  int i;
+  unsigned int regno, endregno;
+  unsigned int i;
   unsigned hash;
   struct table_elt *p, *next;
   int in_table = 0;
@@ -1837,8 +2014,8 @@ invalidate_for_call ()
     if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
       {
        delete_reg_equiv (regno);
-       if (reg_tick[regno] >= 0)
-         reg_tick[regno]++;
+       if (REG_TICK (regno) >= 0)
+         REG_TICK (regno)++;
 
        in_table |= (TEST_HARD_REG_BIT (hard_regs_in_table, regno) != 0);
       }
@@ -1848,17 +2025,11 @@ invalidate_for_call ()
      entry that overlaps a call-clobbered register.  */
 
   if (in_table)
-    for (hash = 0; hash < NBUCKETS; hash++)
+    for (hash = 0; hash < HASH_SIZE; hash++)
       for (p = table[hash]; p; p = next)
        {
          next = p->next_same_hash;
 
-         if (p->in_memory)
-           {
-             remove_from_table (p, hash);
-             continue;
-           }
-
          if (GET_CODE (p->exp) != REG
              || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER)
            continue;
@@ -1901,7 +2072,7 @@ use_related_value (x, elt)
       rtx subexp = get_related_value (x);
       if (subexp != 0)
        relt = lookup (subexp,
-                      safe_hash (subexp, GET_MODE (subexp)) % NBUCKETS,
+                      safe_hash (subexp, GET_MODE (subexp)) & HASH_MASK,
                       GET_MODE (subexp));
     }
 
@@ -1959,8 +2130,6 @@ use_related_value (x, elt)
 
    Store 1 in hash_arg_in_memory if X contains a MEM rtx
    which does not have the RTX_UNCHANGING_P bit set.
-   In this case, also store 1 in hash_arg_in_struct
-   if there is a MEM rtx which has the MEM_IN_STRUCT_P bit set.
 
    Note that cse_insn knows that the hash code of a MEM expression
    is just (int) MEM plus the hash code of the address.  */
@@ -1973,7 +2142,7 @@ canon_hash (x, mode)
   register int i, j;
   register unsigned hash = 0;
   register enum rtx_code code;
-  register char *fmt;
+  register const char *fmt;
 
   /* repeat is used to turn tail-recursion into iteration.  */
  repeat:
@@ -1985,11 +2154,16 @@ canon_hash (x, mode)
     {
     case REG:
       {
-       register int regno = REGNO (x);
+       unsigned int regno = REGNO (x);
 
        /* On some machines, we can't record any non-fixed hard register,
           because extending its life will cause reload problems.  We
-          consider ap, fp, and sp to be fixed for this purpose.
+          consider ap, fp, and sp to be fixed for this purpose. 
+
+          We also consider CCmode registers to be fixed for this purpose;
+          failure to do so leads to failure to simplify 0<100 type of
+          conditionals.
+
           On all machines, we can't record any global registers.  */
 
        if (regno < FIRST_PSEUDO_REGISTER
@@ -1999,12 +2173,14 @@ canon_hash (x, mode)
                    && regno != FRAME_POINTER_REGNUM
                    && regno != HARD_FRAME_POINTER_REGNUM
                    && regno != ARG_POINTER_REGNUM
-                   && regno != STACK_POINTER_REGNUM)))
+                   && regno != STACK_POINTER_REGNUM
+                   && GET_MODE_CLASS (GET_MODE (x)) != MODE_CC)))
          {
            do_not_record = 1;
            return 0;
          }
-       hash += ((unsigned) REG << 7) + (unsigned) reg_qty[regno];
+
+       hash += ((unsigned) REG << 7) + (unsigned) REG_QTY (regno);
        return hash;
       }
 
@@ -2036,7 +2212,7 @@ canon_hash (x, mode)
       if (GET_MODE (x) != VOIDmode)
        for (i = 2; i < GET_RTX_LENGTH (CONST_DOUBLE); i++)
          {
-           unsigned tem = XINT (x, i);
+           unsigned HOST_WIDE_INT tem = XWINT (x, i);
            hash += tem;
          }
       else
@@ -2056,7 +2232,9 @@ canon_hash (x, mode)
       return hash;
 
     case MEM:
-      if (MEM_VOLATILE_P (x))
+      /* We don't record if marked volatile or if BLKmode since we don't
+        know the size of the move.  */
+      if (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode)
        {
          do_not_record = 1;
          return 0;
@@ -2064,7 +2242,6 @@ canon_hash (x, mode)
       if (! RTX_UNCHANGING_P (x) || FIXED_BASE_PLUS_P (XEXP (x, 0)))
        {
          hash_arg_in_memory = 1;
-         if (MEM_IN_STRUCT_P (x)) hash_arg_in_struct = 1;
        }
       /* Now that we have already found this special case,
         might as well speed it up as much as possible.  */
@@ -2119,7 +2296,9 @@ canon_hash (x, mode)
          hash += canon_hash (XVECEXP (x, i, j), 0);
       else if (fmt[i] == 's')
        {
-         register unsigned char *p = (unsigned char *) XSTR (x, i);
+         register const unsigned char *p =
+           (const unsigned char *) XSTR (x, i);
+
          if (p)
            while (*p)
              hash += *p++;
@@ -2129,7 +2308,7 @@ canon_hash (x, mode)
          register unsigned tem = XINT (x, i);
          hash += tem;
        }
-      else if (fmt[i] == '0')
+      else if (fmt[i] == '0' || fmt[i] == 't')
        /* unused */;
       else
        abort ();
@@ -2146,10 +2325,8 @@ safe_hash (x, mode)
 {
   int save_do_not_record = do_not_record;
   int save_hash_arg_in_memory = hash_arg_in_memory;
-  int save_hash_arg_in_struct = hash_arg_in_struct;
   unsigned hash = canon_hash (x, mode);
   hash_arg_in_memory = save_hash_arg_in_memory;
-  hash_arg_in_struct = save_hash_arg_in_struct;
   do_not_record = save_do_not_record;
   return hash;
 }
@@ -2177,7 +2354,7 @@ exp_equiv_p (x, y, validate, equal_values)
 {
   register int i, j;
   register enum rtx_code code;
-  register char *fmt;
+  register const char *fmt;
 
   /* Note: it is incorrect to assume an expression is equivalent to itself
      if VALIDATE is nonzero.  */
@@ -2195,17 +2372,27 @@ exp_equiv_p (x, y, validate, equal_values)
       /* If X is a constant and Y is a register or vice versa, they may be
         equivalent.  We only have to validate if Y is a register.  */
       if (CONSTANT_P (x) && GET_CODE (y) == REG
-         && REGNO_QTY_VALID_P (REGNO (y))
-         && GET_MODE (y) == qty_mode[reg_qty[REGNO (y)]]
-         && rtx_equal_p (x, qty_const[reg_qty[REGNO (y)]])
-         && (! validate || reg_in_table[REGNO (y)] == reg_tick[REGNO (y)]))
-       return 1;
+         && REGNO_QTY_VALID_P (REGNO (y)))
+       {
+         int y_q = REG_QTY (REGNO (y));
+         struct qty_table_elem *y_ent = &qty_table[y_q];
+
+         if (GET_MODE (y) == y_ent->mode
+             && rtx_equal_p (x, y_ent->const_rtx)
+             && (! validate || REG_IN_TABLE (REGNO (y)) == REG_TICK (REGNO (y))))
+           return 1;
+       }
 
       if (CONSTANT_P (y) && code == REG
-         && REGNO_QTY_VALID_P (REGNO (x))
-         && GET_MODE (x) == qty_mode[reg_qty[REGNO (x)]]
-         && rtx_equal_p (y, qty_const[reg_qty[REGNO (x)]]))
-       return 1;
+         && REGNO_QTY_VALID_P (REGNO (x)))
+       {
+         int x_q = REG_QTY (REGNO (x));
+         struct qty_table_elem *x_ent = &qty_table[x_q];
+
+         if (GET_MODE (x) == x_ent->mode
+             && rtx_equal_p (y, x_ent->const_rtx))
+           return 1;
+       }
 
       return 0;
     }
@@ -2218,10 +2405,8 @@ exp_equiv_p (x, y, validate, equal_values)
     {
     case PC:
     case CC0:
-      return x == y;
-
     case CONST_INT:
-      return INTVAL (x) == INTVAL (y);
+      return x == y;
 
     case LABEL_REF:
       return XEXP (x, 0) == XEXP (y, 0);
@@ -2231,24 +2416,24 @@ exp_equiv_p (x, y, validate, equal_values)
 
     case REG:
       {
-       int regno = REGNO (y);
-       int endregno
+       unsigned int regno = REGNO (y);
+       unsigned int endregno
          = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1
                     : HARD_REGNO_NREGS (regno, GET_MODE (y)));
-       int i;
+       unsigned int i;
 
        /* If the quantities are not the same, the expressions are not
           equivalent.  If there are and we are not to validate, they
           are equivalent.  Otherwise, ensure all regs are up-to-date.  */
 
-       if (reg_qty[REGNO (x)] != reg_qty[regno])
+       if (REG_QTY (REGNO (x)) != REG_QTY (regno))
          return 0;
 
        if (! validate)
          return 1;
 
        for (i = regno; i < endregno; i++)
-         if (reg_in_table[i] != reg_tick[i])
+         if (REG_IN_TABLE (i) != REG_TICK (i))
            return 0;
 
        return 1;
@@ -2312,6 +2497,7 @@ exp_equiv_p (x, y, validate, equal_values)
        break;
 
        case '0':
+       case 't':
          break;
 
        default:
@@ -2322,236 +2508,41 @@ exp_equiv_p (x, y, validate, equal_values)
   return 1;
 }
 \f
-/* Return 1 iff any subexpression of X matches Y.
-   Here we do not require that X or Y be valid (for registers referred to)
-   for being in the hash table.  */
+/* Return 1 if X has a value that can vary even between two
+   executions of the program.  0 means X can be compared reliably
+   against certain constants or near-constants.  */
 
 static int
-refers_to_p (x, y)
-     rtx x, y;
+cse_rtx_varies_p (x)
+     register rtx x;
 {
-  register int i;
-  register enum rtx_code code;
-  register char *fmt;
+  /* We need not check for X and the equivalence class being of the same
+     mode because if X is equivalent to a constant in some mode, it
+     doesn't vary in any mode.  */
 
- repeat:
-  if (x == y)
-    return 1;
-  if (x == 0 || y == 0)
-    return 0;
-
-  code = GET_CODE (x);
-  /* If X as a whole has the same code as Y, they may match.
-     If so, return 1.  */
-  if (code == GET_CODE (y))
-    {
-      if (exp_equiv_p (x, y, 0, 1))
-       return 1;
-    }
-
-  /* X does not match, so try its subexpressions.  */
-
-  fmt = GET_RTX_FORMAT (code);
-  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
-    if (fmt[i] == 'e')
-      {
-       if (i == 0)
-         {
-           x = XEXP (x, 0);
-           goto repeat;
-         }
-       else
-         if (refers_to_p (XEXP (x, i), y))
-           return 1;
-      }
-    else if (fmt[i] == 'E')
-      {
-       int j;
-       for (j = 0; j < XVECLEN (x, i); j++)
-         if (refers_to_p (XVECEXP (x, i, j), y))
-           return 1;
-      }
-
-  return 0;
-}
-\f
-/* Given ADDR and SIZE (a memory address, and the size of the memory reference),
-   set PBASE, PSTART, and PEND which correspond to the base of the address,
-   the starting offset, and ending offset respectively.
-
-   ADDR is known to be a nonvarying address.  */
-
-/* ??? Despite what the comments say, this function is in fact frequently
-   passed varying addresses.  This does not appear to cause any problems.  */
-
-static void
-set_nonvarying_address_components (addr, size, pbase, pstart, pend)
-     rtx addr;
-     int size;
-     rtx *pbase;
-     HOST_WIDE_INT *pstart, *pend;
-{
-  rtx base;
-  HOST_WIDE_INT start, end;
-
-  base = addr;
-  start = 0;
-  end = 0;
-
-  if (flag_pic && GET_CODE (base) == PLUS
-      && XEXP (base, 0) == pic_offset_table_rtx)
-    base = XEXP (base, 1);
-
-  /* Registers with nonvarying addresses usually have constant equivalents;
-     but the frame pointer register is also possible.  */
-  if (GET_CODE (base) == REG
-      && qty_const != 0
-      && REGNO_QTY_VALID_P (REGNO (base))
-      && qty_mode[reg_qty[REGNO (base)]] == GET_MODE (base)
-      && qty_const[reg_qty[REGNO (base)]] != 0)
-    base = qty_const[reg_qty[REGNO (base)]];
-  else if (GET_CODE (base) == PLUS
-          && GET_CODE (XEXP (base, 1)) == CONST_INT
-          && GET_CODE (XEXP (base, 0)) == REG
-          && qty_const != 0
-          && REGNO_QTY_VALID_P (REGNO (XEXP (base, 0)))
-          && (qty_mode[reg_qty[REGNO (XEXP (base, 0))]]
-              == GET_MODE (XEXP (base, 0)))
-          && qty_const[reg_qty[REGNO (XEXP (base, 0))]])
-    {
-      start = INTVAL (XEXP (base, 1));
-      base = qty_const[reg_qty[REGNO (XEXP (base, 0))]];
-    }
-  /* This can happen as the result of virtual register instantiation,
-     if the initial offset is too large to be a valid address.  */
-  else if (GET_CODE (base) == PLUS
-          && GET_CODE (XEXP (base, 0)) == REG
-          && GET_CODE (XEXP (base, 1)) == REG
-          && qty_const != 0
-          && REGNO_QTY_VALID_P (REGNO (XEXP (base, 0)))
-          && (qty_mode[reg_qty[REGNO (XEXP (base, 0))]]
-              == GET_MODE (XEXP (base, 0)))
-          && qty_const[reg_qty[REGNO (XEXP (base, 0))]]
-          && REGNO_QTY_VALID_P (REGNO (XEXP (base, 1)))
-          && (qty_mode[reg_qty[REGNO (XEXP (base, 1))]]
-              == GET_MODE (XEXP (base, 1)))
-          && qty_const[reg_qty[REGNO (XEXP (base, 1))]])
-    {
-      rtx tem = qty_const[reg_qty[REGNO (XEXP (base, 1))]];
-      base = qty_const[reg_qty[REGNO (XEXP (base, 0))]];
-
-      /* One of the two values must be a constant.  */
-      if (GET_CODE (base) != CONST_INT)
-       {
-         if (GET_CODE (tem) != CONST_INT)
-           abort ();
-         start = INTVAL (tem);
-       }
-      else
-       {
-         start = INTVAL (base);
-         base = tem;
-       }
-    }
-
-  /* Handle everything that we can find inside an address that has been
-     viewed as constant.  */
-
-  while (1)
+  if (GET_CODE (x) == REG
+      && REGNO_QTY_VALID_P (REGNO (x)))
     {
-      /* If no part of this switch does a "continue", the code outside
-        will exit this loop.  */
-
-      switch (GET_CODE (base))
-       {
-       case LO_SUM:
-         /* By definition, operand1 of a LO_SUM is the associated constant
-            address.  Use the associated constant address as the base
-            instead.  */
-         base = XEXP (base, 1);
-         continue;
-
-       case CONST:
-         /* Strip off CONST.  */
-         base = XEXP (base, 0);
-         continue;
-
-       case PLUS:
-         if (GET_CODE (XEXP (base, 1)) == CONST_INT)
-           {
-             start += INTVAL (XEXP (base, 1));
-             base = XEXP (base, 0);
-             continue;
-           }
-         break;
-
-       case AND:
-         /* Handle the case of an AND which is the negative of a power of
-            two.  This is used to represent unaligned memory operations.  */
-         if (GET_CODE (XEXP (base, 1)) == CONST_INT
-             && exact_log2 (- INTVAL (XEXP (base, 1))) > 0)
-           {
-             set_nonvarying_address_components (XEXP (base, 0), size,
-                                                pbase, pstart, pend);
-
-             /* Assume the worst misalignment.  START is affected, but not
-                END, so compensate but adjusting SIZE.  Don't lose any
-                constant we already had.  */
-
-             size = *pend - *pstart - INTVAL (XEXP (base, 1)) - 1;
-             start += *pstart + INTVAL (XEXP (base, 1)) + 1;
-             end += *pend;
-             base = *pbase;
-           }
-         break;
-
-       default:
-         break;
-       }
-
-      break;
-    }
+      int x_q = REG_QTY (REGNO (x));
+      struct qty_table_elem *x_ent = &qty_table[x_q];
 
-  if (GET_CODE (base) == CONST_INT)
-    {
-      start += INTVAL (base);
-      base = const0_rtx;
+      if (GET_MODE (x) == x_ent->mode
+         && x_ent->const_rtx != NULL_RTX)
+       return 0;
     }
 
-  end = start + size;
-
-  /* Set the return values.  */
-  *pbase = base;
-  *pstart = start;
-  *pend = end;
-}
-
-/* Return 1 if X has a value that can vary even between two
-   executions of the program.  0 means X can be compared reliably
-   against certain constants or near-constants.  */
-
-static int
-cse_rtx_varies_p (x)
-     register rtx x;
-{
-  /* We need not check for X and the equivalence class being of the same
-     mode because if X is equivalent to a constant in some mode, it
-     doesn't vary in any mode.  */
-
-  if (GET_CODE (x) == REG
-      && REGNO_QTY_VALID_P (REGNO (x))
-      && GET_MODE (x) == qty_mode[reg_qty[REGNO (x)]]
-      && qty_const[reg_qty[REGNO (x)]] != 0)
-    return 0;
-
   if (GET_CODE (x) == PLUS
       && GET_CODE (XEXP (x, 1)) == CONST_INT
       && GET_CODE (XEXP (x, 0)) == REG
-      && REGNO_QTY_VALID_P (REGNO (XEXP (x, 0)))
-      && (GET_MODE (XEXP (x, 0))
-         == qty_mode[reg_qty[REGNO (XEXP (x, 0))]])
-      && qty_const[reg_qty[REGNO (XEXP (x, 0))]])
-    return 0;
+      && REGNO_QTY_VALID_P (REGNO (XEXP (x, 0))))
+    {
+      int x0_q = REG_QTY (REGNO (XEXP (x, 0)));
+      struct qty_table_elem *x0_ent = &qty_table[x0_q];
+
+      if ((GET_MODE (XEXP (x, 0)) == x0_ent->mode)
+         && x0_ent->const_rtx != NULL_RTX)
+       return 0;
+    }
 
   /* This can happen as the result of virtual register instantiation, if
      the initial constant is too large to be a valid address.  This gives
@@ -2562,14 +2553,19 @@ cse_rtx_varies_p (x)
       && GET_CODE (XEXP (x, 0)) == REG
       && GET_CODE (XEXP (x, 1)) == REG
       && REGNO_QTY_VALID_P (REGNO (XEXP (x, 0)))
-      && (GET_MODE (XEXP (x, 0))
-         == qty_mode[reg_qty[REGNO (XEXP (x, 0))]])
-      && qty_const[reg_qty[REGNO (XEXP (x, 0))]]
-      && REGNO_QTY_VALID_P (REGNO (XEXP (x, 1)))
-      && (GET_MODE (XEXP (x, 1))
-         == qty_mode[reg_qty[REGNO (XEXP (x, 1))]])
-      && qty_const[reg_qty[REGNO (XEXP (x, 1))]])
-    return 0;
+      && REGNO_QTY_VALID_P (REGNO (XEXP (x, 1))))
+    {
+      int x0_q = REG_QTY (REGNO (XEXP (x, 0)));
+      int x1_q = REG_QTY (REGNO (XEXP (x, 1)));
+      struct qty_table_elem *x0_ent = &qty_table[x0_q];
+      struct qty_table_elem *x1_ent = &qty_table[x1_q];
+
+      if ((GET_MODE (XEXP (x, 0)) == x0_ent->mode)
+         && x0_ent->const_rtx != NULL_RTX
+         && (GET_MODE (XEXP (x, 1)) == x1_ent->mode)
+         && x1_ent->const_rtx != NULL_RTX)
+       return 0;
+    }
 
   return rtx_varies_p (x);
 }
@@ -2592,7 +2588,7 @@ canon_reg (x, insn)
 {
   register int i;
   register enum rtx_code code;
-  register char *fmt;
+  register const char *fmt;
 
   if (x == 0)
     return x;
@@ -2614,6 +2610,8 @@ canon_reg (x, insn)
     case REG:
       {
        register int first;
+       register int q;
+       register struct qty_table_elem *ent;
 
        /* Never replace a hard reg, because hard regs can appear
           in more than one machine mode, and we must preserve the mode
@@ -2624,10 +2622,12 @@ canon_reg (x, insn)
            || ! REGNO_QTY_VALID_P (REGNO (x)))
          return x;
 
-       first = qty_first_reg[reg_qty[REGNO (x)]];
+       q = REG_QTY (REGNO(x));
+       ent = &qty_table[q];
+       first = ent->first_reg;
        return (first >= FIRST_PSEUDO_REGISTER ? regno_reg_rtx[first]
                : REGNO_REG_CLASS (first) == NO_REGS ? x
-               : gen_rtx_REG (qty_mode[reg_qty[REGNO (x)]], first));
+               : gen_rtx_REG (ent->mode, first));
       }
       
     default:
@@ -2651,7 +2651,7 @@ canon_reg (x, insn)
              && (((REGNO (new) < FIRST_PSEUDO_REGISTER)
                   != (REGNO (XEXP (x, i)) < FIRST_PSEUDO_REGISTER))
                  || (insn_code = recog_memoized (insn)) < 0
-                 || insn_n_dups[insn_code] > 0))
+                 || insn_data[insn_code].n_dups > 0))
            validate_change (insn, &XEXP (x, i), new, 1);
          else
            XEXP (x, i) = new;
@@ -2693,7 +2693,6 @@ find_best_addr (insn, loc)
 #endif
   int save_do_not_record = do_not_record;
   int save_hash_arg_in_memory = hash_arg_in_memory;
-  int save_hash_arg_in_struct = hash_arg_in_struct;
   int addr_volatile;
   int regno;
   unsigned hash;
@@ -2749,7 +2748,6 @@ find_best_addr (insn, loc)
   addr_volatile = do_not_record;
   do_not_record = save_do_not_record;
   hash_arg_in_memory = save_hash_arg_in_memory;
-  hash_arg_in_struct = save_hash_arg_in_struct;
 
   if (addr_volatile)
     return;
@@ -2838,7 +2836,6 @@ find_best_addr (insn, loc)
       hash = HASH (XEXP (*loc, 0), Pmode);
       do_not_record = save_do_not_record;
       hash_arg_in_memory = save_hash_arg_in_memory;
-      hash_arg_in_struct = save_hash_arg_in_struct;
 
       elt = lookup (XEXP (*loc, 0), hash, Pmode);
       if (elt == 0)
@@ -2863,7 +2860,8 @@ find_best_addr (insn, loc)
          /* This is at worst case an O(n^2) algorithm, so limit our search
             to the first 32 elements on the list.  This avoids trouble
             compiling code with very long basic blocks that can easily
-            call cse_gen_binary so many times that we run out of memory.  */
+            call simplify_gen_binary so many times that we run out of
+            memory.  */
 
          found_better = 0;
          for (p = elt->first_same_value, count = 0;
@@ -2873,7 +2871,8 @@ find_best_addr (insn, loc)
                && (GET_CODE (p->exp) == REG
                    || exp_equiv_p (p->exp, p->exp, 1, 0)))
              {
-               rtx new = cse_gen_binary (GET_CODE (*loc), Pmode, p->exp, c);
+               rtx new = simplify_gen_binary (GET_CODE (*loc), Pmode,
+                                              p->exp, c);
 
                if ((CSE_ADDRESS_COST (new) < best_addr_cost
                    || (CSE_ADDRESS_COST (new) == best_addr_cost
@@ -2949,1938 +2948,123 @@ find_comparison_args (code, parg1, parg2, pmode1, pmode2)
              || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT
                  && code == LT && STORE_FLAG_VALUE == -1)
 #ifdef FLOAT_STORE_FLAG_VALUE
-             || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT
-                 && FLOAT_STORE_FLAG_VALUE < 0)
-#endif
-             )
-           x = arg1;
-         else if (code == EQ
-                  || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT
-                      && code == GE && STORE_FLAG_VALUE == -1)
-#ifdef FLOAT_STORE_FLAG_VALUE
-                  || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT
-                      && FLOAT_STORE_FLAG_VALUE < 0)
-#endif
-                  )
-           x = arg1, reverse_code = 1;
-       }
-
-      /* ??? We could also check for
-
-        (ne (and (eq (...) (const_int 1))) (const_int 0))
-
-        and related forms, but let's wait until we see them occurring.  */
-
-      if (x == 0)
-       /* Look up ARG1 in the hash table and see if it has an equivalence
-          that lets us see what is being compared.  */
-       p = lookup (arg1, safe_hash (arg1, GET_MODE (arg1)) % NBUCKETS,
-                   GET_MODE (arg1));
-      if (p) p = p->first_same_value;
-
-      for (; p; p = p->next_same_value)
-       {
-         enum machine_mode inner_mode = GET_MODE (p->exp);
-
-         /* If the entry isn't valid, skip it.  */
-         if (! exp_equiv_p (p->exp, p->exp, 1, 0))
-           continue;
-
-         if (GET_CODE (p->exp) == COMPARE
-             /* Another possibility is that this machine has a compare insn
-                that includes the comparison code.  In that case, ARG1 would
-                be equivalent to a comparison operation that would set ARG1 to
-                either STORE_FLAG_VALUE or zero.  If this is an NE operation,
-                ORIG_CODE is the actual comparison being done; if it is an EQ,
-                we must reverse ORIG_CODE.  On machine with a negative value
-                for STORE_FLAG_VALUE, also look at LT and GE operations.  */
-             || ((code == NE
-                  || (code == LT
-                      && GET_MODE_CLASS (inner_mode) == MODE_INT
-                      && (GET_MODE_BITSIZE (inner_mode)
-                          <= HOST_BITS_PER_WIDE_INT)
-                      && (STORE_FLAG_VALUE
-                          & ((HOST_WIDE_INT) 1
-                             << (GET_MODE_BITSIZE (inner_mode) - 1))))
-#ifdef FLOAT_STORE_FLAG_VALUE
-                  || (code == LT
-                      && GET_MODE_CLASS (inner_mode) == MODE_FLOAT
-                      && FLOAT_STORE_FLAG_VALUE < 0)
-#endif
-                  )
-                 && GET_RTX_CLASS (GET_CODE (p->exp)) == '<'))
-           {
-             x = p->exp;
-             break;
-           }
-         else if ((code == EQ
-                   || (code == GE
-                       && GET_MODE_CLASS (inner_mode) == MODE_INT
-                       && (GET_MODE_BITSIZE (inner_mode)
-                           <= HOST_BITS_PER_WIDE_INT)
-                       && (STORE_FLAG_VALUE
-                           & ((HOST_WIDE_INT) 1
-                              << (GET_MODE_BITSIZE (inner_mode) - 1))))
-#ifdef FLOAT_STORE_FLAG_VALUE
-                   || (code == GE
-                       && GET_MODE_CLASS (inner_mode) == MODE_FLOAT
-                       && FLOAT_STORE_FLAG_VALUE < 0)
-#endif
-                   )
-                  && GET_RTX_CLASS (GET_CODE (p->exp)) == '<')
-           {
-             reverse_code = 1;
-             x = p->exp;
-             break;
-           }
-
-         /* If this is fp + constant, the equivalent is a better operand since
-            it may let us predict the value of the comparison.  */
-         else if (NONZERO_BASE_PLUS_P (p->exp))
-           {
-             arg1 = p->exp;
-             continue;
-           }
-       }
-
-      /* If we didn't find a useful equivalence for ARG1, we are done.
-        Otherwise, set up for the next iteration.  */
-      if (x == 0)
-       break;
-
-      arg1 = XEXP (x, 0),  arg2 = XEXP (x, 1);
-      if (GET_RTX_CLASS (GET_CODE (x)) == '<')
-       code = GET_CODE (x);
-
-      if (reverse_code)
-       code = reverse_condition (code);
-    }
-
-  /* Return our results.  Return the modes from before fold_rtx
-     because fold_rtx might produce const_int, and then it's too late.  */
-  *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2);
-  *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0);
-
-  return code;
-}
-\f
-/* Try to simplify a unary operation CODE whose output mode is to be
-   MODE with input operand OP whose mode was originally OP_MODE.
-   Return zero if no simplification can be made.  */
-
-rtx
-simplify_unary_operation (code, mode, op, op_mode)
-     enum rtx_code code;
-     enum machine_mode mode;
-     rtx op;
-     enum machine_mode op_mode;
-{
-  register int width = GET_MODE_BITSIZE (mode);
-
-  /* The order of these tests is critical so that, for example, we don't
-     check the wrong mode (input vs. output) for a conversion operation,
-     such as FIX.  At some point, this should be simplified.  */
-
-#if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
-
-  if (code == FLOAT && GET_MODE (op) == VOIDmode
-      && (GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT))
-    {
-      HOST_WIDE_INT hv, lv;
-      REAL_VALUE_TYPE d;
-
-      if (GET_CODE (op) == CONST_INT)
-       lv = INTVAL (op), hv = INTVAL (op) < 0 ? -1 : 0;
-      else
-       lv = CONST_DOUBLE_LOW (op),  hv = CONST_DOUBLE_HIGH (op);
-
-#ifdef REAL_ARITHMETIC
-      REAL_VALUE_FROM_INT (d, lv, hv, mode);
-#else
-      if (hv < 0)
-       {
-         d = (double) (~ hv);
-         d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
-               * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
-         d += (double) (unsigned HOST_WIDE_INT) (~ lv);
-         d = (- d - 1.0);
-       }
-      else
-       {
-         d = (double) hv;
-         d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
-               * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
-         d += (double) (unsigned HOST_WIDE_INT) lv;
-       }
-#endif  /* REAL_ARITHMETIC */
-      d = real_value_truncate (mode, d);
-      return CONST_DOUBLE_FROM_REAL_VALUE (d, mode);
-    }
-  else if (code == UNSIGNED_FLOAT && GET_MODE (op) == VOIDmode
-          && (GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT))
-    {
-      HOST_WIDE_INT hv, lv;
-      REAL_VALUE_TYPE d;
-
-      if (GET_CODE (op) == CONST_INT)
-       lv = INTVAL (op), hv = INTVAL (op) < 0 ? -1 : 0;
-      else
-       lv = CONST_DOUBLE_LOW (op),  hv = CONST_DOUBLE_HIGH (op);
-
-      if (op_mode == VOIDmode)
-       {
-         /* We don't know how to interpret negative-looking numbers in
-            this case, so don't try to fold those.  */
-         if (hv < 0)
-           return 0;
-       }
-      else if (GET_MODE_BITSIZE (op_mode) >= HOST_BITS_PER_WIDE_INT * 2)
-       ;
-      else
-       hv = 0, lv &= GET_MODE_MASK (op_mode);
-
-#ifdef REAL_ARITHMETIC
-      REAL_VALUE_FROM_UNSIGNED_INT (d, lv, hv, mode);
-#else
-
-      d = (double) (unsigned HOST_WIDE_INT) hv;
-      d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
-           * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
-      d += (double) (unsigned HOST_WIDE_INT) lv;
-#endif  /* REAL_ARITHMETIC */
-      d = real_value_truncate (mode, d);
-      return CONST_DOUBLE_FROM_REAL_VALUE (d, mode);
-    }
-#endif
-
-  if (GET_CODE (op) == CONST_INT
-      && width <= HOST_BITS_PER_WIDE_INT && width > 0)
-    {
-      register HOST_WIDE_INT arg0 = INTVAL (op);
-      register HOST_WIDE_INT val;
-
-      switch (code)
-       {
-       case NOT:
-         val = ~ arg0;
-         break;
-
-       case NEG:
-         val = - arg0;
-         break;
-
-       case ABS:
-         val = (arg0 >= 0 ? arg0 : - arg0);
-         break;
-
-       case FFS:
-         /* Don't use ffs here.  Instead, get low order bit and then its
-            number.  If arg0 is zero, this will return 0, as desired.  */
-         arg0 &= GET_MODE_MASK (mode);
-         val = exact_log2 (arg0 & (- arg0)) + 1;
-         break;
-
-       case TRUNCATE:
-         val = arg0;
-         break;
-
-       case ZERO_EXTEND:
-         if (op_mode == VOIDmode)
-           op_mode = mode;
-         if (GET_MODE_BITSIZE (op_mode) == HOST_BITS_PER_WIDE_INT)
-           {
-             /* If we were really extending the mode,
-                we would have to distinguish between zero-extension
-                and sign-extension.  */
-             if (width != GET_MODE_BITSIZE (op_mode))
-               abort ();
-             val = arg0;
-           }
-         else if (GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT)
-           val = arg0 & ~((HOST_WIDE_INT) (-1) << GET_MODE_BITSIZE (op_mode));
-         else
-           return 0;
-         break;
-
-       case SIGN_EXTEND:
-         if (op_mode == VOIDmode)
-           op_mode = mode;
-         if (GET_MODE_BITSIZE (op_mode) == HOST_BITS_PER_WIDE_INT)
-           {
-             /* If we were really extending the mode,
-                we would have to distinguish between zero-extension
-                and sign-extension.  */
-             if (width != GET_MODE_BITSIZE (op_mode))
-               abort ();
-             val = arg0;
-           }
-         else if (GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT)
-           {
-             val
-               = arg0 & ~((HOST_WIDE_INT) (-1) << GET_MODE_BITSIZE (op_mode));
-             if (val
-                 & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (op_mode) - 1)))
-               val -= (HOST_WIDE_INT) 1 << GET_MODE_BITSIZE (op_mode);
-           }
-         else
-           return 0;
-         break;
-
-       case SQRT:
-         return 0;
-
-       default:
-         abort ();
-       }
-
-      /* Clear the bits that don't belong in our mode,
-        unless they and our sign bit are all one.
-        So we get either a reasonable negative value or a reasonable
-        unsigned value for this mode.  */
-      if (width < HOST_BITS_PER_WIDE_INT
-         && ((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
-             != ((HOST_WIDE_INT) (-1) << (width - 1))))
-       val &= ((HOST_WIDE_INT) 1 << width) - 1;
-
-      /* If this would be an entire word for the target, but is not for
-        the host, then sign-extend on the host so that the number will look
-        the same way on the host that it would on the target.
-
-        For example, when building a 64 bit alpha hosted 32 bit sparc
-        targeted compiler, then we want the 32 bit unsigned value -1 to be
-        represented as a 64 bit value -1, and not as 0x00000000ffffffff.
-        The later confuses the sparc backend.  */
-
-      if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
-         && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
-       val |= ((HOST_WIDE_INT) (-1) << width);
-
-      return GEN_INT (val);
-    }
-
-  /* We can do some operations on integer CONST_DOUBLEs.  Also allow
-     for a DImode operation on a CONST_INT.  */
-  else if (GET_MODE (op) == VOIDmode && width <= HOST_BITS_PER_INT * 2
-          && (GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT))
-    {
-      HOST_WIDE_INT l1, h1, lv, hv;
-
-      if (GET_CODE (op) == CONST_DOUBLE)
-       l1 = CONST_DOUBLE_LOW (op), h1 = CONST_DOUBLE_HIGH (op);
-      else
-       l1 = INTVAL (op), h1 = l1 < 0 ? -1 : 0;
-
-      switch (code)
-       {
-       case NOT:
-         lv = ~ l1;
-         hv = ~ h1;
-         break;
-
-       case NEG:
-         neg_double (l1, h1, &lv, &hv);
-         break;
-
-       case ABS:
-         if (h1 < 0)
-           neg_double (l1, h1, &lv, &hv);
-         else
-           lv = l1, hv = h1;
-         break;
-
-       case FFS:
-         hv = 0;
-         if (l1 == 0)
-           lv = HOST_BITS_PER_WIDE_INT + exact_log2 (h1 & (-h1)) + 1;
-         else
-           lv = exact_log2 (l1 & (-l1)) + 1;
-         break;
-
-       case TRUNCATE:
-         /* This is just a change-of-mode, so do nothing.  */
-         lv = l1, hv = h1;
-         break;
-
-       case ZERO_EXTEND:
-         if (op_mode == VOIDmode
-             || GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT)
-           return 0;
-
-         hv = 0;
-         lv = l1 & GET_MODE_MASK (op_mode);
-         break;
-
-       case SIGN_EXTEND:
-         if (op_mode == VOIDmode
-             || GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT)
-           return 0;
-         else
-           {
-             lv = l1 & GET_MODE_MASK (op_mode);
-             if (GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
-                 && (lv & ((HOST_WIDE_INT) 1
-                           << (GET_MODE_BITSIZE (op_mode) - 1))) != 0)
-               lv -= (HOST_WIDE_INT) 1 << GET_MODE_BITSIZE (op_mode);
-
-             hv = (lv < 0) ? ~ (HOST_WIDE_INT) 0 : 0;
-           }
-         break;
-
-       case SQRT:
-         return 0;
-
-       default:
-         return 0;
-       }
-
-      return immed_double_const (lv, hv, mode);
-    }
-
-#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
-  else if (GET_CODE (op) == CONST_DOUBLE
-          && GET_MODE_CLASS (mode) == MODE_FLOAT)
-    {
-      REAL_VALUE_TYPE d;
-      jmp_buf handler;
-      rtx x;
-
-      if (setjmp (handler))
-       /* There used to be a warning here, but that is inadvisable.
-          People may want to cause traps, and the natural way
-          to do it should not get a warning.  */
-       return 0;
-
-      set_float_handler (handler);
-
-      REAL_VALUE_FROM_CONST_DOUBLE (d, op);
-
-      switch (code)
-       {
-       case NEG:
-         d = REAL_VALUE_NEGATE (d);
-         break;
-
-       case ABS:
-         if (REAL_VALUE_NEGATIVE (d))
-           d = REAL_VALUE_NEGATE (d);
-         break;
-
-       case FLOAT_TRUNCATE:
-         d = real_value_truncate (mode, d);
-         break;
-
-       case FLOAT_EXTEND:
-         /* All this does is change the mode.  */
-         break;
-
-       case FIX:
-         d = REAL_VALUE_RNDZINT (d);
-         break;
-
-       case UNSIGNED_FIX:
-         d = REAL_VALUE_UNSIGNED_RNDZINT (d);
-         break;
-
-       case SQRT:
-         return 0;
-
-       default:
-         abort ();
-       }
-
-      x = CONST_DOUBLE_FROM_REAL_VALUE (d, mode);
-      set_float_handler (NULL_PTR);
-      return x;
-    }
-
-  else if (GET_CODE (op) == CONST_DOUBLE
-          && GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT
-          && GET_MODE_CLASS (mode) == MODE_INT
-          && width <= HOST_BITS_PER_WIDE_INT && width > 0)
-    {
-      REAL_VALUE_TYPE d;
-      jmp_buf handler;
-      HOST_WIDE_INT val;
-
-      if (setjmp (handler))
-       return 0;
-
-      set_float_handler (handler);
-
-      REAL_VALUE_FROM_CONST_DOUBLE (d, op);
-
-      switch (code)
-       {
-       case FIX:
-         val = REAL_VALUE_FIX (d);
-         break;
-
-       case UNSIGNED_FIX:
-         val = REAL_VALUE_UNSIGNED_FIX (d);
-         break;
-
-       default:
-         abort ();
-       }
-
-      set_float_handler (NULL_PTR);
-
-      /* Clear the bits that don't belong in our mode,
-        unless they and our sign bit are all one.
-        So we get either a reasonable negative value or a reasonable
-        unsigned value for this mode.  */
-      if (width < HOST_BITS_PER_WIDE_INT
-         && ((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
-             != ((HOST_WIDE_INT) (-1) << (width - 1))))
-       val &= ((HOST_WIDE_INT) 1 << width) - 1;
-
-      /* If this would be an entire word for the target, but is not for
-        the host, then sign-extend on the host so that the number will look
-        the same way on the host that it would on the target.
-
-        For example, when building a 64 bit alpha hosted 32 bit sparc
-        targeted compiler, then we want the 32 bit unsigned value -1 to be
-        represented as a 64 bit value -1, and not as 0x00000000ffffffff.
-        The later confuses the sparc backend.  */
-
-      if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
-         && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
-       val |= ((HOST_WIDE_INT) (-1) << width);
-
-      return GEN_INT (val);
-    }
-#endif
-  /* This was formerly used only for non-IEEE float.
-     eggert@twinsun.com says it is safe for IEEE also.  */
-  else
-    {
-      /* There are some simplifications we can do even if the operands
-        aren't constant.  */
-      switch (code)
-       {
-       case NEG:
-       case NOT:
-         /* (not (not X)) == X, similarly for NEG.  */
-         if (GET_CODE (op) == code)
-           return XEXP (op, 0);
-         break;
-
-       case SIGN_EXTEND:
-         /* (sign_extend (truncate (minus (label_ref L1) (label_ref L2))))
-            becomes just the MINUS if its mode is MODE.  This allows
-            folding switch statements on machines using casesi (such as
-            the Vax).  */
-         if (GET_CODE (op) == TRUNCATE
-             && GET_MODE (XEXP (op, 0)) == mode
-             && GET_CODE (XEXP (op, 0)) == MINUS
-             && GET_CODE (XEXP (XEXP (op, 0), 0)) == LABEL_REF
-             && GET_CODE (XEXP (XEXP (op, 0), 1)) == LABEL_REF)
-           return XEXP (op, 0);
-
-#ifdef POINTERS_EXTEND_UNSIGNED
-         if (! POINTERS_EXTEND_UNSIGNED
-             && mode == Pmode && GET_MODE (op) == ptr_mode
-             && CONSTANT_P (op))
-           return convert_memory_address (Pmode, op);
-#endif
-         break;
-
-#ifdef POINTERS_EXTEND_UNSIGNED
-       case ZERO_EXTEND:
-         if (POINTERS_EXTEND_UNSIGNED
-             && mode == Pmode && GET_MODE (op) == ptr_mode
-             && CONSTANT_P (op))
-           return convert_memory_address (Pmode, op);
-         break;
-#endif
-         
-       default:
-         break;
-       }
-
-      return 0;
-    }
-}
-\f
-/* Simplify a binary operation CODE with result mode MODE, operating on OP0
-   and OP1.  Return 0 if no simplification is possible.
-
-   Don't use this for relational operations such as EQ or LT.
-   Use simplify_relational_operation instead.  */
-
-rtx
-simplify_binary_operation (code, mode, op0, op1)
-     enum rtx_code code;
-     enum machine_mode mode;
-     rtx op0, op1;
-{
-  register HOST_WIDE_INT arg0, arg1, arg0s, arg1s;
-  HOST_WIDE_INT val;
-  int width = GET_MODE_BITSIZE (mode);
-  rtx tem;
-
-  /* Relational operations don't work here.  We must know the mode
-     of the operands in order to do the comparison correctly.
-     Assuming a full word can give incorrect results.
-     Consider comparing 128 with -128 in QImode.  */
-
-  if (GET_RTX_CLASS (code) == '<')
-    abort ();
-
-#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
-  if (GET_MODE_CLASS (mode) == MODE_FLOAT
-      && GET_CODE (op0) == CONST_DOUBLE && GET_CODE (op1) == CONST_DOUBLE
-      && mode == GET_MODE (op0) && mode == GET_MODE (op1))
-    {
-      REAL_VALUE_TYPE f0, f1, value;
-      jmp_buf handler;
-
-      if (setjmp (handler))
-       return 0;
-
-      set_float_handler (handler);
-
-      REAL_VALUE_FROM_CONST_DOUBLE (f0, op0);
-      REAL_VALUE_FROM_CONST_DOUBLE (f1, op1);
-      f0 = real_value_truncate (mode, f0);
-      f1 = real_value_truncate (mode, f1);
-
-#ifdef REAL_ARITHMETIC
-#ifndef REAL_INFINITY
-      if (code == DIV && REAL_VALUES_EQUAL (f1, dconst0))
-       return 0;
-#endif
-      REAL_ARITHMETIC (value, rtx_to_tree_code (code), f0, f1);
-#else
-      switch (code)
-       {
-       case PLUS:
-         value = f0 + f1;
-         break;
-       case MINUS:
-         value = f0 - f1;
-         break;
-       case MULT:
-         value = f0 * f1;
-         break;
-       case DIV:
-#ifndef REAL_INFINITY
-         if (f1 == 0)
-           return 0;
-#endif
-         value = f0 / f1;
-         break;
-       case SMIN:
-         value = MIN (f0, f1);
-         break;
-       case SMAX:
-         value = MAX (f0, f1);
-         break;
-       default:
-         abort ();
-       }
-#endif
-
-      value = real_value_truncate (mode, value);
-      set_float_handler (NULL_PTR);
-      return CONST_DOUBLE_FROM_REAL_VALUE (value, mode);
-    }
-#endif  /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
-
-  /* We can fold some multi-word operations.  */
-  if (GET_MODE_CLASS (mode) == MODE_INT
-      && width == HOST_BITS_PER_WIDE_INT * 2
-      && (GET_CODE (op0) == CONST_DOUBLE || GET_CODE (op0) == CONST_INT)
-      && (GET_CODE (op1) == CONST_DOUBLE || GET_CODE (op1) == CONST_INT))
-    {
-      HOST_WIDE_INT l1, l2, h1, h2, lv, hv;
-
-      if (GET_CODE (op0) == CONST_DOUBLE)
-       l1 = CONST_DOUBLE_LOW (op0), h1 = CONST_DOUBLE_HIGH (op0);
-      else
-       l1 = INTVAL (op0), h1 = l1 < 0 ? -1 : 0;
-
-      if (GET_CODE (op1) == CONST_DOUBLE)
-       l2 = CONST_DOUBLE_LOW (op1), h2 = CONST_DOUBLE_HIGH (op1);
-      else
-       l2 = INTVAL (op1), h2 = l2 < 0 ? -1 : 0;
-
-      switch (code)
-       {
-       case MINUS:
-         /* A - B == A + (-B).  */
-         neg_double (l2, h2, &lv, &hv);
-         l2 = lv, h2 = hv;
-
-         /* .. fall through ...  */
-
-       case PLUS:
-         add_double (l1, h1, l2, h2, &lv, &hv);
-         break;
-
-       case MULT:
-         mul_double (l1, h1, l2, h2, &lv, &hv);
-         break;
-
-       case DIV:  case MOD:   case UDIV:  case UMOD:
-         /* We'd need to include tree.h to do this and it doesn't seem worth
-            it.  */
-         return 0;
-
-       case AND:
-         lv = l1 & l2, hv = h1 & h2;
-         break;
-
-       case IOR:
-         lv = l1 | l2, hv = h1 | h2;
-         break;
-
-       case XOR:
-         lv = l1 ^ l2, hv = h1 ^ h2;
-         break;
-
-       case SMIN:
-         if (h1 < h2
-             || (h1 == h2
-                 && ((unsigned HOST_WIDE_INT) l1
-                     < (unsigned HOST_WIDE_INT) l2)))
-           lv = l1, hv = h1;
-         else
-           lv = l2, hv = h2;
-         break;
-
-       case SMAX:
-         if (h1 > h2
-             || (h1 == h2
-                 && ((unsigned HOST_WIDE_INT) l1
-                     > (unsigned HOST_WIDE_INT) l2)))
-           lv = l1, hv = h1;
-         else
-           lv = l2, hv = h2;
-         break;
-
-       case UMIN:
-         if ((unsigned HOST_WIDE_INT) h1 < (unsigned HOST_WIDE_INT) h2
-             || (h1 == h2
-                 && ((unsigned HOST_WIDE_INT) l1
-                     < (unsigned HOST_WIDE_INT) l2)))
-           lv = l1, hv = h1;
-         else
-           lv = l2, hv = h2;
-         break;
-
-       case UMAX:
-         if ((unsigned HOST_WIDE_INT) h1 > (unsigned HOST_WIDE_INT) h2
-             || (h1 == h2
-                 && ((unsigned HOST_WIDE_INT) l1
-                     > (unsigned HOST_WIDE_INT) l2)))
-           lv = l1, hv = h1;
-         else
-           lv = l2, hv = h2;
-         break;
-
-       case LSHIFTRT:   case ASHIFTRT:
-       case ASHIFT:
-       case ROTATE:     case ROTATERT:
-#ifdef SHIFT_COUNT_TRUNCATED
-         if (SHIFT_COUNT_TRUNCATED)
-           l2 &= (GET_MODE_BITSIZE (mode) - 1), h2 = 0;
-#endif
-
-         if (h2 != 0 || l2 < 0 || l2 >= GET_MODE_BITSIZE (mode))
-           return 0;
-
-         if (code == LSHIFTRT || code == ASHIFTRT)
-           rshift_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv,
-                          code == ASHIFTRT);
-         else if (code == ASHIFT)
-           lshift_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv, 1);
-         else if (code == ROTATE)
-           lrotate_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv);
-         else /* code == ROTATERT */
-           rrotate_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv);
-         break;
-
-       default:
-         return 0;
-       }
-
-      return immed_double_const (lv, hv, mode);
-    }
-
-  if (GET_CODE (op0) != CONST_INT || GET_CODE (op1) != CONST_INT
-      || width > HOST_BITS_PER_WIDE_INT || width == 0)
-    {
-      /* Even if we can't compute a constant result,
-        there are some cases worth simplifying.  */
-
-      switch (code)
-       {
-       case PLUS:
-         /* In IEEE floating point, x+0 is not the same as x.  Similarly
-            for the other optimizations below.  */
-         if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
-             && FLOAT_MODE_P (mode) && ! flag_fast_math)
-           break;
-
-         if (op1 == CONST0_RTX (mode))
-           return op0;
-
-         /* ((-a) + b) -> (b - a) and similarly for (a + (-b)) */
-         if (GET_CODE (op0) == NEG)
-           return cse_gen_binary (MINUS, mode, op1, XEXP (op0, 0));
-         else if (GET_CODE (op1) == NEG)
-           return cse_gen_binary (MINUS, mode, op0, XEXP (op1, 0));
-
-         /* Handle both-operands-constant cases.  We can only add
-            CONST_INTs to constants since the sum of relocatable symbols
-            can't be handled by most assemblers.  Don't add CONST_INT
-            to CONST_INT since overflow won't be computed properly if wider
-            than HOST_BITS_PER_WIDE_INT.  */
-
-         if (CONSTANT_P (op0) && GET_MODE (op0) != VOIDmode
-             && GET_CODE (op1) == CONST_INT)
-           return plus_constant (op0, INTVAL (op1));
-         else if (CONSTANT_P (op1) && GET_MODE (op1) != VOIDmode
-                  && GET_CODE (op0) == CONST_INT)
-           return plus_constant (op1, INTVAL (op0));
-
-         /* See if this is something like X * C - X or vice versa or
-            if the multiplication is written as a shift.  If so, we can
-            distribute and make a new multiply, shift, or maybe just
-            have X (if C is 2 in the example above).  But don't make
-            real multiply if we didn't have one before.  */
-
-         if (! FLOAT_MODE_P (mode))
-           {
-             HOST_WIDE_INT coeff0 = 1, coeff1 = 1;
-             rtx lhs = op0, rhs = op1;
-             int had_mult = 0;
-
-             if (GET_CODE (lhs) == NEG)
-               coeff0 = -1, lhs = XEXP (lhs, 0);
-             else if (GET_CODE (lhs) == MULT
-                      && GET_CODE (XEXP (lhs, 1)) == CONST_INT)
-               {
-                 coeff0 = INTVAL (XEXP (lhs, 1)), lhs = XEXP (lhs, 0);
-                 had_mult = 1;
-               }
-             else if (GET_CODE (lhs) == ASHIFT
-                      && GET_CODE (XEXP (lhs, 1)) == CONST_INT
-                      && INTVAL (XEXP (lhs, 1)) >= 0
-                      && INTVAL (XEXP (lhs, 1)) < HOST_BITS_PER_WIDE_INT)
-               {
-                 coeff0 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (lhs, 1));
-                 lhs = XEXP (lhs, 0);
-               }
-
-             if (GET_CODE (rhs) == NEG)
-               coeff1 = -1, rhs = XEXP (rhs, 0);
-             else if (GET_CODE (rhs) == MULT
-                      && GET_CODE (XEXP (rhs, 1)) == CONST_INT)
-               {
-                 coeff1 = INTVAL (XEXP (rhs, 1)), rhs = XEXP (rhs, 0);
-                 had_mult = 1;
-               }
-             else if (GET_CODE (rhs) == ASHIFT
-                      && GET_CODE (XEXP (rhs, 1)) == CONST_INT
-                      && INTVAL (XEXP (rhs, 1)) >= 0
-                      && INTVAL (XEXP (rhs, 1)) < HOST_BITS_PER_WIDE_INT)
-               {
-                 coeff1 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (rhs, 1));
-                 rhs = XEXP (rhs, 0);
-               }
-
-             if (rtx_equal_p (lhs, rhs))
-               {
-                 tem = cse_gen_binary (MULT, mode, lhs,
-                                       GEN_INT (coeff0 + coeff1));
-                 return (GET_CODE (tem) == MULT && ! had_mult) ? 0 : tem;
-               }
-           }
-
-         /* If one of the operands is a PLUS or a MINUS, see if we can
-            simplify this by the associative law. 
-            Don't use the associative law for floating point.
-            The inaccuracy makes it nonassociative,
-            and subtle programs can break if operations are associated.  */
-
-         if (INTEGRAL_MODE_P (mode)
-             && (GET_CODE (op0) == PLUS || GET_CODE (op0) == MINUS
-                 || GET_CODE (op1) == PLUS || GET_CODE (op1) == MINUS)
-             && (tem = simplify_plus_minus (code, mode, op0, op1)) != 0)
-           return tem;
-         break;
-
-       case COMPARE:
-#ifdef HAVE_cc0
-         /* Convert (compare FOO (const_int 0)) to FOO unless we aren't
-            using cc0, in which case we want to leave it as a COMPARE
-            so we can distinguish it from a register-register-copy.
-
-            In IEEE floating point, x-0 is not the same as x.  */
-
-         if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
-              || ! FLOAT_MODE_P (mode) || flag_fast_math)
-             && op1 == CONST0_RTX (mode))
-           return op0;
-#else
-         /* Do nothing here.  */
-#endif
-         break;
-             
-       case MINUS:
-         /* None of these optimizations can be done for IEEE
-            floating point.  */
-         if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
-             && FLOAT_MODE_P (mode) && ! flag_fast_math)
-           break;
-
-         /* We can't assume x-x is 0 even with non-IEEE floating point,
-            but since it is zero except in very strange circumstances, we
-            will treat it as zero with -ffast-math.  */
-         if (rtx_equal_p (op0, op1)
-             && ! side_effects_p (op0)
-             && (! FLOAT_MODE_P (mode) || flag_fast_math))
-           return CONST0_RTX (mode);
-
-         /* Change subtraction from zero into negation.  */
-         if (op0 == CONST0_RTX (mode))
-           return gen_rtx_NEG (mode, op1);
-
-         /* (-1 - a) is ~a.  */
-         if (op0 == constm1_rtx)
-           return gen_rtx_NOT (mode, op1);
-
-         /* Subtracting 0 has no effect.  */
-         if (op1 == CONST0_RTX (mode))
-           return op0;
-
-         /* See if this is something like X * C - X or vice versa or
-            if the multiplication is written as a shift.  If so, we can
-            distribute and make a new multiply, shift, or maybe just
-            have X (if C is 2 in the example above).  But don't make
-            real multiply if we didn't have one before.  */
-
-         if (! FLOAT_MODE_P (mode))
-           {
-             HOST_WIDE_INT coeff0 = 1, coeff1 = 1;
-             rtx lhs = op0, rhs = op1;
-             int had_mult = 0;
-
-             if (GET_CODE (lhs) == NEG)
-               coeff0 = -1, lhs = XEXP (lhs, 0);
-             else if (GET_CODE (lhs) == MULT
-                      && GET_CODE (XEXP (lhs, 1)) == CONST_INT)
-               {
-                 coeff0 = INTVAL (XEXP (lhs, 1)), lhs = XEXP (lhs, 0);
-                 had_mult = 1;
-               }
-             else if (GET_CODE (lhs) == ASHIFT
-                      && GET_CODE (XEXP (lhs, 1)) == CONST_INT
-                      && INTVAL (XEXP (lhs, 1)) >= 0
-                      && INTVAL (XEXP (lhs, 1)) < HOST_BITS_PER_WIDE_INT)
-               {
-                 coeff0 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (lhs, 1));
-                 lhs = XEXP (lhs, 0);
-               }
-
-             if (GET_CODE (rhs) == NEG)
-               coeff1 = - 1, rhs = XEXP (rhs, 0);
-             else if (GET_CODE (rhs) == MULT
-                      && GET_CODE (XEXP (rhs, 1)) == CONST_INT)
-               {
-                 coeff1 = INTVAL (XEXP (rhs, 1)), rhs = XEXP (rhs, 0);
-                 had_mult = 1;
-               }
-             else if (GET_CODE (rhs) == ASHIFT
-                      && GET_CODE (XEXP (rhs, 1)) == CONST_INT
-                      && INTVAL (XEXP (rhs, 1)) >= 0
-                      && INTVAL (XEXP (rhs, 1)) < HOST_BITS_PER_WIDE_INT)
-               {
-                 coeff1 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (rhs, 1));
-                 rhs = XEXP (rhs, 0);
-               }
-
-             if (rtx_equal_p (lhs, rhs))
-               {
-                 tem = cse_gen_binary (MULT, mode, lhs,
-                                       GEN_INT (coeff0 - coeff1));
-                 return (GET_CODE (tem) == MULT && ! had_mult) ? 0 : tem;
-               }
-           }
-
-         /* (a - (-b)) -> (a + b).  */
-         if (GET_CODE (op1) == NEG)
-           return cse_gen_binary (PLUS, mode, op0, XEXP (op1, 0));
-
-         /* If one of the operands is a PLUS or a MINUS, see if we can
-            simplify this by the associative law. 
-            Don't use the associative law for floating point.
-            The inaccuracy makes it nonassociative,
-            and subtle programs can break if operations are associated.  */
-
-         if (INTEGRAL_MODE_P (mode)
-             && (GET_CODE (op0) == PLUS || GET_CODE (op0) == MINUS
-                 || GET_CODE (op1) == PLUS || GET_CODE (op1) == MINUS)
-             && (tem = simplify_plus_minus (code, mode, op0, op1)) != 0)
-           return tem;
-
-         /* Don't let a relocatable value get a negative coeff.  */
-         if (GET_CODE (op1) == CONST_INT && GET_MODE (op0) != VOIDmode)
-           return plus_constant (op0, - INTVAL (op1));
-
-         /* (x - (x & y)) -> (x & ~y) */
-         if (GET_CODE (op1) == AND)
-           {
-            if (rtx_equal_p (op0, XEXP (op1, 0)))
-              return cse_gen_binary (AND, mode, op0, gen_rtx_NOT (mode, XEXP (op1, 1)));
-            if (rtx_equal_p (op0, XEXP (op1, 1)))
-              return cse_gen_binary (AND, mode, op0, gen_rtx_NOT (mode, XEXP (op1, 0)));
-          }
-         break;
-
-       case MULT:
-         if (op1 == constm1_rtx)
-           {
-             tem = simplify_unary_operation (NEG, mode, op0, mode);
-
-             return tem ? tem : gen_rtx_NEG (mode, op0);
-           }
-
-         /* In IEEE floating point, x*0 is not always 0.  */
-         if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
-              || ! FLOAT_MODE_P (mode) || flag_fast_math)
-             && op1 == CONST0_RTX (mode)
-             && ! side_effects_p (op0))
-           return op1;
-
-         /* In IEEE floating point, x*1 is not equivalent to x for nans.
-            However, ANSI says we can drop signals,
-            so we can do this anyway.  */
-         if (op1 == CONST1_RTX (mode))
-           return op0;
-
-         /* Convert multiply by constant power of two into shift unless
-            we are still generating RTL.  This test is a kludge.  */
-         if (GET_CODE (op1) == CONST_INT
-             && (val = exact_log2 (INTVAL (op1))) >= 0
-             /* If the mode is larger than the host word size, and the
-                uppermost bit is set, then this isn't a power of two due
-                to implicit sign extension.  */
-             && (width <= HOST_BITS_PER_WIDE_INT
-                 || val != HOST_BITS_PER_WIDE_INT - 1)
-             && ! rtx_equal_function_value_matters)
-           return gen_rtx_ASHIFT (mode, op0, GEN_INT (val));
-
-         if (GET_CODE (op1) == CONST_DOUBLE
-             && GET_MODE_CLASS (GET_MODE (op1)) == MODE_FLOAT)
-           {
-             REAL_VALUE_TYPE d;
-             jmp_buf handler;
-             int op1is2, op1ism1;
-
-             if (setjmp (handler))
-               return 0;
-
-             set_float_handler (handler);
-             REAL_VALUE_FROM_CONST_DOUBLE (d, op1);
-             op1is2 = REAL_VALUES_EQUAL (d, dconst2);
-             op1ism1 = REAL_VALUES_EQUAL (d, dconstm1);
-             set_float_handler (NULL_PTR);
-
-             /* x*2 is x+x and x*(-1) is -x */
-             if (op1is2 && GET_MODE (op0) == mode)
-               return gen_rtx_PLUS (mode, op0, copy_rtx (op0));
-
-             else if (op1ism1 && GET_MODE (op0) == mode)
-               return gen_rtx_NEG (mode, op0);
-           }
-         break;
-
-       case IOR:
-         if (op1 == const0_rtx)
-           return op0;
-         if (GET_CODE (op1) == CONST_INT
-             && (INTVAL (op1) & GET_MODE_MASK (mode)) == GET_MODE_MASK (mode))
-           return op1;
-         if (rtx_equal_p (op0, op1) && ! side_effects_p (op0))
-           return op0;
-         /* A | (~A) -> -1 */
-         if (((GET_CODE (op0) == NOT && rtx_equal_p (XEXP (op0, 0), op1))
-              || (GET_CODE (op1) == NOT && rtx_equal_p (XEXP (op1, 0), op0)))
-             && ! side_effects_p (op0)
-             && GET_MODE_CLASS (mode) != MODE_CC)
-           return constm1_rtx;
-         break;
-
-       case XOR:
-         if (op1 == const0_rtx)
-           return op0;
-         if (GET_CODE (op1) == CONST_INT
-             && (INTVAL (op1) & GET_MODE_MASK (mode)) == GET_MODE_MASK (mode))
-           return gen_rtx_NOT (mode, op0);
-         if (op0 == op1 && ! side_effects_p (op0)
-             && GET_MODE_CLASS (mode) != MODE_CC)
-           return const0_rtx;
-         break;
-
-       case AND:
-         if (op1 == const0_rtx && ! side_effects_p (op0))
-           return const0_rtx;
-         if (GET_CODE (op1) == CONST_INT
-             && (INTVAL (op1) & GET_MODE_MASK (mode)) == GET_MODE_MASK (mode))
-           return op0;
-         if (op0 == op1 && ! side_effects_p (op0)
-             && GET_MODE_CLASS (mode) != MODE_CC)
-           return op0;
-         /* A & (~A) -> 0 */
-         if (((GET_CODE (op0) == NOT && rtx_equal_p (XEXP (op0, 0), op1))
-              || (GET_CODE (op1) == NOT && rtx_equal_p (XEXP (op1, 0), op0)))
-             && ! side_effects_p (op0)
-             && GET_MODE_CLASS (mode) != MODE_CC)
-           return const0_rtx;
-         break;
-
-       case UDIV:
-         /* Convert divide by power of two into shift (divide by 1 handled
-            below).  */
-         if (GET_CODE (op1) == CONST_INT
-             && (arg1 = exact_log2 (INTVAL (op1))) > 0)
-           return gen_rtx_LSHIFTRT (mode, op0, GEN_INT (arg1));
-
-         /* ... fall through ...  */
-
-       case DIV:
-         if (op1 == CONST1_RTX (mode))
-           return op0;
-
-         /* In IEEE floating point, 0/x is not always 0.  */
-         if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
-              || ! FLOAT_MODE_P (mode) || flag_fast_math)
-             && op0 == CONST0_RTX (mode)
-             && ! side_effects_p (op1))
-           return op0;
-
-#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
-         /* Change division by a constant into multiplication.  Only do
-            this with -ffast-math until an expert says it is safe in
-            general.  */
-         else if (GET_CODE (op1) == CONST_DOUBLE
-                  && GET_MODE_CLASS (GET_MODE (op1)) == MODE_FLOAT
-                  && op1 != CONST0_RTX (mode)
-                  && flag_fast_math)
-           {
-             REAL_VALUE_TYPE d;
-             REAL_VALUE_FROM_CONST_DOUBLE (d, op1);
-
-             if (! REAL_VALUES_EQUAL (d, dconst0))
-               {
-#if defined (REAL_ARITHMETIC)
-                 REAL_ARITHMETIC (d, rtx_to_tree_code (DIV), dconst1, d);
-                 return gen_rtx_MULT (mode, op0, 
-                                      CONST_DOUBLE_FROM_REAL_VALUE (d, mode));
-#else
-                 return gen_rtx_MULT (mode, op0, 
-                                      CONST_DOUBLE_FROM_REAL_VALUE (1./d, mode));
-#endif
-               }
-           }
-#endif
-         break;
-
-       case UMOD:
-         /* Handle modulus by power of two (mod with 1 handled below).  */
-         if (GET_CODE (op1) == CONST_INT
-             && exact_log2 (INTVAL (op1)) > 0)
-           return gen_rtx_AND (mode, op0, GEN_INT (INTVAL (op1) - 1));
-
-         /* ... fall through ...  */
-
-       case MOD:
-         if ((op0 == const0_rtx || op1 == const1_rtx)
-             && ! side_effects_p (op0) && ! side_effects_p (op1))
-           return const0_rtx;
-         break;
-
-       case ROTATERT:
-       case ROTATE:
-         /* Rotating ~0 always results in ~0.  */
-         if (GET_CODE (op0) == CONST_INT && width <= HOST_BITS_PER_WIDE_INT
-             && INTVAL (op0) == GET_MODE_MASK (mode)
-             && ! side_effects_p (op1))
-           return op0;
-
-         /* ... fall through ...  */
-
-       case ASHIFT:
-       case ASHIFTRT:
-       case LSHIFTRT:
-         if (op1 == const0_rtx)
-           return op0;
-         if (op0 == const0_rtx && ! side_effects_p (op1))
-           return op0;
-         break;
-
-       case SMIN:
-         if (width <= HOST_BITS_PER_WIDE_INT && GET_CODE (op1) == CONST_INT 
-             && INTVAL (op1) == (HOST_WIDE_INT) 1 << (width -1)
-             && ! side_effects_p (op0))
-           return op1;
-         else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0))
-           return op0;
-         break;
-          
-       case SMAX:
-         if (width <= HOST_BITS_PER_WIDE_INT && GET_CODE (op1) == CONST_INT
-             && (INTVAL (op1)
-                 == (unsigned HOST_WIDE_INT) GET_MODE_MASK (mode) >> 1)
-             && ! side_effects_p (op0))
-           return op1;
-         else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0))
-           return op0;
-         break;
-
-       case UMIN:
-         if (op1 == const0_rtx && ! side_effects_p (op0))
-           return op1;
-         else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0))
-           return op0;
-         break;
-           
-       case UMAX:
-         if (op1 == constm1_rtx && ! side_effects_p (op0))
-           return op1;
-         else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0))
-           return op0;
-         break;
-
-       default:
-         abort ();
-       }
-      
-      return 0;
-    }
-
-  /* Get the integer argument values in two forms:
-     zero-extended in ARG0, ARG1 and sign-extended in ARG0S, ARG1S.  */
-
-  arg0 = INTVAL (op0);
-  arg1 = INTVAL (op1);
-
-  if (width < HOST_BITS_PER_WIDE_INT)
-    {
-      arg0 &= ((HOST_WIDE_INT) 1 << width) - 1;
-      arg1 &= ((HOST_WIDE_INT) 1 << width) - 1;
-
-      arg0s = arg0;
-      if (arg0s & ((HOST_WIDE_INT) 1 << (width - 1)))
-       arg0s |= ((HOST_WIDE_INT) (-1) << width);
-
-      arg1s = arg1;
-      if (arg1s & ((HOST_WIDE_INT) 1 << (width - 1)))
-       arg1s |= ((HOST_WIDE_INT) (-1) << width);
-    }
-  else
-    {
-      arg0s = arg0;
-      arg1s = arg1;
-    }
-
-  /* Compute the value of the arithmetic.  */
-
-  switch (code)
-    {
-    case PLUS:
-      val = arg0s + arg1s;
-      break;
-
-    case MINUS:
-      val = arg0s - arg1s;
-      break;
-
-    case MULT:
-      val = arg0s * arg1s;
-      break;
-
-    case DIV:
-      if (arg1s == 0)
-       return 0;
-      val = arg0s / arg1s;
-      break;
-
-    case MOD:
-      if (arg1s == 0)
-       return 0;
-      val = arg0s % arg1s;
-      break;
-
-    case UDIV:
-      if (arg1 == 0)
-       return 0;
-      val = (unsigned HOST_WIDE_INT) arg0 / arg1;
-      break;
-
-    case UMOD:
-      if (arg1 == 0)
-       return 0;
-      val = (unsigned HOST_WIDE_INT) arg0 % arg1;
-      break;
-
-    case AND:
-      val = arg0 & arg1;
-      break;
-
-    case IOR:
-      val = arg0 | arg1;
-      break;
-
-    case XOR:
-      val = arg0 ^ arg1;
-      break;
-
-    case LSHIFTRT:
-      /* If shift count is undefined, don't fold it; let the machine do
-        what it wants.  But truncate it if the machine will do that.  */
-      if (arg1 < 0)
-       return 0;
-
-#ifdef SHIFT_COUNT_TRUNCATED
-      if (SHIFT_COUNT_TRUNCATED)
-       arg1 %= width;
-#endif
-
-      val = ((unsigned HOST_WIDE_INT) arg0) >> arg1;
-      break;
-
-    case ASHIFT:
-      if (arg1 < 0)
-       return 0;
-
-#ifdef SHIFT_COUNT_TRUNCATED
-      if (SHIFT_COUNT_TRUNCATED)
-       arg1 %= width;
-#endif
-
-      val = ((unsigned HOST_WIDE_INT) arg0) << arg1;
-      break;
-
-    case ASHIFTRT:
-      if (arg1 < 0)
-       return 0;
-
-#ifdef SHIFT_COUNT_TRUNCATED
-      if (SHIFT_COUNT_TRUNCATED)
-       arg1 %= width;
-#endif
-
-      val = arg0s >> arg1;
-
-      /* Bootstrap compiler may not have sign extended the right shift.
-        Manually extend the sign to insure bootstrap cc matches gcc.  */
-      if (arg0s < 0 && arg1 > 0)
-       val |= ((HOST_WIDE_INT) -1) << (HOST_BITS_PER_WIDE_INT - arg1);
-
-      break;
-
-    case ROTATERT:
-      if (arg1 < 0)
-       return 0;
-
-      arg1 %= width;
-      val = ((((unsigned HOST_WIDE_INT) arg0) << (width - arg1))
-            | (((unsigned HOST_WIDE_INT) arg0) >> arg1));
-      break;
-
-    case ROTATE:
-      if (arg1 < 0)
-       return 0;
-
-      arg1 %= width;
-      val = ((((unsigned HOST_WIDE_INT) arg0) << arg1)
-            | (((unsigned HOST_WIDE_INT) arg0) >> (width - arg1)));
-      break;
-
-    case COMPARE:
-      /* Do nothing here.  */
-      return 0;
-
-    case SMIN:
-      val = arg0s <= arg1s ? arg0s : arg1s;
-      break;
-
-    case UMIN:
-      val = ((unsigned HOST_WIDE_INT) arg0
-            <= (unsigned HOST_WIDE_INT) arg1 ? arg0 : arg1);
-      break;
-
-    case SMAX:
-      val = arg0s > arg1s ? arg0s : arg1s;
-      break;
-
-    case UMAX:
-      val = ((unsigned HOST_WIDE_INT) arg0
-            > (unsigned HOST_WIDE_INT) arg1 ? arg0 : arg1);
-      break;
-
-    default:
-      abort ();
-    }
-
-  /* Clear the bits that don't belong in our mode, unless they and our sign
-     bit are all one.  So we get either a reasonable negative value or a
-     reasonable unsigned value for this mode.  */
-  if (width < HOST_BITS_PER_WIDE_INT
-      && ((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
-         != ((HOST_WIDE_INT) (-1) << (width - 1))))
-    val &= ((HOST_WIDE_INT) 1 << width) - 1;
-
-  /* If this would be an entire word for the target, but is not for
-     the host, then sign-extend on the host so that the number will look
-     the same way on the host that it would on the target.
-
-     For example, when building a 64 bit alpha hosted 32 bit sparc
-     targeted compiler, then we want the 32 bit unsigned value -1 to be
-     represented as a 64 bit value -1, and not as 0x00000000ffffffff.
-     The later confuses the sparc backend.  */
-
-  if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
-      && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
-    val |= ((HOST_WIDE_INT) (-1) << width);
-
-  return GEN_INT (val);
-}
-\f
-/* Simplify a PLUS or MINUS, at least one of whose operands may be another
-   PLUS or MINUS.
-
-   Rather than test for specific case, we do this by a brute-force method
-   and do all possible simplifications until no more changes occur.  Then
-   we rebuild the operation.  */
-
-static rtx
-simplify_plus_minus (code, mode, op0, op1)
-     enum rtx_code code;
-     enum machine_mode mode;
-     rtx op0, op1;
-{
-  rtx ops[8];
-  int negs[8];
-  rtx result, tem;
-  int n_ops = 2, input_ops = 2, input_consts = 0, n_consts = 0;
-  int first = 1, negate = 0, changed;
-  int i, j;
-
-  bzero ((char *) ops, sizeof ops);
-  
-  /* Set up the two operands and then expand them until nothing has been
-     changed.  If we run out of room in our array, give up; this should
-     almost never happen.  */
-
-  ops[0] = op0, ops[1] = op1, negs[0] = 0, negs[1] = (code == MINUS);
-
-  changed = 1;
-  while (changed)
-    {
-      changed = 0;
-
-      for (i = 0; i < n_ops; i++)
-       switch (GET_CODE (ops[i]))
-         {
-         case PLUS:
-         case MINUS:
-           if (n_ops == 7)
-             return 0;
-
-           ops[n_ops] = XEXP (ops[i], 1);
-           negs[n_ops++] = GET_CODE (ops[i]) == MINUS ? !negs[i] : negs[i];
-           ops[i] = XEXP (ops[i], 0);
-           input_ops++;
-           changed = 1;
-           break;
-
-         case NEG:
-           ops[i] = XEXP (ops[i], 0);
-           negs[i] = ! negs[i];
-           changed = 1;
-           break;
-
-         case CONST:
-           ops[i] = XEXP (ops[i], 0);
-           input_consts++;
-           changed = 1;
-           break;
-
-         case NOT:
-           /* ~a -> (-a - 1) */
-           if (n_ops != 7)
-             {
-               ops[n_ops] = constm1_rtx;
-               negs[n_ops++] = negs[i];
-               ops[i] = XEXP (ops[i], 0);
-               negs[i] = ! negs[i];
-               changed = 1;
-             }
-           break;
-
-         case CONST_INT:
-           if (negs[i])
-             ops[i] = GEN_INT (- INTVAL (ops[i])), negs[i] = 0, changed = 1;
-           break;
-
-         default:
-           break;
-         }
-    }
-
-  /* If we only have two operands, we can't do anything.  */
-  if (n_ops <= 2)
-    return 0;
-
-  /* Now simplify each pair of operands until nothing changes.  The first
-     time through just simplify constants against each other.  */
-
-  changed = 1;
-  while (changed)
-    {
-      changed = first;
-
-      for (i = 0; i < n_ops - 1; i++)
-       for (j = i + 1; j < n_ops; j++)
-         if (ops[i] != 0 && ops[j] != 0
-             && (! first || (CONSTANT_P (ops[i]) && CONSTANT_P (ops[j]))))
-           {
-             rtx lhs = ops[i], rhs = ops[j];
-             enum rtx_code ncode = PLUS;
-
-             if (negs[i] && ! negs[j])
-               lhs = ops[j], rhs = ops[i], ncode = MINUS;
-             else if (! negs[i] && negs[j])
-               ncode = MINUS;
-
-             tem = simplify_binary_operation (ncode, mode, lhs, rhs);
-             if (tem)
-               {
-                 ops[i] = tem, ops[j] = 0;
-                 negs[i] = negs[i] && negs[j];
-                 if (GET_CODE (tem) == NEG)
-                   ops[i] = XEXP (tem, 0), negs[i] = ! negs[i];
-
-                 if (GET_CODE (ops[i]) == CONST_INT && negs[i])
-                   ops[i] = GEN_INT (- INTVAL (ops[i])), negs[i] = 0;
-                 changed = 1;
-               }
-           }
-
-      first = 0;
-    }
-
-  /* Pack all the operands to the lower-numbered entries and give up if
-     we didn't reduce the number of operands we had.  Make sure we
-     count a CONST as two operands.  If we have the same number of
-     operands, but have made more CONSTs than we had, this is also
-     an improvement, so accept it.  */
-
-  for (i = 0, j = 0; j < n_ops; j++)
-    if (ops[j] != 0)
-      {
-       ops[i] = ops[j], negs[i++] = negs[j];
-       if (GET_CODE (ops[j]) == CONST)
-         n_consts++;
-      }
-
-  if (i + n_consts > input_ops
-      || (i + n_consts == input_ops && n_consts <= input_consts))
-    return 0;
-
-  n_ops = i;
-
-  /* If we have a CONST_INT, put it last.  */
-  for (i = 0; i < n_ops - 1; i++)
-    if (GET_CODE (ops[i]) == CONST_INT)
-      {
-       tem = ops[n_ops - 1], ops[n_ops - 1] = ops[i] , ops[i] = tem;
-       j = negs[n_ops - 1], negs[n_ops - 1] = negs[i], negs[i] = j;
-      }
-
-  /* Put a non-negated operand first.  If there aren't any, make all
-     operands positive and negate the whole thing later.  */
-  for (i = 0; i < n_ops && negs[i]; i++)
-    ;
-
-  if (i == n_ops)
-    {
-      for (i = 0; i < n_ops; i++)
-       negs[i] = 0;
-      negate = 1;
-    }
-  else if (i != 0)
-    {
-      tem = ops[0], ops[0] = ops[i], ops[i] = tem;
-      j = negs[0], negs[0] = negs[i], negs[i] = j;
-    }
-
-  /* Now make the result by performing the requested operations.  */
-  result = ops[0];
-  for (i = 1; i < n_ops; i++)
-    result = cse_gen_binary (negs[i] ? MINUS : PLUS, mode, result, ops[i]);
-
-  return negate ? gen_rtx_NEG (mode, result) : result;
-}
-\f
-/* Make a binary operation by properly ordering the operands and 
-   seeing if the expression folds.  */
-
-static rtx
-cse_gen_binary (code, mode, op0, op1)
-     enum rtx_code code;
-     enum machine_mode mode;
-     rtx op0, op1;
-{
-  rtx tem;
-
-  /* Put complex operands first and constants second if commutative.  */
-  if (GET_RTX_CLASS (code) == 'c'
-      && ((CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT)
-         || (GET_RTX_CLASS (GET_CODE (op0)) == 'o'
-             && GET_RTX_CLASS (GET_CODE (op1)) != 'o')
-         || (GET_CODE (op0) == SUBREG
-             && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op0))) == 'o'
-             && GET_RTX_CLASS (GET_CODE (op1)) != 'o')))
-    tem = op0, op0 = op1, op1 = tem;
-
-  /* If this simplifies, do it.  */
-  tem = simplify_binary_operation (code, mode, op0, op1);
-
-  if (tem)
-    return tem;
-
-  /* Handle addition and subtraction of CONST_INT specially.  Otherwise,
-     just form the operation.  */
-
-  if (code == PLUS && GET_CODE (op1) == CONST_INT
-      && GET_MODE (op0) != VOIDmode)
-    return plus_constant (op0, INTVAL (op1));
-  else if (code == MINUS && GET_CODE (op1) == CONST_INT
-          && GET_MODE (op0) != VOIDmode)
-    return plus_constant (op0, - INTVAL (op1));
-  else
-    return gen_rtx_fmt_ee (code, mode, op0, op1);
-}
-\f
-/* Like simplify_binary_operation except used for relational operators.
-   MODE is the mode of the operands, not that of the result.  If MODE
-   is VOIDmode, both operands must also be VOIDmode and we compare the
-   operands in "infinite precision".
-
-   If no simplification is possible, this function returns zero.  Otherwise,
-   it returns either const_true_rtx or const0_rtx.  */
-
-rtx
-simplify_relational_operation (code, mode, op0, op1)
-     enum rtx_code code;
-     enum machine_mode mode;
-     rtx op0, op1;
-{
-  int equal, op0lt, op0ltu, op1lt, op1ltu;
-  rtx tem;
-
-  /* If op0 is a compare, extract the comparison arguments from it.  */
-  if (GET_CODE (op0) == COMPARE && op1 == const0_rtx)
-    op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
-
-  /* We can't simplify MODE_CC values since we don't know what the
-     actual comparison is.  */
-  if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC
-#ifdef HAVE_cc0
-      || op0 == cc0_rtx
-#endif
-      )
-    return 0;
-
-  /* For integer comparisons of A and B maybe we can simplify A - B and can
-     then simplify a comparison of that with zero.  If A and B are both either
-     a register or a CONST_INT, this can't help; testing for these cases will
-     prevent infinite recursion here and speed things up.
-
-     If CODE is an unsigned comparison, then we can never do this optimization,
-     because it gives an incorrect result if the subtraction wraps around zero.
-     ANSI C defines unsigned operations such that they never overflow, and
-     thus such cases can not be ignored.  */
-
-  if (INTEGRAL_MODE_P (mode) && op1 != const0_rtx
-      && ! ((GET_CODE (op0) == REG || GET_CODE (op0) == CONST_INT)
-           && (GET_CODE (op1) == REG || GET_CODE (op1) == CONST_INT))
-      && 0 != (tem = simplify_binary_operation (MINUS, mode, op0, op1))
-      && code != GTU && code != GEU && code != LTU && code != LEU)
-    return simplify_relational_operation (signed_condition (code),
-                                         mode, tem, const0_rtx);
-
-  /* For non-IEEE floating-point, if the two operands are equal, we know the
-     result.  */
-  if (rtx_equal_p (op0, op1)
-      && (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
-         || ! FLOAT_MODE_P (GET_MODE (op0)) || flag_fast_math))
-    equal = 1, op0lt = 0, op0ltu = 0, op1lt = 0, op1ltu = 0;
-
-  /* If the operands are floating-point constants, see if we can fold
-     the result.  */
-#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
-  else if (GET_CODE (op0) == CONST_DOUBLE && GET_CODE (op1) == CONST_DOUBLE
-          && GET_MODE_CLASS (GET_MODE (op0)) == MODE_FLOAT)
-    {
-      REAL_VALUE_TYPE d0, d1;
-      jmp_buf handler;
-      
-      if (setjmp (handler))
-       return 0;
-
-      set_float_handler (handler);
-      REAL_VALUE_FROM_CONST_DOUBLE (d0, op0);
-      REAL_VALUE_FROM_CONST_DOUBLE (d1, op1);
-      equal = REAL_VALUES_EQUAL (d0, d1);
-      op0lt = op0ltu = REAL_VALUES_LESS (d0, d1);
-      op1lt = op1ltu = REAL_VALUES_LESS (d1, d0);
-      set_float_handler (NULL_PTR);
-    }
-#endif  /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
-
-  /* Otherwise, see if the operands are both integers.  */
-  else if ((GET_MODE_CLASS (mode) == MODE_INT || mode == VOIDmode)
-          && (GET_CODE (op0) == CONST_DOUBLE || GET_CODE (op0) == CONST_INT)
-          && (GET_CODE (op1) == CONST_DOUBLE || GET_CODE (op1) == CONST_INT))
-    {
-      int width = GET_MODE_BITSIZE (mode);
-      HOST_WIDE_INT l0s, h0s, l1s, h1s;
-      unsigned HOST_WIDE_INT l0u, h0u, l1u, h1u;
-
-      /* Get the two words comprising each integer constant.  */
-      if (GET_CODE (op0) == CONST_DOUBLE)
-       {
-         l0u = l0s = CONST_DOUBLE_LOW (op0);
-         h0u = h0s = CONST_DOUBLE_HIGH (op0);
-       }
-      else
-       {
-         l0u = l0s = INTVAL (op0);
-         h0u = h0s = l0s < 0 ? -1 : 0;
-       }
-         
-      if (GET_CODE (op1) == CONST_DOUBLE)
-       {
-         l1u = l1s = CONST_DOUBLE_LOW (op1);
-         h1u = h1s = CONST_DOUBLE_HIGH (op1);
-       }
-      else
-       {
-         l1u = l1s = INTVAL (op1);
-         h1u = h1s = l1s < 0 ? -1 : 0;
-       }
-
-      /* If WIDTH is nonzero and smaller than HOST_BITS_PER_WIDE_INT,
-        we have to sign or zero-extend the values.  */
-      if (width != 0 && width <= HOST_BITS_PER_WIDE_INT)
-       h0u = h1u = 0, h0s = l0s < 0 ? -1 : 0, h1s = l1s < 0 ? -1 : 0;
-
-      if (width != 0 && width < HOST_BITS_PER_WIDE_INT)
-       {
-         l0u &= ((HOST_WIDE_INT) 1 << width) - 1;
-         l1u &= ((HOST_WIDE_INT) 1 << width) - 1;
-
-         if (l0s & ((HOST_WIDE_INT) 1 << (width - 1)))
-           l0s |= ((HOST_WIDE_INT) (-1) << width);
-
-         if (l1s & ((HOST_WIDE_INT) 1 << (width - 1)))
-           l1s |= ((HOST_WIDE_INT) (-1) << width);
-       }
-
-      equal = (h0u == h1u && l0u == l1u);
-      op0lt = (h0s < h1s || (h0s == h1s && l0s < l1s));
-      op1lt = (h1s < h0s || (h1s == h0s && l1s < l0s));
-      op0ltu = (h0u < h1u || (h0u == h1u && l0u < l1u));
-      op1ltu = (h1u < h0u || (h1u == h0u && l1u < l0u));
-    }
-
-  /* Otherwise, there are some code-specific tests we can make.  */
-  else
-    {
-      switch (code)
-       {
-       case EQ:
-         /* References to the frame plus a constant or labels cannot
-            be zero, but a SYMBOL_REF can due to #pragma weak.  */
-         if (((NONZERO_BASE_PLUS_P (op0) && op1 == const0_rtx)
-              || GET_CODE (op0) == LABEL_REF)
-#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
-             /* On some machines, the ap reg can be 0 sometimes.  */
-             && op0 != arg_pointer_rtx
-#endif
-               )
-           return const0_rtx;
-         break;
-
-       case NE:
-         if (((NONZERO_BASE_PLUS_P (op0) && op1 == const0_rtx)
-              || GET_CODE (op0) == LABEL_REF)
-#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
-             && op0 != arg_pointer_rtx
+             || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT
+                 && (REAL_VALUE_NEGATIVE
+                     (FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)))))
 #endif
              )
-           return const_true_rtx;
-         break;
-
-       case GEU:
-         /* Unsigned values are never negative.  */
-         if (op1 == const0_rtx)
-           return const_true_rtx;
-         break;
-
-       case LTU:
-         if (op1 == const0_rtx)
-           return const0_rtx;
-         break;
-
-       case LEU:
-         /* Unsigned values are never greater than the largest
-            unsigned value.  */
-         if (GET_CODE (op1) == CONST_INT
-             && INTVAL (op1) == GET_MODE_MASK (mode)
-           && INTEGRAL_MODE_P (mode))
-         return const_true_rtx;
-         break;
-
-       case GTU:
-         if (GET_CODE (op1) == CONST_INT
-             && INTVAL (op1) == GET_MODE_MASK (mode)
-             && INTEGRAL_MODE_P (mode))
-           return const0_rtx;
-         break;
-         
-       default:
-         break;
+           x = arg1;
+         else if (code == EQ
+                  || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT
+                      && code == GE && STORE_FLAG_VALUE == -1)
+#ifdef FLOAT_STORE_FLAG_VALUE
+                  || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT
+                      && (REAL_VALUE_NEGATIVE
+                          (FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)))))
+#endif
+                  )
+           x = arg1, reverse_code = 1;
        }
 
-      return 0;
-    }
+      /* ??? We could also check for
 
-  /* If we reach here, EQUAL, OP0LT, OP0LTU, OP1LT, and OP1LTU are set
-     as appropriate.  */
-  switch (code)
-    {
-    case EQ:
-      return equal ? const_true_rtx : const0_rtx;
-    case NE:
-      return ! equal ? const_true_rtx : const0_rtx;
-    case LT:
-      return op0lt ? const_true_rtx : const0_rtx;
-    case GT:
-      return op1lt ? const_true_rtx : const0_rtx;
-    case LTU:
-      return op0ltu ? const_true_rtx : const0_rtx;
-    case GTU:
-      return op1ltu ? const_true_rtx : const0_rtx;
-    case LE:
-      return equal || op0lt ? const_true_rtx : const0_rtx;
-    case GE:
-      return equal || op1lt ? const_true_rtx : const0_rtx;
-    case LEU:
-      return equal || op0ltu ? const_true_rtx : const0_rtx;
-    case GEU:
-      return equal || op1ltu ? const_true_rtx : const0_rtx;
-    default:
-      abort ();
-    }
-}
-\f
-/* Simplify CODE, an operation with result mode MODE and three operands,
-   OP0, OP1, and OP2.  OP0_MODE was the mode of OP0 before it became
-   a constant.  Return 0 if no simplifications is possible.  */
+        (ne (and (eq (...) (const_int 1))) (const_int 0))
 
-rtx
-simplify_ternary_operation (code, mode, op0_mode, op0, op1, op2)
-     enum rtx_code code;
-     enum machine_mode mode, op0_mode;
-     rtx op0, op1, op2;
-{
-  int width = GET_MODE_BITSIZE (mode);
+        and related forms, but let's wait until we see them occurring.  */
 
-  /* VOIDmode means "infinite" precision.  */
-  if (width == 0)
-    width = HOST_BITS_PER_WIDE_INT;
+      if (x == 0)
+       /* Look up ARG1 in the hash table and see if it has an equivalence
+          that lets us see what is being compared.  */
+       p = lookup (arg1, safe_hash (arg1, GET_MODE (arg1)) & HASH_MASK,
+                   GET_MODE (arg1));
+      if (p) p = p->first_same_value;
 
-  switch (code)
-    {
-    case SIGN_EXTRACT:
-    case ZERO_EXTRACT:
-      if (GET_CODE (op0) == CONST_INT
-         && GET_CODE (op1) == CONST_INT
-         && GET_CODE (op2) == CONST_INT
-         && INTVAL (op1) + INTVAL (op2) <= GET_MODE_BITSIZE (op0_mode)
-         && width <= HOST_BITS_PER_WIDE_INT)
+      for (; p; p = p->next_same_value)
        {
-         /* Extracting a bit-field from a constant */
-         HOST_WIDE_INT val = INTVAL (op0);
+         enum machine_mode inner_mode = GET_MODE (p->exp);
 
-         if (BITS_BIG_ENDIAN)
-           val >>= (GET_MODE_BITSIZE (op0_mode)
-                    - INTVAL (op2) - INTVAL (op1));
-         else
-           val >>= INTVAL (op2);
+         /* If the entry isn't valid, skip it.  */
+         if (! exp_equiv_p (p->exp, p->exp, 1, 0))
+           continue;
 
-         if (HOST_BITS_PER_WIDE_INT != INTVAL (op1))
+         if (GET_CODE (p->exp) == COMPARE
+             /* Another possibility is that this machine has a compare insn
+                that includes the comparison code.  In that case, ARG1 would
+                be equivalent to a comparison operation that would set ARG1 to
+                either STORE_FLAG_VALUE or zero.  If this is an NE operation,
+                ORIG_CODE is the actual comparison being done; if it is an EQ,
+                we must reverse ORIG_CODE.  On machine with a negative value
+                for STORE_FLAG_VALUE, also look at LT and GE operations.  */
+             || ((code == NE
+                  || (code == LT
+                      && GET_MODE_CLASS (inner_mode) == MODE_INT
+                      && (GET_MODE_BITSIZE (inner_mode)
+                          <= HOST_BITS_PER_WIDE_INT)
+                      && (STORE_FLAG_VALUE
+                          & ((HOST_WIDE_INT) 1
+                             << (GET_MODE_BITSIZE (inner_mode) - 1))))
+#ifdef FLOAT_STORE_FLAG_VALUE
+                  || (code == LT
+                      && GET_MODE_CLASS (inner_mode) == MODE_FLOAT
+                      && (REAL_VALUE_NEGATIVE
+                          (FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)))))
+#endif
+                  )
+                 && GET_RTX_CLASS (GET_CODE (p->exp)) == '<'))
            {
-             /* First zero-extend.  */
-             val &= ((HOST_WIDE_INT) 1 << INTVAL (op1)) - 1;
-             /* If desired, propagate sign bit.  */
-             if (code == SIGN_EXTRACT
-                 && (val & ((HOST_WIDE_INT) 1 << (INTVAL (op1) - 1))))
-               val |= ~ (((HOST_WIDE_INT) 1 << INTVAL (op1)) - 1);
+             x = p->exp;
+             break;
+           }
+         else if ((code == EQ
+                   || (code == GE
+                       && GET_MODE_CLASS (inner_mode) == MODE_INT
+                       && (GET_MODE_BITSIZE (inner_mode)
+                           <= HOST_BITS_PER_WIDE_INT)
+                       && (STORE_FLAG_VALUE
+                           & ((HOST_WIDE_INT) 1
+                              << (GET_MODE_BITSIZE (inner_mode) - 1))))
+#ifdef FLOAT_STORE_FLAG_VALUE
+                   || (code == GE
+                       && GET_MODE_CLASS (inner_mode) == MODE_FLOAT
+                       && (REAL_VALUE_NEGATIVE
+                           (FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)))))
+#endif
+                   )
+                  && GET_RTX_CLASS (GET_CODE (p->exp)) == '<')
+           {
+             reverse_code = 1;
+             x = p->exp;
+             break;
            }
 
-         /* Clear the bits that don't belong in our mode,
-            unless they and our sign bit are all one.
-            So we get either a reasonable negative value or a reasonable
-            unsigned value for this mode.  */
-         if (width < HOST_BITS_PER_WIDE_INT
-             && ((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
-                 != ((HOST_WIDE_INT) (-1) << (width - 1))))
-           val &= ((HOST_WIDE_INT) 1 << width) - 1;
-
-         return GEN_INT (val);
+         /* If this is fp + constant, the equivalent is a better operand since
+            it may let us predict the value of the comparison.  */
+         else if (NONZERO_BASE_PLUS_P (p->exp))
+           {
+             arg1 = p->exp;
+             continue;
+           }
        }
-      break;
 
-    case IF_THEN_ELSE:
-      if (GET_CODE (op0) == CONST_INT)
-       return op0 != const0_rtx ? op1 : op2;
-
-      /* Convert a == b ? b : a to "a".  */
-      if (GET_CODE (op0) == NE && ! side_effects_p (op0)
-         && rtx_equal_p (XEXP (op0, 0), op1)
-         && rtx_equal_p (XEXP (op0, 1), op2))
-       return op1;
-      else if (GET_CODE (op0) == EQ && ! side_effects_p (op0)
-         && rtx_equal_p (XEXP (op0, 1), op1)
-         && rtx_equal_p (XEXP (op0, 0), op2))
-       return op2;
-      else if (GET_RTX_CLASS (GET_CODE (op0)) == '<' && ! side_effects_p (op0))
-       {
-         rtx temp;
-         temp = simplify_relational_operation (GET_CODE (op0), op0_mode,
-                                               XEXP (op0, 0), XEXP (op0, 1));
-         /* See if any simplifications were possible.  */
-         if (temp == const0_rtx)
-           return op2;
-         else if (temp == const1_rtx)
-           return op1;
-       }
-      break;
+      /* If we didn't find a useful equivalence for ARG1, we are done.
+        Otherwise, set up for the next iteration.  */
+      if (x == 0)
+       break;
 
-    default:
-      abort ();
+      arg1 = XEXP (x, 0),  arg2 = XEXP (x, 1);
+      if (GET_RTX_CLASS (GET_CODE (x)) == '<')
+       code = GET_CODE (x);
+
+      if (reverse_code)
+       code = reverse_condition (code);
     }
 
-  return 0;
+  /* Return our results.  Return the modes from before fold_rtx
+     because fold_rtx might produce const_int, and then it's too late.  */
+  *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2);
+  *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0);
+
+  return code;
 }
 \f
 /* If X is a nontrivial arithmetic operation on an argument
@@ -4903,7 +3087,7 @@ fold_rtx (x, insn)
 {
   register enum rtx_code code;
   register enum machine_mode mode;
-  register char *fmt;
+  register const char *fmt;
   register int i;
   rtx new = 0;
   int copied = 0;
@@ -5002,7 +3186,7 @@ fold_rtx (x, insn)
                    && GET_MODE (SUBREG_REG (elt->exp)) == mode
                    && exp_equiv_p (elt->exp, elt->exp, 1, 0))
                  return copy_rtx (SUBREG_REG (elt->exp));
-           }
+             }
 
          return x;
        }
@@ -5176,10 +3360,15 @@ fold_rtx (x, insn)
        HOST_WIDE_INT offset = 0;
 
        if (GET_CODE (addr) == REG
-           && REGNO_QTY_VALID_P (REGNO (addr))
-           && GET_MODE (addr) == qty_mode[reg_qty[REGNO (addr)]]
-           && qty_const[reg_qty[REGNO (addr)]] != 0)
-         addr = qty_const[reg_qty[REGNO (addr)]];
+           && REGNO_QTY_VALID_P (REGNO (addr)))
+         {
+           int addr_q = REG_QTY (REGNO (addr));
+           struct qty_table_elem *addr_ent = &qty_table[addr_q];
+
+           if (GET_MODE (addr) == addr_ent->mode
+               && addr_ent->const_rtx != NULL_RTX)
+             addr = addr_ent->const_rtx;
+         }
 
        /* If address is constant, split it into a base and integer offset.  */
        if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF)
@@ -5272,7 +3461,11 @@ fold_rtx (x, insn)
                    /* Indicate this is a constant.  This isn't a 
                       valid form of CONST, but it will only be used
                       to fold the next insns and then discarded, so
-                      it should be safe.  */
+                      it should be safe.
+
+                      Note this expression must be explicitly discarded,
+                      by cse_insn, else it may end up in a REG_EQUAL note
+                      and "escape" to cause problems elsewhere.  */
                    return gen_rtx_CONST (GET_MODE (new), new);
                  }
              }
@@ -5316,13 +3509,18 @@ fold_rtx (x, insn)
          case REG:
            /* This is the same as calling equiv_constant; it is duplicated
               here for speed.  */
-           if (REGNO_QTY_VALID_P (REGNO (arg))
-               && qty_const[reg_qty[REGNO (arg)]] != 0
-               && GET_CODE (qty_const[reg_qty[REGNO (arg)]]) != REG
-               && GET_CODE (qty_const[reg_qty[REGNO (arg)]]) != PLUS)
-             const_arg
-               = gen_lowpart_if_possible (GET_MODE (arg),
-                                          qty_const[reg_qty[REGNO (arg)]]);
+           if (REGNO_QTY_VALID_P (REGNO (arg)))
+             {
+               int arg_q = REG_QTY (REGNO (arg));
+               struct qty_table_elem *arg_ent = &qty_table[arg_q];
+
+               if (arg_ent->const_rtx != NULL_RTX
+                   && GET_CODE (arg_ent->const_rtx) != REG
+                   && GET_CODE (arg_ent->const_rtx) != PLUS)
+                 const_arg
+                   = gen_lowpart_if_possible (GET_MODE (arg),
+                                              arg_ent->const_rtx);
+             }
            break;
 
          case CONST:
@@ -5495,8 +3693,8 @@ fold_rtx (x, insn)
 #ifdef FLOAT_STORE_FLAG_VALUE
          if (GET_MODE_CLASS (mode) == MODE_FLOAT)
            {
-             true = CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE,
-                                                  mode);
+             true = (CONST_DOUBLE_FROM_REAL_VALUE
+                     (FLOAT_STORE_FLAG_VALUE (mode), mode));
              false = CONST0_RTX (mode);
            }
 #endif
@@ -5545,14 +3743,14 @@ fold_rtx (x, insn)
                  && (folded_arg0 == folded_arg1
                      || (GET_CODE (folded_arg0) == REG
                          && GET_CODE (folded_arg1) == REG
-                         && (reg_qty[REGNO (folded_arg0)]
-                             == reg_qty[REGNO (folded_arg1)]))
+                         && (REG_QTY (REGNO (folded_arg0))
+                             == REG_QTY (REGNO (folded_arg1))))
                      || ((p0 = lookup (folded_arg0,
                                        (safe_hash (folded_arg0, mode_arg0)
-                                        % NBUCKETS), mode_arg0))
+                                        & HASH_MASK), mode_arg0))
                          && (p1 = lookup (folded_arg1,
                                           (safe_hash (folded_arg1, mode_arg0)
-                                           % NBUCKETS), mode_arg0))
+                                           & HASH_MASK), mode_arg0))
                          && p0->first_same_value == p1->first_same_value)))
                return ((code == EQ || code == LE || code == GE
                         || code == LEU || code == GEU)
@@ -5563,23 +3761,25 @@ fold_rtx (x, insn)
                 (we only check the reverse if not floating-point).  */
              else if (GET_CODE (folded_arg0) == REG)
                {
-                 int qty = reg_qty[REGNO (folded_arg0)];
-
-                 if (REGNO_QTY_VALID_P (REGNO (folded_arg0))
-                     && (comparison_dominates_p (qty_comparison_code[qty], code)
-                         || (comparison_dominates_p (qty_comparison_code[qty],
-                                                     reverse_condition (code))
-                             && ! FLOAT_MODE_P (mode_arg0)))
-                     && (rtx_equal_p (qty_comparison_const[qty], folded_arg1)
-                         || (const_arg1
-                             && rtx_equal_p (qty_comparison_const[qty],
-                                             const_arg1))
-                         || (GET_CODE (folded_arg1) == REG
-                             && (reg_qty[REGNO (folded_arg1)]
-                                 == qty_comparison_qty[qty]))))
-                   return (comparison_dominates_p (qty_comparison_code[qty],
-                                                   code)
-                           ? true : false);
+                 int qty = REG_QTY (REGNO (folded_arg0));
+
+                 if (REGNO_QTY_VALID_P (REGNO (folded_arg0)))
+                   {
+                     struct qty_table_elem *ent = &qty_table[qty];
+
+                     if ((comparison_dominates_p (ent->comparison_code, code)
+                          || (! FLOAT_MODE_P (mode_arg0)
+                              && comparison_dominates_p (ent->comparison_code,
+                                                         reverse_condition (code))))
+                         && (rtx_equal_p (ent->comparison_const, folded_arg1)
+                             || (const_arg1
+                                 && rtx_equal_p (ent->comparison_const,
+                                                 const_arg1))
+                             || (GET_CODE (folded_arg1) == REG
+                                 && (REG_QTY (REGNO (folded_arg1)) == ent->comparison_qty))))
+                       return (comparison_dominates_p (ent->comparison_code, code)
+                               ? true : false);
+                   }
                }
            }
        }
@@ -5607,8 +3807,8 @@ fold_rtx (x, insn)
 #ifdef FLOAT_STORE_FLAG_VALUE
              if (GET_MODE_CLASS (mode) == MODE_FLOAT)
                {
-                 true = CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE,
-                                                      mode);
+                 true = (CONST_DOUBLE_FROM_REAL_VALUE
+                         (FLOAT_STORE_FLAG_VALUE (mode), mode));
                  false = CONST0_RTX (mode);
                }
 #endif
@@ -5638,8 +3838,13 @@ fold_rtx (x, insn)
                                           const_arg1 ? const_arg1 : folded_arg1);
 #ifdef FLOAT_STORE_FLAG_VALUE
       if (new != 0 && GET_MODE_CLASS (mode) == MODE_FLOAT)
-       new = ((new == const0_rtx) ? CONST0_RTX (mode)
-              : CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE, mode));
+       {
+         if (new == const0_rtx)
+           new = CONST0_RTX (mode);
+         else
+           new = (CONST_DOUBLE_FROM_REAL_VALUE
+                  (FLOAT_STORE_FLAG_VALUE (mode), mode));
+       }
 #endif
       break;
 
@@ -5703,19 +3908,27 @@ fold_rtx (x, insn)
             hence not save anything) or be incorrect.  */
          if (const_arg1 != 0 && GET_CODE (const_arg1) == CONST_INT
              && INTVAL (const_arg1) < 0
-             && - INTVAL (const_arg1) >= 0
+             /* This used to test
+
+                - INTVAL (const_arg1) >= 0
+
+                But The Sun V5.0 compilers mis-compiled that test.  So
+                instead we test for the problematic value in a more direct
+                manner and hope the Sun compilers get it correct.  */
+             && INTVAL (const_arg1) !=
+               ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1))
              && GET_CODE (folded_arg1) == REG)
            {
              rtx new_const = GEN_INT (- INTVAL (const_arg1));
              struct table_elt *p
-               = lookup (new_const, safe_hash (new_const, mode) % NBUCKETS,
+               = lookup (new_const, safe_hash (new_const, mode) & HASH_MASK,
                          mode);
 
              if (p)
                for (p = p->first_same_value; p; p = p->next_same_value)
                  if (GET_CODE (p->exp) == REG)
-                   return cse_gen_binary (MINUS, mode, folded_arg0,
-                                          canon_reg (p->exp, NULL_RTX));
+                   return simplify_gen_binary (MINUS, mode, folded_arg0,
+                                               canon_reg (p->exp, NULL_RTX));
            }
          goto from_plus;
 
@@ -5822,7 +4035,7 @@ fold_rtx (x, insn)
              if (! reg_mentioned_p (folded_arg0, y))
                y = fold_rtx (y, insn);
 
-             return cse_gen_binary (code, mode, y, new_const);
+             return simplify_gen_binary (code, mode, y, new_const);
            }
          break;
 
@@ -5869,9 +4082,14 @@ equiv_constant (x)
      rtx x;
 {
   if (GET_CODE (x) == REG
-      && REGNO_QTY_VALID_P (REGNO (x))
-      && qty_const[reg_qty[REGNO (x)]])
-    x = gen_lowpart_if_possible (GET_MODE (x), qty_const[reg_qty[REGNO (x)]]);
+      && REGNO_QTY_VALID_P (REGNO (x)))
+    {
+      int x_q = REG_QTY (REGNO (x));
+      struct qty_table_elem *x_ent = &qty_table[x_q];
+
+      if (x_ent->const_rtx)
+       x = gen_lowpart_if_possible (GET_MODE (x), x_ent->const_rtx);
+    }
 
   if (x == 0 || CONSTANT_P (x))
     return x;
@@ -5889,7 +4107,7 @@ equiv_constant (x)
       if (CONSTANT_P (x))
        return x;
 
-      elt = lookup (x, safe_hash (x, GET_MODE (x)) % NBUCKETS, GET_MODE (x));
+      elt = lookup (x, safe_hash (x, GET_MODE (x)) & HASH_MASK, GET_MODE (x));
       if (elt == 0)
        return 0;
 
@@ -5988,6 +4206,10 @@ record_jump_equiv (insn, taken)
     {
       reversed_nonequality = (code != EQ && code != NE);
       code = reverse_condition (code);
+
+      /* Don't remember if we can't find the inverse.  */
+      if (code == UNKNOWN)
+       return;
     }
 
   /* The mode is the mode of the non-constant.  */
@@ -6011,13 +4233,13 @@ record_jump_cond (code, mode, op0, op1, reversed_nonequality)
      int reversed_nonequality;
 {
   unsigned op0_hash, op1_hash;
-  int op0_in_memory, op0_in_struct, op1_in_memory, op1_in_struct;
+  int op0_in_memory, op1_in_memory;
   struct table_elt *op0_elt, *op1_elt;
 
   /* If OP0 and OP1 are known equal, and either is a paradoxical SUBREG,
      we know that they are also equal in the smaller mode (this is also
      true for all smaller modes whether or not there is a SUBREG, but
-     is not worth testing for with no SUBREG.  */
+     is not worth testing for with no SUBREG).  */
 
   /* Note that GET_MODE (op0) may not equal MODE.  */
   if (code == EQ && GET_CODE (op0) == SUBREG
@@ -6081,20 +4303,16 @@ record_jump_cond (code, mode, op0, op1, reversed_nonequality)
 
   do_not_record = 0;
   hash_arg_in_memory = 0;
-  hash_arg_in_struct = 0;
   op0_hash = HASH (op0, mode);
   op0_in_memory = hash_arg_in_memory;
-  op0_in_struct = hash_arg_in_struct;
 
   if (do_not_record)
     return;
 
   do_not_record = 0;
   hash_arg_in_memory = 0;
-  hash_arg_in_struct = 0;
   op1_hash = HASH (op1, mode);
   op1_in_memory = hash_arg_in_memory;
-  op1_in_struct = hash_arg_in_struct;
   
   if (do_not_record)
     return;
@@ -6118,6 +4336,9 @@ record_jump_cond (code, mode, op0, op1, reversed_nonequality)
 
   if (code != EQ || FLOAT_MODE_P (GET_MODE (op0)))
     {
+      struct qty_table_elem *ent;
+      int qty;
+
       /* If we reversed a floating-point comparison, if OP0 is not a
         register, or if OP1 is neither a register or constant, we can't
         do anything.  */
@@ -6147,10 +4368,12 @@ record_jump_cond (code, mode, op0, op1, reversed_nonequality)
 
          op0_elt = insert (op0, NULL_PTR, op0_hash, mode);
          op0_elt->in_memory = op0_in_memory;
-         op0_elt->in_struct = op0_in_struct;
        }
 
-      qty_comparison_code[reg_qty[REGNO (op0)]] = code;
+      qty = REG_QTY (REGNO (op0));
+      ent = &qty_table[qty];
+
+      ent->comparison_code = code;
       if (GET_CODE (op1) == REG)
        {
          /* Look it up again--in case op0 and op1 are the same.  */
@@ -6167,16 +4390,15 @@ record_jump_cond (code, mode, op0, op1, reversed_nonequality)
 
              op1_elt = insert (op1, NULL_PTR, op1_hash, mode);
              op1_elt->in_memory = op1_in_memory;
-             op1_elt->in_struct = op1_in_struct;
            }
 
-         qty_comparison_qty[reg_qty[REGNO (op0)]] = reg_qty[REGNO (op1)];
-         qty_comparison_const[reg_qty[REGNO (op0)]] = 0;
+         ent->comparison_const = NULL_RTX;
+         ent->comparison_qty = REG_QTY (REGNO (op1));
        }
       else
        {
-         qty_comparison_qty[reg_qty[REGNO (op0)]] = -1;
-         qty_comparison_const[reg_qty[REGNO (op0)]] = op1;
+         ent->comparison_const = op1;
+         ent->comparison_qty = -1;
        }
 
       return;
@@ -6195,7 +4417,6 @@ record_jump_cond (code, mode, op0, op1, reversed_nonequality)
 
       op0_elt = insert (op0, NULL_PTR, op0_hash, mode);
       op0_elt->in_memory = op0_in_memory;
-      op0_elt->in_struct = op0_in_struct;
     }
 
   if (op1_elt == 0)
@@ -6208,7 +4429,6 @@ record_jump_cond (code, mode, op0, op1, reversed_nonequality)
 
       op1_elt = insert (op1, NULL_PTR, op1_hash, mode);
       op1_elt->in_memory = op1_in_memory;
-      op1_elt->in_struct = op1_in_struct;
     }
 
   merge_equiv_classes (op0_elt, op1_elt);
@@ -6241,12 +4461,8 @@ struct set
   unsigned dest_hash;
   /* The SET_DEST, with SUBREG, etc., stripped.  */
   rtx inner_dest;
-  /* Place where the pointer to the INNER_DEST was found.  */
-  rtx *inner_dest_loc;
   /* Nonzero if the SET_SRC is in memory.  */ 
   char src_in_memory;
-  /* Nonzero if the SET_SRC is in a structure.  */ 
-  char src_in_struct;
   /* Nonzero if the SET_SRC contains something
      whose value cannot be predicted and understood.  */
   char src_volatile;
@@ -6254,6 +4470,8 @@ struct set
   enum machine_mode mode;
   /* A constant equivalent for SET_SRC, if any.  */
   rtx src_const;
+  /* Original SET_SRC value used for libcall notes.  */
+  rtx orig_src;
   /* Hash value of constant equivalent for SET_SRC.  */
   unsigned src_const_hash;
   /* Table entry for constant equivalent for SET_SRC, if any.  */
@@ -6278,12 +4496,11 @@ cse_insn (insn, libcall_insn)
 
   rtx src_eqv = 0;
   struct table_elt *src_eqv_elt = 0;
-  int src_eqv_volatile;
-  int src_eqv_in_memory;
-  int src_eqv_in_struct;
-  unsigned src_eqv_hash;
+  int src_eqv_volatile = 0;
+  int src_eqv_in_memory = 0;
+  unsigned src_eqv_hash = 0;
 
-  struct set *sets;
+  struct set *sets = (struct set *) NULL_PTR;
 
   this_insn = insn;
 
@@ -6453,11 +4670,12 @@ cse_insn (insn, libcall_insn)
       rtx new = canon_reg (src, insn);
       int insn_code;
 
+      sets[i].orig_src = src;
       if ((GET_CODE (new) == REG && GET_CODE (src) == REG
           && ((REGNO (new) < FIRST_PSEUDO_REGISTER)
               != (REGNO (src) < FIRST_PSEUDO_REGISTER)))
          || (insn_code = recog_memoized (insn)) < 0
-         || insn_n_dups[insn_code] > 0)
+         || insn_data[insn_code].n_dups > 0)
        validate_change (insn, &SET_SRC (sets[i].rtl), new, 1);
       else
        SET_SRC (sets[i].rtl) = new;
@@ -6529,7 +4747,6 @@ cse_insn (insn, libcall_insn)
            eqvmode = GET_MODE (SUBREG_REG (XEXP (dest, 0)));
          do_not_record = 0;
          hash_arg_in_memory = 0;
-         hash_arg_in_struct = 0;
          src_eqv = fold_rtx (src_eqv, insn);
          src_eqv_hash = HASH (src_eqv, eqvmode);
 
@@ -6540,7 +4757,6 @@ cse_insn (insn, libcall_insn)
 
          src_eqv_volatile = do_not_record;
          src_eqv_in_memory = hash_arg_in_memory;
-         src_eqv_in_struct = hash_arg_in_struct;
        }
 
       /* If this is a STRICT_LOW_PART assignment, src_eqv corresponds to the
@@ -6584,13 +4800,11 @@ cse_insn (insn, libcall_insn)
         prevent any further processing of this assignment.  */
       do_not_record = 0;
       hash_arg_in_memory = 0;
-      hash_arg_in_struct = 0;
 
       sets[i].src = src;
       sets[i].src_hash = HASH (src, mode);
       sets[i].src_volatile = do_not_record;
       sets[i].src_in_memory = hash_arg_in_memory;
-      sets[i].src_in_struct = hash_arg_in_struct;
 
       /* If SRC is a MEM, there is a REG_EQUIV note for SRC, and DEST is
         a pseudo that is set more than once, do not record SRC.  Using
@@ -6956,7 +5170,7 @@ cse_insn (insn, libcall_insn)
          the current contents will be tested and will always be valid.  */
       while (1)
         {
-          rtx trial, old_src;
+          rtx trial;
 
           /* Skip invalid entries.  */
           while (elt && GET_CODE (elt->exp) != REG
@@ -7022,28 +5236,26 @@ cse_insn (insn, libcall_insn)
             insert the substitution here and we will delete and re-emit
             the insn later.  */
 
-         /* Keep track of the original SET_SRC so that we can fix notes
-            on libcall instructions.  */
-         old_src = SET_SRC (sets[i].rtl);
-
          if (n_sets == 1 && dest == pc_rtx
              && (trial == pc_rtx
                  || (GET_CODE (trial) == LABEL_REF
                      && ! condjump_p (insn))))
            {
-             /* If TRIAL is a label in front of a jump table, we are
-                really falling through the switch (this is how casesi
-                insns work), so we must branch around the table.  */
-             if (GET_CODE (trial) == CODE_LABEL
-                 && NEXT_INSN (trial) != 0
-                 && GET_CODE (NEXT_INSN (trial)) == JUMP_INSN
-                 && (GET_CODE (PATTERN (NEXT_INSN (trial))) == ADDR_DIFF_VEC
-                     || GET_CODE (PATTERN (NEXT_INSN (trial))) == ADDR_VEC))
-
-               trial = gen_rtx_LABEL_REF (Pmode, get_label_after (trial));
-
-             SET_SRC (sets[i].rtl) = trial;
-             cse_jumps_altered = 1;
+             if (trial == pc_rtx)
+               {
+                 SET_SRC (sets[i].rtl) = trial;
+                 cse_jumps_altered = 1;
+                 break;
+               }
+
+             PATTERN (insn) = gen_jump (XEXP (trial, 0));
+             INSN_CODE (insn) = -1;
+
+             if (NEXT_INSN (insn) != 0
+                 && GET_CODE (NEXT_INSN (insn)) != BARRIER)
+               emit_barrier_after (insn);
+
+             cse_jumps_altered = 1;
              break;
            }
           
@@ -7054,10 +5266,10 @@ cse_insn (insn, libcall_insn)
                 need to make the same substitution in any notes attached
                 to the RETVAL insn.  */
              if (libcall_insn
-                 && (GET_CODE (old_src) == REG
-                     || GET_CODE (old_src) == SUBREG
-                     ||  GET_CODE (old_src) == MEM))
-               replace_rtx (REG_NOTES (libcall_insn), old_src, 
+                 && (GET_CODE (sets[i].orig_src) == REG
+                     || GET_CODE (sets[i].orig_src) == SUBREG
+                     ||  GET_CODE (sets[i].orig_src) == MEM))
+               replace_rtx (REG_NOTES (libcall_insn), sets[i].orig_src, 
                             canon_reg (SET_SRC (sets[i].rtl), insn));
 
              /* The result of apply_change_group can be ignored; see
@@ -7100,49 +5312,56 @@ cse_insn (insn, libcall_insn)
         both registers live over a portion of the basic block.  This way,
         their lifetimes will likely abut instead of overlapping.  */
       if (GET_CODE (dest) == REG
-         && REGNO_QTY_VALID_P (REGNO (dest))
-         && qty_mode[reg_qty[REGNO (dest)]] == GET_MODE (dest)
-         && qty_first_reg[reg_qty[REGNO (dest)]] != REGNO (dest)
-         && GET_CODE (src) == REG && REGNO (src) == REGNO (dest)
-         /* Don't do this if the original insn had a hard reg as
-            SET_SRC.  */
-         && (GET_CODE (sets[i].src) != REG
-             || REGNO (sets[i].src) >= FIRST_PSEUDO_REGISTER))
-       /* We can't call canon_reg here because it won't do anything if
-          SRC is a hard register.  */
+         && REGNO_QTY_VALID_P (REGNO (dest)))
        {
-         int first = qty_first_reg[reg_qty[REGNO (src)]];
-         rtx new_src
-           = (first >= FIRST_PSEUDO_REGISTER
-              ? regno_reg_rtx[first] : gen_rtx_REG (GET_MODE (src), first));
-
-         /* We must use validate-change even for this, because this
-            might be a special no-op instruction, suitable only to
-            tag notes onto.  */
-         if (validate_change (insn, &SET_SRC (sets[i].rtl), new_src, 0))
+         int dest_q = REG_QTY (REGNO (dest));
+         struct qty_table_elem *dest_ent = &qty_table[dest_q];
+
+         if (dest_ent->mode == GET_MODE (dest)
+             && dest_ent->first_reg != REGNO (dest)
+             && GET_CODE (src) == REG && REGNO (src) == REGNO (dest)
+             /* Don't do this if the original insn had a hard reg as
+                SET_SRC or SET_DEST.  */
+             && (GET_CODE (sets[i].src) != REG
+                 || REGNO (sets[i].src) >= FIRST_PSEUDO_REGISTER)
+             && (GET_CODE (dest) != REG || REGNO (dest) >= FIRST_PSEUDO_REGISTER))
+           /* We can't call canon_reg here because it won't do anything if
+              SRC is a hard register.  */
            {
-             src = new_src;
-             /* If we had a constant that is cheaper than what we are now
-                setting SRC to, use that constant.  We ignored it when we
-                thought we could make this into a no-op.  */
-             if (src_const && COST (src_const) < COST (src)
-                 && validate_change (insn, &SET_SRC (sets[i].rtl), src_const,
-                                     0))
-               src = src_const;
+             int src_q = REG_QTY (REGNO (src));
+             struct qty_table_elem *src_ent = &qty_table[src_q];
+             int first = src_ent->first_reg;
+             rtx new_src
+               = (first >= FIRST_PSEUDO_REGISTER
+                  ? regno_reg_rtx[first] : gen_rtx_REG (GET_MODE (src), first));
+
+             /* We must use validate-change even for this, because this
+                might be a special no-op instruction, suitable only to
+                tag notes onto.  */
+             if (validate_change (insn, &SET_SRC (sets[i].rtl), new_src, 0))
+               {
+                 src = new_src;
+                 /* If we had a constant that is cheaper than what we are now
+                    setting SRC to, use that constant.  We ignored it when we
+                    thought we could make this into a no-op.  */
+                 if (src_const && COST (src_const) < COST (src)
+                     && validate_change (insn, &SET_SRC (sets[i].rtl), src_const,
+                                         0))
+                   src = src_const;
+               }
            }
        }
 
       /* If we made a change, recompute SRC values.  */
       if (src != sets[i].src)
         {
+         cse_altered = 1;
           do_not_record = 0;
           hash_arg_in_memory = 0;
-          hash_arg_in_struct = 0;
          sets[i].src = src;
           sets[i].src_hash = HASH (src, mode);
           sets[i].src_volatile = do_not_record;
           sets[i].src_in_memory = hash_arg_in_memory;
-          sets[i].src_in_struct = hash_arg_in_struct;
           sets[i].src_elt = lookup (src, sets[i].src_hash, mode);
         }
 
@@ -7150,12 +5369,24 @@ cse_insn (insn, libcall_insn)
         equivalent constant, we want to add a REG_NOTE.   We don't want
         to write a REG_EQUAL note for a constant pseudo since verifying that
         that pseudo hasn't been eliminated is a pain.  Such a note also
-        won't help anything.  */
+        won't help anything. 
+
+        Avoid a REG_EQUAL note for (CONST (MINUS (LABEL_REF) (LABEL_REF)))
+        which can be created for a reference to a compile time computable
+        entry in a jump table.  */
+
       if (n_sets == 1 && src_const && GET_CODE (dest) == REG
-         && GET_CODE (src_const) != REG)
+         && GET_CODE (src_const) != REG
+         && ! (GET_CODE (src_const) == CONST
+               && GET_CODE (XEXP (src_const, 0)) == MINUS
+               && GET_CODE (XEXP (XEXP (src_const, 0), 0)) == LABEL_REF
+               && GET_CODE (XEXP (XEXP (src_const, 0), 1)) == LABEL_REF))
        {
          tem = find_reg_note (insn, REG_EQUAL, NULL_RTX);
          
+         /* Make sure that the rtx is not shared with any other insn.  */
+         src_const = copy_rtx (src_const);
+
          /* Record the actual constant value in a REG_EQUAL note, making
             a new one if one does not already exist.  */
          if (tem)
@@ -7175,29 +5406,33 @@ cse_insn (insn, libcall_insn)
             Rather than track each register individually, we just see if
             the last set for this quantity was for this register.  */
 
-         if (REGNO_QTY_VALID_P (REGNO (dest))
-             && qty_const[reg_qty[REGNO (dest)]] == const0_rtx)
+         if (REGNO_QTY_VALID_P (REGNO (dest)))
            {
-             /* See if we previously had a REG_WAS_0 note.  */
-             rtx note = find_reg_note (insn, REG_WAS_0, NULL_RTX);
-             rtx const_insn = qty_const_insn[reg_qty[REGNO (dest)]];
+             int dest_q = REG_QTY (REGNO (dest));
+             struct qty_table_elem *dest_ent = &qty_table[dest_q];
 
-             if ((tem = single_set (const_insn)) != 0
-                 && rtx_equal_p (SET_DEST (tem), dest))
+             if (dest_ent->const_rtx == const0_rtx)
                {
-                 if (note)
-                   XEXP (note, 0) = const_insn;
-                 else
-                   REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_WAS_0,
-                                                         const_insn,
-                                                         REG_NOTES (insn));
+                 /* See if we previously had a REG_WAS_0 note.  */
+                 rtx note = find_reg_note (insn, REG_WAS_0, NULL_RTX);
+                 rtx const_insn = dest_ent->const_insn;
+
+                 if ((tem = single_set (const_insn)) != 0
+                     && rtx_equal_p (SET_DEST (tem), dest))
+                   {
+                     if (note)
+                       XEXP (note, 0) = const_insn;
+                     else
+                       REG_NOTES (insn)
+                         = gen_rtx_INSN_LIST (REG_WAS_0, const_insn,
+                                              REG_NOTES (insn));
+                   }
                }
            }
        }
 
       /* Now deal with the destination.  */
       do_not_record = 0;
-      sets[i].inner_dest_loc = &SET_DEST (sets[0].rtl);
 
       /* Look within any SIGN_EXTRACT or ZERO_EXTRACT
         to the MEM or REG within it.  */
@@ -7205,10 +5440,7 @@ cse_insn (insn, libcall_insn)
             || GET_CODE (dest) == ZERO_EXTRACT
             || GET_CODE (dest) == SUBREG
             || GET_CODE (dest) == STRICT_LOW_PART)
-       {
-         sets[i].inner_dest_loc = &XEXP (dest, 0);
-         dest = XEXP (dest, 0);
-       }
+       dest = XEXP (dest, 0);
 
       sets[i].inner_dest = dest;
 
@@ -7265,13 +5497,13 @@ cse_insn (insn, libcall_insn)
         the insn.  */
       else if (n_sets == 1 && dest == pc_rtx && src == pc_rtx)
        {
+         /* One less use of the label this insn used to jump to.  */
+         if (JUMP_LABEL (insn) != 0)
+           --LABEL_NUSES (JUMP_LABEL (insn));
          PUT_CODE (insn, NOTE);
          NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
          NOTE_SOURCE_FILE (insn) = 0;
          cse_jumps_altered = 1;
-         /* One less use of the label this insn used to jump to.  */
-         if (JUMP_LABEL (insn) != 0)
-           --LABEL_NUSES (JUMP_LABEL (insn));
          /* No more processing for this set.  */
          sets[i].rtl = 0;
        }
@@ -7281,8 +5513,6 @@ cse_insn (insn, libcall_insn)
         it.  If it was a computed branch, delete it and re-emit.  */
       else if (dest == pc_rtx && GET_CODE (src) == LABEL_REF)
        {
-         rtx p;
-
          /* If this is not in the format for a simple branch and
             we are the only SET in it, re-emit it.  */
          if (! simplejump_p (insn) && n_sets == 1)
@@ -7290,7 +5520,6 @@ cse_insn (insn, libcall_insn)
              rtx new = emit_jump_insn_before (gen_jump (XEXP (src, 0)), insn);
              JUMP_LABEL (new) = XEXP (src, 0);
              LABEL_NUSES (XEXP (src, 0))++;
-             delete_insn (insn);
              insn = new;
            }
          else
@@ -7301,39 +5530,13 @@ cse_insn (insn, libcall_insn)
               Until the right place is found, might as well do this here.  */
            INSN_CODE (insn) = -1;
 
-         /* Now that we've converted this jump to an unconditional jump,
-            there is dead code after it.  Delete the dead code until we
-            reach a BARRIER, the end of the function, or a label.  Do
-            not delete NOTEs except for NOTE_INSN_DELETED since later
-            phases assume these notes are retained.  */
-
-         p = insn;
-
-         while (NEXT_INSN (p) != 0
-                && GET_CODE (NEXT_INSN (p)) != BARRIER
-                && GET_CODE (NEXT_INSN (p)) != CODE_LABEL)
-           {
-             if (GET_CODE (NEXT_INSN (p)) != NOTE
-                 || NOTE_LINE_NUMBER (NEXT_INSN (p)) == NOTE_INSN_DELETED)
-               delete_insn (NEXT_INSN (p));
-             else
-               p = NEXT_INSN (p);
-           }
-
-         /* If we don't have a BARRIER immediately after INSN, put one there.
-            Much code assumes that there are no NOTEs between a JUMP_INSN and
-            BARRIER.  */
+         never_reached_warning (insn);
 
-         if (NEXT_INSN (insn) == 0
-             || GET_CODE (NEXT_INSN (insn)) != BARRIER)
-           emit_barrier_before (NEXT_INSN (insn));
-
-         /* We might have two BARRIERs separated by notes.  Delete the second
-            one if so.  */
-
-         if (p != insn && NEXT_INSN (p) != 0
-             && GET_CODE (NEXT_INSN (p)) == BARRIER)
-           delete_insn (NEXT_INSN (p));
+         /* Now emit a BARRIER after the unconditional jump.  Do not bother
+            deleting any unreachable code, let jump/flow do that.  */
+         if (NEXT_INSN (insn) != 0
+             && GET_CODE (NEXT_INSN (insn)) != BARRIER)
+           emit_barrier_after (insn);
 
          cse_jumps_altered = 1;
          sets[i].rtl = 0;
@@ -7401,7 +5604,6 @@ cse_insn (insn, libcall_insn)
        }
       elt = insert (src_eqv, classp, src_eqv_hash, eqvmode);
       elt->in_memory = src_eqv_in_memory;
-      elt->in_struct = src_eqv_in_struct;
       src_eqv_elt = elt;
 
       /* Check to see if src_eqv_elt is the same as a set source which
@@ -7439,22 +5641,30 @@ cse_insn (insn, libcall_insn)
 
            if (sets[i].src_elt == 0)
              {
-               register struct table_elt *elt;
-
-               /* Note that these insert_regs calls cannot remove
-                  any of the src_elt's, because they would have failed to
-                  match if not still valid.  */
-               if (insert_regs (src, classp, 0))
+               /* Don't put a hard register source into the table if this is
+                  the last insn of a libcall.  In this case, we only need
+                  to put src_eqv_elt in src_elt.  */
+               if (GET_CODE (src) != REG
+                   || REGNO (src) >= FIRST_PSEUDO_REGISTER
+                   || ! find_reg_note (insn, REG_RETVAL, NULL_RTX))
                  {
-                   rehash_using_reg (src);
-                   sets[i].src_hash = HASH (src, mode);
+                   register struct table_elt *elt;
+
+                   /* Note that these insert_regs calls cannot remove
+                      any of the src_elt's, because they would have failed to
+                      match if not still valid.  */
+                   if (insert_regs (src, classp, 0))
+                     {
+                       rehash_using_reg (src);
+                       sets[i].src_hash = HASH (src, mode);
+                     }
+                   elt = insert (src, classp, sets[i].src_hash, mode);
+                   elt->in_memory = sets[i].src_in_memory;
+                   sets[i].src_elt = classp = elt;
                  }
-               elt = insert (src, classp, sets[i].src_hash, mode);
-               elt->in_memory = sets[i].src_in_memory;
-               elt->in_struct = sets[i].src_in_struct;
-               sets[i].src_elt = classp = elt;
+               else
+                 sets[i].src_elt = classp;
              }
-
            if (sets[i].src_const && sets[i].src_const_elt == 0
                && src != sets[i].src_const
                && ! rtx_equal_p (sets[i].src_const, src))
@@ -7504,6 +5714,12 @@ cse_insn (insn, libcall_insn)
          invalidate (XEXP (dest, 0), GET_MODE (dest));
       }
 
+  /* A volatile ASM invalidates everything.  */
+  if (GET_CODE (insn) == INSN
+      && GET_CODE (PATTERN (insn)) == ASM_OPERANDS
+      && MEM_VOLATILE_P (PATTERN (insn)))
+    flush_hash_table ();
+
   /* Make sure registers mentioned in destinations
      are safe for use in an expression to be inserted.
      This removes from the hash table
@@ -7525,7 +5741,7 @@ cse_insn (insn, libcall_insn)
              /* We used to rely on all references to a register becoming
                 inaccessible when a register changes to a new quantity,
                 since that changes the hash code.  However, that is not
-                safe, since after NBUCKETS new quantities we get a
+                safe, since after HASH_SIZE new quantities we get a
                 hash 'collision' of a register with its own invalid
                 entries.  And since SUBREGs have been changed not to
                 change their hash code with the hash code of the register,
@@ -7534,18 +5750,18 @@ cse_insn (insn, libcall_insn)
                 This code is similar to the REG case in mention_regs,
                 but it knows that reg_tick has been incremented, and
                 it leaves reg_in_table as -1 .  */
-             register int regno = REGNO (x);
-             register int endregno
+             unsigned int regno = REGNO (x);
+             unsigned int endregno
                = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1
                           : HARD_REGNO_NREGS (regno, GET_MODE (x)));
-             int i;
+             unsigned int i;
 
              for (i = regno; i < endregno; i++)
                {
-                 if (reg_in_table[i] >= 0)
+                 if (REG_IN_TABLE (i) >= 0)
                    {
                      remove_invalid_refs (i);
-                     reg_in_table[i] = -1;
+                     REG_IN_TABLE (i) = -1;
                    }
                }
            }
@@ -7645,15 +5861,6 @@ cse_insn (insn, libcall_insn)
                              || FIXED_BASE_PLUS_P (XEXP (sets[i].inner_dest,
                                                          0))));
 
-       if (elt->in_memory)
-         {
-           /* This implicitly assumes a whole struct
-              need not have MEM_IN_STRUCT_P.
-              But a whole struct is *supposed* to have MEM_IN_STRUCT_P.  */
-           elt->in_struct = (MEM_IN_STRUCT_P (sets[i].inner_dest)
-                             || sets[i].inner_dest != SET_DEST (sets[i].rtl));
-         }
-
        /* If we have (set (subreg:m1 (reg:m2 foo) 0) (bar:m1)), M1 is no
           narrower than M2, and both M1 and M2 are the same number of words,
           we are also doing (set (reg:m2 foo) (subreg:m2 (bar:m1) 0)) so
@@ -7710,7 +5917,6 @@ cse_insn (insn, libcall_insn)
                      }
                    src_elt = insert (new_src, classp, src_hash, new_mode);
                    src_elt->in_memory = elt->in_memory;
-                   src_elt->in_struct = elt->in_struct;
                  }
                else if (classp && classp != src_elt->first_same_value)
                  /* Show that two things that we've seen before are 
@@ -7727,67 +5933,78 @@ cse_insn (insn, libcall_insn)
          }
       }
 
-  /* Special handling for (set REG0 REG1)
-     where REG0 is the "cheapest", cheaper than REG1.
-     After cse, REG1 will probably not be used in the sequel, 
-     so (if easily done) change this insn to (set REG1 REG0) and
-     replace REG1 with REG0 in the previous insn that computed their value.
-     Then REG1 will become a dead store and won't cloud the situation
-     for later optimizations.
+  /* Special handling for (set REG0 REG1) where REG0 is the
+     "cheapest", cheaper than REG1.  After cse, REG1 will probably not
+     be used in the sequel, so (if easily done) change this insn to
+     (set REG1 REG0) and replace REG1 with REG0 in the previous insn
+     that computed their value.  Then REG1 will become a dead store
+     and won't cloud the situation for later optimizations.
 
      Do not make this change if REG1 is a hard register, because it will
      then be used in the sequel and we may be changing a two-operand insn
      into a three-operand insn.
 
-     Also do not do this if we are operating on a copy of INSN.  */
+     Also do not do this if we are operating on a copy of INSN.
+
+     Also don't do this if INSN ends a libcall; this would cause an unrelated
+     register to be set in the middle of a libcall, and we then get bad code
+     if the libcall is deleted.  */
 
   if (n_sets == 1 && sets[0].rtl && GET_CODE (SET_DEST (sets[0].rtl)) == REG
       && NEXT_INSN (PREV_INSN (insn)) == insn
       && GET_CODE (SET_SRC (sets[0].rtl)) == REG
       && REGNO (SET_SRC (sets[0].rtl)) >= FIRST_PSEUDO_REGISTER
-      && REGNO_QTY_VALID_P (REGNO (SET_SRC (sets[0].rtl)))
-      && (qty_first_reg[reg_qty[REGNO (SET_SRC (sets[0].rtl))]]
-         == REGNO (SET_DEST (sets[0].rtl))))
+      && REGNO_QTY_VALID_P (REGNO (SET_SRC (sets[0].rtl))))
     {
-      rtx prev = PREV_INSN (insn);
-      while (prev && GET_CODE (prev) == NOTE)
-       prev = PREV_INSN (prev);
+      int src_q = REG_QTY (REGNO (SET_SRC (sets[0].rtl)));
+      struct qty_table_elem *src_ent = &qty_table[src_q];
 
-      if (prev && GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SET
-         && SET_DEST (PATTERN (prev)) == SET_SRC (sets[0].rtl))
+      if ((src_ent->first_reg == REGNO (SET_DEST (sets[0].rtl)))
+         && ! find_reg_note (insn, REG_RETVAL, NULL_RTX))
        {
-         rtx dest = SET_DEST (sets[0].rtl);
-         rtx note = find_reg_note (prev, REG_EQUIV, NULL_RTX);
+         rtx prev = prev_nonnote_insn (insn);
 
-         validate_change (prev, & SET_DEST (PATTERN (prev)), dest, 1);
-         validate_change (insn, & SET_DEST (sets[0].rtl),
-                          SET_SRC (sets[0].rtl), 1);
-         validate_change (insn, & SET_SRC (sets[0].rtl), dest, 1);
-         apply_change_group ();
+         if (prev != 0 && GET_CODE (prev) == INSN
+             && GET_CODE (PATTERN (prev)) == SET
+             && SET_DEST (PATTERN (prev)) == SET_SRC (sets[0].rtl))
+           {
+             rtx dest = SET_DEST (sets[0].rtl);
+             rtx src = SET_SRC (sets[0].rtl);
+             rtx note = find_reg_note (prev, REG_EQUIV, NULL_RTX);
 
-         /* If REG1 was equivalent to a constant, REG0 is not.  */
-         if (note)
-           PUT_REG_NOTE_KIND (note, REG_EQUAL);
+             validate_change (prev, & SET_DEST (PATTERN (prev)), dest, 1);
+             validate_change (insn, & SET_DEST (sets[0].rtl), src, 1);
+             validate_change (insn, & SET_SRC (sets[0].rtl), dest, 1);
+             apply_change_group ();
 
-         /* If there was a REG_WAS_0 note on PREV, remove it.  Move
-            any REG_WAS_0 note on INSN to PREV.  */
-         note = find_reg_note (prev, REG_WAS_0, NULL_RTX);
-         if (note)
-           remove_note (prev, note);
+             /* If REG1 was equivalent to a constant, REG0 is not.  */
+             if (note)
+               PUT_REG_NOTE_KIND (note, REG_EQUAL);
 
-         note = find_reg_note (insn, REG_WAS_0, NULL_RTX);
-         if (note)
-           {
-             remove_note (insn, note);
-             XEXP (note, 1) = REG_NOTES (prev);
-             REG_NOTES (prev) = note;
-           }
+             /* If there was a REG_WAS_0 note on PREV, remove it.  Move
+                any REG_WAS_0 note on INSN to PREV.  */
+             note = find_reg_note (prev, REG_WAS_0, NULL_RTX);
+             if (note)
+               remove_note (prev, note);
 
-         /* If INSN has a REG_EQUAL note, and this note mentions REG0,
-            then we must delete it, because the value in REG0 has changed.  */
-         note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
-         if (note && reg_mentioned_p (dest, XEXP (note, 0)))
-           remove_note (insn, note);
+             note = find_reg_note (insn, REG_WAS_0, NULL_RTX);
+             if (note)
+               {
+                 remove_note (insn, note);
+                 XEXP (note, 1) = REG_NOTES (prev);
+                 REG_NOTES (prev) = note;
+               }
+
+             /* If INSN has a REG_EQUAL note, and this note mentions
+                REG0, then we must delete it, because the value in
+                REG0 has changed.  If the note's value is REG1, we must
+                also delete it because that is now this insn's dest.  */
+             note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
+             if (note != 0
+                 && (reg_mentioned_p (dest, XEXP (note, 0))
+                     || rtx_equal_p (src, XEXP (note, 0))))
+               remove_note (insn, note);
+           }
        }
     }
 
@@ -7821,14 +6038,15 @@ cse_insn (insn, libcall_insn)
   prev_insn = insn;
 }
 \f
-/* Remove from the ahsh table all expressions that reference memory.  */
+/* Remove from the hash table all expressions that reference memory.  */
+
 static void
 invalidate_memory ()
 {
   register int i;
   register struct table_elt *p, *next;
 
-  for (i = 0; i < NBUCKETS; i++)
+  for (i = 0; i < HASH_SIZE; i++)
     for (p = table[i]; p; p = next)
       {
        next = p->next_same_hash;
@@ -7837,26 +6055,28 @@ invalidate_memory ()
       }
 }
 
-/* XXX ??? The name of this function bears little resemblance to
-   what this function actually does.  FIXME.  */
+/* If ADDR is an address that implicitly affects the stack pointer, return
+   1 and update the register tables to show the effect.  Else, return 0.  */
+
 static int
-note_mem_written (addr)
+addr_affects_sp_p (addr)
      register rtx addr;
 {
-  /* Pushing or popping the stack invalidates just the stack pointer.  */
   if ((GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
        || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
       && GET_CODE (XEXP (addr, 0)) == REG
       && REGNO (XEXP (addr, 0)) == STACK_POINTER_REGNUM)
     {
-      if (reg_tick[STACK_POINTER_REGNUM] >= 0)
-       reg_tick[STACK_POINTER_REGNUM]++;
+      if (REG_TICK (STACK_POINTER_REGNUM) >= 0)
+       REG_TICK (STACK_POINTER_REGNUM)++;
 
       /* This should be *very* rare.  */
       if (TEST_HARD_REG_BIT (hard_regs_in_table, STACK_POINTER_REGNUM))
        invalidate (stack_pointer_rtx, VOIDmode);
+
       return 1;
     }
+
   return 0;
 }
 
@@ -7919,7 +6139,7 @@ cse_process_notes (x, object)
      rtx object;
 {
   enum rtx_code code = GET_CODE (x);
-  char *fmt = GET_RTX_FORMAT (code);
+  const char *fmt = GET_RTX_FORMAT (code);
   int i;
 
   switch (code)
@@ -7959,17 +6179,21 @@ cse_process_notes (x, object)
       }
 
     case REG:
-      i = reg_qty[REGNO (x)];
+      i = REG_QTY (REGNO (x));
 
       /* Return a constant or a constant register.  */
-      if (REGNO_QTY_VALID_P (REGNO (x))
-         && qty_const[i] != 0
-         && (CONSTANT_P (qty_const[i])
-             || GET_CODE (qty_const[i]) == REG))
+      if (REGNO_QTY_VALID_P (REGNO (x)))
        {
-         rtx new = gen_lowpart_if_possible (GET_MODE (x), qty_const[i]);
-         if (new)
-           return new;
+         struct qty_table_elem *ent = &qty_table[i];
+
+         if (ent->const_rtx != NULL_RTX
+             && (CONSTANT_P (ent->const_rtx)
+                 || GET_CODE (ent->const_rtx) == REG))
+           {
+             rtx new = gen_lowpart_if_possible (GET_MODE (x), ent->const_rtx);
+             if (new)
+               return new;
+           }
        }
 
       /* Otherwise, canonicalize this register.  */
@@ -8075,14 +6299,15 @@ cse_around_loop (loop_start)
    since they are done elsewhere.  This function is called via note_stores.  */
 
 static void
-invalidate_skipped_set (dest, set)
+invalidate_skipped_set (dest, set, data)
      rtx set;
      rtx dest;
+     void *data ATTRIBUTE_UNUSED;
 {
   enum rtx_code code = GET_CODE (dest);
 
   if (code == MEM
-      && ! note_mem_written (dest)     /* If this is not a stack push ... */
+      && ! addr_affects_sp_p (dest)    /* If this is not a stack push ... */
       /* There are times when an address can appear varying and be a PLUS
         during this scan when it would be a fixed address were we to know
         the proper equivalences.  So invalidate all memory if there is
@@ -8132,30 +6357,29 @@ invalidate_skipped_block (start)
        }
 
       invalidate_from_clobbers (PATTERN (insn));
-      note_stores (PATTERN (insn), invalidate_skipped_set);
+      note_stores (PATTERN (insn), invalidate_skipped_set, NULL);
     }
 }
 \f
-/* Used for communication between the following two routines; contains a
-   value to be checked for modification.  */
-
-static rtx cse_check_loop_start_value;
-
-/* If modifying X will modify the value in CSE_CHECK_LOOP_START_VALUE,
-   indicate that fact by setting CSE_CHECK_LOOP_START_VALUE to 0.  */
+/* If modifying X will modify the value in *DATA (which is really an
+   `rtx *'), indicate that fact by setting the pointed to value to
+   NULL_RTX.  */
 
 static void
-cse_check_loop_start (x, set)
+cse_check_loop_start (x, set, data)
      rtx x;
      rtx set ATTRIBUTE_UNUSED;
+     void *data;
 {
-  if (cse_check_loop_start_value == 0
+  rtx *cse_check_loop_start_value = (rtx *) data;
+
+  if (*cse_check_loop_start_value == NULL_RTX
       || GET_CODE (x) == CC0 || GET_CODE (x) == PC)
     return;
 
-  if ((GET_CODE (x) == MEM && GET_CODE (cse_check_loop_start_value) == MEM)
-      || reg_overlap_mentioned_p (x, cse_check_loop_start_value))
-    cse_check_loop_start_value = 0;
+  if ((GET_CODE (x) == MEM && GET_CODE (*cse_check_loop_start_value) == MEM)
+      || reg_overlap_mentioned_p (x, *cse_check_loop_start_value))
+    *cse_check_loop_start_value = NULL_RTX;
 }
 
 /* X is a SET or CLOBBER contained in INSN that was found near the start of
@@ -8220,11 +6444,12 @@ cse_set_around_loop (x, insn, loop_start)
                       can modify it, or we would have invalidated it in
                       the hash table.  */
                    rtx q;
-
-                   cse_check_loop_start_value = SET_SRC (x);
+                   rtx cse_check_loop_start_value = SET_SRC (x);
                    for (q = p; q != loop_start; q = NEXT_INSN (q))
                      if (GET_RTX_CLASS (GET_CODE (q)) == 'i')
-                       note_stores (PATTERN (q), cse_check_loop_start);
+                       note_stores (PATTERN (q),
+                                    cse_check_loop_start,
+                                    &cse_check_loop_start_value);
 
                    /* If nothing was changed and we can replace our
                       SET_SRC, add an insn after P to copy its destination
@@ -8255,10 +6480,11 @@ cse_set_around_loop (x, insn, loop_start)
            }
     }
 
-  /* Now invalidate anything modified by X.  */
-  note_mem_written (SET_DEST (x));
+  /* Deal with the destination of X affecting the stack pointer.  */
+  addr_affects_sp_p (SET_DEST (x));
 
-  /* See comment on similar code in cse_insn for explanation of these tests.  */
+  /* See comment on similar code in cse_insn for explanation of these
+     tests.  */
   if (GET_CODE (SET_DEST (x)) == REG || GET_CODE (SET_DEST (x)) == SUBREG
       || GET_CODE (SET_DEST (x)) == MEM)
     invalidate (SET_DEST (x), VOIDmode);
@@ -8312,6 +6538,15 @@ cse_end_of_basic_block (insn, data, follow_jumps, after_loop, skip_blocks)
        path_size--;
     }
 
+  /* If the first instruction is marked with QImode, that means we've
+     already processed this block.  Our caller will look at DATA->LAST
+     to figure out where to go next.  We want to return the next block
+     in the instruction stream, not some branched-to block somewhere
+     else.  We accomplish this by pretending our called forbid us to
+     follow jumps, or skip blocks.  */
+  if (GET_MODE (insn) == QImode)
+    follow_jumps = skip_blocks = 0;
+
   /* Scan to end of this basic block.  */
   while (p && GET_CODE (p) != CODE_LABEL)
     {
@@ -8517,20 +6752,8 @@ cse_main (f, nregs, after_loop, file)
 
   max_insn_uid = get_max_uid ();
 
-  all_minus_one = (int *) alloca (nregs * sizeof (int));
-  consec_ints = (int *) alloca (nregs * sizeof (int));
-
-  for (i = 0; i < nregs; i++)
-    {
-      all_minus_one[i] = -1;
-      consec_ints[i] = i;
-    }
-
-  reg_next_eqv = (int *) alloca (nregs * sizeof (int));
-  reg_prev_eqv = (int *) alloca (nregs * sizeof (int));
-  reg_qty = (int *) alloca (nregs * sizeof (int));
-  reg_in_table = (int *) alloca (nregs * sizeof (int));
-  reg_tick = (int *) alloca (nregs * sizeof (int));
+  reg_eqv_table = (struct reg_eqv_elem *)
+    xmalloc (nregs * sizeof (struct reg_eqv_elem));
 
 #ifdef LOAD_EXTEND_OP
 
@@ -8548,8 +6771,7 @@ cse_main (f, nregs, after_loop, file)
   /* Find the largest uid.  */
 
   max_uid = get_max_uid ();
-  uid_cuid = (int *) alloca ((max_uid + 1) * sizeof (int));
-  bzero ((char *) uid_cuid, (max_uid + 1) * sizeof (int));
+  uid_cuid = (int *) xcalloc (max_uid + 1, sizeof (int));
 
   /* Compute the mapping from uids to cuids.
      CUIDs are numbers assigned to insns, like uids,
@@ -8598,12 +6820,16 @@ cse_main (f, nregs, after_loop, file)
        || global_regs[i])
       SET_HARD_REG_BIT (regs_invalidated_by_call, i);
 
+  if (ggc_p)
+    ggc_push_context ();
+
   /* Loop over basic blocks.
      Compute the maximum number of qty's needed for each basic block
      (which is 2 for each SET).  */
   insn = f;
   while (insn)
     {
+      cse_altered = 0;
       cse_end_of_basic_block (insn, &val, flag_cse_follow_jumps, after_loop,
                              flag_cse_skip_blocks);
 
@@ -8654,17 +6880,25 @@ cse_main (f, nregs, after_loop, file)
          cse_jumps_altered |= old_cse_jumps_altered;
        }
 
+      if (ggc_p && cse_altered)
+       ggc_collect ();
+
 #ifdef USE_C_ALLOCA
       alloca (0);
 #endif
     }
 
-  /* Tell refers_to_mem_p that qty_const info is not available.  */
-  qty_const = 0;
+  if (ggc_p)
+    ggc_pop_context ();
 
   if (max_elements_made < n_elements_made)
     max_elements_made = n_elements_made;
 
+  /* Clean up.  */
+  end_alias_analysis ();
+  free (uid_cuid);
+  free (reg_eqv_table);
+
   return cse_jumps_altered || recorded_label_ref;
 }
 
@@ -8687,27 +6921,13 @@ cse_basic_block (from, to, next_branch, around_loop)
   rtx libcall_insn = NULL_RTX;
   int num_insns = 0;
 
-  /* Each of these arrays is undefined before max_reg, so only allocate
-     the space actually needed and adjust the start below.  */
-
-  qty_first_reg = (int *) alloca ((max_qty - max_reg) * sizeof (int));
-  qty_last_reg = (int *) alloca ((max_qty - max_reg) * sizeof (int));
-  qty_mode= (enum machine_mode *) alloca ((max_qty - max_reg) * sizeof (enum machine_mode));
-  qty_const = (rtx *) alloca ((max_qty - max_reg) * sizeof (rtx));
-  qty_const_insn = (rtx *) alloca ((max_qty - max_reg) * sizeof (rtx));
-  qty_comparison_code
-    = (enum rtx_code *) alloca ((max_qty - max_reg) * sizeof (enum rtx_code));
-  qty_comparison_qty = (int *) alloca ((max_qty - max_reg) * sizeof (int));
-  qty_comparison_const = (rtx *) alloca ((max_qty - max_reg) * sizeof (rtx));
-
-  qty_first_reg -= max_reg;
-  qty_last_reg -= max_reg;
-  qty_mode -= max_reg;
-  qty_const -= max_reg;
-  qty_const_insn -= max_reg;
-  qty_comparison_code -= max_reg;
-  qty_comparison_qty -= max_reg;
-  qty_comparison_const -= max_reg;
+  /* This array is undefined before max_reg, so only allocate
+     the space actually needed and adjust the start.  */
+
+  qty_table
+    = (struct qty_table_elem *) xmalloc ((max_qty - max_reg)
+                                         * sizeof (struct qty_table_elem));
+  qty_table -= max_reg;
 
   new_basic_block ();
 
@@ -8718,12 +6938,10 @@ cse_basic_block (from, to, next_branch, around_loop)
   for (insn = from; insn != to; insn = NEXT_INSN (insn))
     {
       register enum rtx_code code = GET_CODE (insn);
-      int i;
-      struct table_elt *p;
 
       /* If we have processed 1,000 insns, flush the hash table to
         avoid extreme quadratic behavior.  We must not include NOTEs
-        in the count since there may be more or them when generating
+        in the count since there may be more of them when generating
         debugging information.  If we clear the table at different
         times, code generated with -g -O might be different than code
         generated with -O but not -g.
@@ -8732,17 +6950,7 @@ cse_basic_block (from, to, next_branch, around_loop)
         Perhaps for 2.9.  */
       if (code != NOTE && num_insns++ > 1000)
        {
-         for (i = 0; i < NBUCKETS; i++)
-           for (p = table[i]; p; p = table[i])
-             {
-               /* Note that invalidate can remove elements
-                  after P in the current hash chain.  */
-               if (GET_CODE (p->exp) == REG)
-                 invalidate (p->exp, p->mode);
-               else
-                 remove_from_table (p, i);
-             }
-
+         flush_hash_table ();
          num_insns = 0;
        }
 
@@ -8804,7 +7012,10 @@ cse_basic_block (from, to, next_branch, around_loop)
       if (simplejump_p (insn))
        {
          if (to == 0)
-           return 0;
+           {
+             free (qty_table + max_reg);
+             return 0;
+           }
 
          if (JUMP_LABEL (insn) == to)
            to_usage = 1;
@@ -8834,18 +7045,21 @@ cse_basic_block (from, to, next_branch, around_loop)
 
          insn = NEXT_INSN (to);
 
-         if (LABEL_NUSES (to) == 0)
-           insn = delete_insn (to);
-
          /* If TO was the last insn in the function, we are done.  */
          if (insn == 0)
-           return 0;
+           {
+             free (qty_table + max_reg);
+             return 0;
+           }
 
          /* If TO was preceded by a BARRIER we are done with this block
             because it has no continuation.  */
          prev = prev_nonnote_insn (to);
          if (prev && GET_CODE (prev) == BARRIER)
-           return insn;
+           {
+             free (qty_table + max_reg);
+             return insn;
+           }
 
          /* Find the end of the following block.  Note that we won't be
             following branches in this case.  */
@@ -8890,6 +7104,8 @@ cse_basic_block (from, to, next_branch, around_loop)
       && LABEL_NUSES (JUMP_LABEL (PREV_INSN (to))) == 1)
     cse_around_loop (JUMP_LABEL (PREV_INSN (to)));
 
+  free (qty_table + max_reg);
+
   return to ? NEXT_INSN (to) : 0;
 }
 \f
@@ -8909,7 +7125,7 @@ count_reg_usage (x, counts, dest, incr)
      int incr;
 {
   enum rtx_code code;
-  char *fmt;
+  const char *fmt;
   int i, j;
 
   if (x == 0)
@@ -9004,7 +7220,7 @@ delete_trivially_dead_insns (insns, nreg)
      rtx insns;
      int nreg;
 {
-  int *counts = (int *) alloca (nreg * sizeof (int));
+  int *counts;
   rtx insn, prev;
 #ifdef HAVE_cc0
   rtx tem;
@@ -9013,14 +7229,22 @@ delete_trivially_dead_insns (insns, nreg)
   int in_libcall = 0, dead_libcall = 0;
 
   /* First count the number of times each register is used.  */
-  bzero ((char *) counts, sizeof (int) * nreg);
+  counts = (int *) xcalloc (nreg, sizeof (int));
   for (insn = next_real_insn (insns); insn; insn = next_real_insn (insn))
     count_reg_usage (insn, counts, NULL_RTX, 1);
 
   /* Go from the last insn to the first and delete insns that only set unused
      registers or copy a register to itself.  As we delete an insn, remove
-     usage counts for registers it uses.  */
-  for (insn = prev_real_insn (get_last_insn ()); insn; insn = prev)
+     usage counts for registers it uses. 
+
+     The first jump optimization pass may leave a real insn as the last
+     insn in the function.   We must not skip that insn or we may end
+     up deleting code that is not really dead.   */
+  insn = get_last_insn ();
+  if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
+    insn = prev_real_insn (insn);
+
+  for ( ; insn; insn = prev)
     {
       int live_insn = 0;
       rtx note;
@@ -9047,8 +7271,12 @@ delete_trivially_dead_insns (insns, nreg)
          if (note)
            {
              rtx set = single_set (insn);
-             if (set
-                 && validate_change (insn, &SET_SRC (set), XEXP (note, 0), 0))
+             rtx new = simplify_rtx (XEXP (note, 0));
+
+             if (!new)
+               new = XEXP (note, 0);
+
+             if (set && validate_change (insn, &SET_SRC (set), new, 0))
                {
                  remove_note (insn,
                               find_reg_note (insn, REG_RETVAL, NULL_RTX));
@@ -9060,8 +7288,14 @@ delete_trivially_dead_insns (insns, nreg)
        live_insn = ! dead_libcall;
       else if (GET_CODE (PATTERN (insn)) == SET)
        {
-         if (GET_CODE (SET_DEST (PATTERN (insn))) == REG
-             && SET_DEST (PATTERN (insn)) == SET_SRC (PATTERN (insn)))
+         if ((GET_CODE (SET_DEST (PATTERN (insn))) == REG
+              || GET_CODE (SET_DEST (PATTERN (insn))) == SUBREG)
+             && rtx_equal_p (SET_DEST (PATTERN (insn)),
+                             SET_SRC (PATTERN (insn))))
+           ;
+         else if (GET_CODE (SET_DEST (PATTERN (insn))) == STRICT_LOW_PART
+                  && rtx_equal_p (XEXP (SET_DEST (PATTERN (insn)), 0),
+                                  SET_SRC (PATTERN (insn))))
            ;
 
 #ifdef HAVE_cc0
@@ -9075,7 +7309,13 @@ delete_trivially_dead_insns (insns, nreg)
          else if (GET_CODE (SET_DEST (PATTERN (insn))) != REG
                   || REGNO (SET_DEST (PATTERN (insn))) < FIRST_PSEUDO_REGISTER
                   || counts[REGNO (SET_DEST (PATTERN (insn)))] != 0
-                  || side_effects_p (SET_SRC (PATTERN (insn))))
+                  || side_effects_p (SET_SRC (PATTERN (insn)))
+                  /* An ADDRESSOF expression can turn into a use of the
+                     internal arg pointer, so always consider the
+                     internal arg pointer live.  If it is truly dead,
+                     flow will delete the initializing insn.  */
+                  || (SET_DEST (PATTERN (insn))
+                      == current_function_internal_arg_pointer))
            live_insn = 1;
        }
       else if (GET_CODE (PATTERN (insn)) == PARALLEL)
@@ -9085,8 +7325,9 @@ delete_trivially_dead_insns (insns, nreg)
 
            if (GET_CODE (elt) == SET)
              {
-               if (GET_CODE (SET_DEST (elt)) == REG
-                   && SET_DEST (elt) == SET_SRC (elt))
+               if ((GET_CODE (SET_DEST (elt)) == REG
+                    || GET_CODE (SET_DEST (elt)) == SUBREG)
+                   && rtx_equal_p (SET_DEST (elt), SET_SRC (elt)))
                  ;
 
 #ifdef HAVE_cc0
@@ -9100,7 +7341,13 @@ delete_trivially_dead_insns (insns, nreg)
                else if (GET_CODE (SET_DEST (elt)) != REG
                         || REGNO (SET_DEST (elt)) < FIRST_PSEUDO_REGISTER
                         || counts[REGNO (SET_DEST (elt))] != 0
-                        || side_effects_p (SET_SRC (elt)))
+                        || side_effects_p (SET_SRC (elt))
+                        /* An ADDRESSOF expression can turn into a use of the
+                           internal arg pointer, so always consider the
+                           internal arg pointer live.  If it is truly dead,
+                           flow will delete the initializing insn.  */
+                        || (SET_DEST (elt)
+                            == current_function_internal_arg_pointer))
                  live_insn = 1;
              }
            else if (GET_CODE (elt) != CLOBBER && GET_CODE (elt) != USE)
@@ -9124,4 +7371,7 @@ delete_trivially_dead_insns (insns, nreg)
          dead_libcall = 0;
        }
     }
+
+  /* Clean up.  */
+  free (counts);
 }