OSDN Git Service

* config/h8300/h8300.md (*movsf_h8300h): Change to
[pf3gnuchains/gcc-fork.git] / gcc / gcse.c
index 5525ffe..8f9f13a 100644 (file)
@@ -165,7 +165,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "ggc.h"
 #include "params.h"
 #include "cselib.h"
-
+#include "intl.h"
 #include "obstack.h"
 
 /* Propagate flow information through back edges and thus enable PRE's
@@ -548,174 +548,171 @@ struct null_pointer_info
   sbitmap *nonnull_killed;
 };
 \f
-static void compute_can_copy   PARAMS ((void));
-static char *gmalloc           PARAMS ((unsigned int));
-static char *grealloc          PARAMS ((char *, unsigned int));
-static char *gcse_alloc                PARAMS ((unsigned long));
-static void alloc_gcse_mem     PARAMS ((rtx));
-static void free_gcse_mem      PARAMS ((void));
-static void alloc_reg_set_mem  PARAMS ((int));
-static void free_reg_set_mem   PARAMS ((void));
-static int get_bitmap_width     PARAMS ((int, int, int));
-static void record_one_set     PARAMS ((int, rtx));
-static void record_set_info    PARAMS ((rtx, rtx, void *));
-static void compute_sets       PARAMS ((rtx));
-static void hash_scan_insn     PARAMS ((rtx, struct hash_table *, int));
-static void hash_scan_set      PARAMS ((rtx, rtx, struct hash_table *));
-static void hash_scan_clobber  PARAMS ((rtx, rtx, struct hash_table *));
-static void hash_scan_call     PARAMS ((rtx, rtx, struct hash_table *));
-static int want_to_gcse_p      PARAMS ((rtx));
-static bool gcse_constant_p    PARAMS ((rtx));
-static int oprs_unchanged_p    PARAMS ((rtx, rtx, int));
-static int oprs_anticipatable_p PARAMS ((rtx, rtx));
-static int oprs_available_p    PARAMS ((rtx, rtx));
-static void insert_expr_in_table PARAMS ((rtx, enum machine_mode, rtx,
-                                         int, int, struct hash_table *));
-static void insert_set_in_table PARAMS ((rtx, rtx, struct hash_table *));
-static unsigned int hash_expr  PARAMS ((rtx, enum machine_mode, int *, int));
-static unsigned int hash_expr_1 PARAMS ((rtx, enum machine_mode, int *));
-static unsigned int hash_string_1 PARAMS ((const char *));
-static unsigned int hash_set   PARAMS ((int, int));
-static int expr_equiv_p                PARAMS ((rtx, rtx));
-static void record_last_reg_set_info PARAMS ((rtx, int));
-static void record_last_mem_set_info PARAMS ((rtx));
-static void record_last_set_info PARAMS ((rtx, rtx, void *));
-static void compute_hash_table PARAMS ((struct hash_table *));
-static void alloc_hash_table PARAMS ((int, struct hash_table *, int));
-static void free_hash_table PARAMS ((struct hash_table *));
-static void compute_hash_table_work PARAMS ((struct hash_table *));
-static void dump_hash_table    PARAMS ((FILE *, const char *,
-                                       struct hash_table *));
-static struct expr *lookup_expr        PARAMS ((rtx, struct hash_table *));
-static struct expr *lookup_set PARAMS ((unsigned int, struct hash_table *));
-static struct expr *next_set   PARAMS ((unsigned int, struct expr *));
-static void reset_opr_set_tables PARAMS ((void));
-static int oprs_not_set_p      PARAMS ((rtx, rtx));
-static void mark_call          PARAMS ((rtx));
-static void mark_set           PARAMS ((rtx, rtx));
-static void mark_clobber       PARAMS ((rtx, rtx));
-static void mark_oprs_set      PARAMS ((rtx));
-static void alloc_cprop_mem    PARAMS ((int, int));
-static void free_cprop_mem     PARAMS ((void));
-static void compute_transp     PARAMS ((rtx, int, sbitmap *, int));
-static void compute_transpout  PARAMS ((void));
-static void compute_local_properties PARAMS ((sbitmap *, sbitmap *, sbitmap *,
-                                             struct hash_table *));
-static void compute_cprop_data PARAMS ((void));
-static void find_used_regs     PARAMS ((rtx *, void *));
-static int try_replace_reg     PARAMS ((rtx, rtx, rtx));
-static struct expr *find_avail_set PARAMS ((int, rtx));
-static int cprop_jump          PARAMS ((basic_block, rtx, rtx, rtx, rtx));
-static void mems_conflict_for_gcse_p PARAMS ((rtx, rtx, void *));
-static int load_killed_in_block_p    PARAMS ((basic_block, int, rtx, int));
-static void canon_list_insert        PARAMS ((rtx, rtx, void *));
-static int cprop_insn          PARAMS ((rtx, int));
-static int cprop               PARAMS ((int));
-static void find_implicit_sets PARAMS ((void));
-static int one_cprop_pass      PARAMS ((int, int, int));
-static bool constprop_register PARAMS ((rtx, rtx, rtx, int));
-static struct expr *find_bypass_set PARAMS ((int, int));
-static bool reg_killed_on_edge     PARAMS ((rtx, edge));
-static int bypass_block                    PARAMS ((basic_block, rtx, rtx));
-static int bypass_conditional_jumps PARAMS ((void));
-static void alloc_pre_mem      PARAMS ((int, int));
-static void free_pre_mem       PARAMS ((void));
-static void compute_pre_data   PARAMS ((void));
-static int pre_expr_reaches_here_p PARAMS ((basic_block, struct expr *,
-                                           basic_block));
-static void insert_insn_end_bb PARAMS ((struct expr *, basic_block, int));
-static void pre_insert_copy_insn PARAMS ((struct expr *, rtx));
-static void pre_insert_copies  PARAMS ((void));
-static int pre_delete          PARAMS ((void));
-static int pre_gcse            PARAMS ((void));
-static int one_pre_gcse_pass   PARAMS ((int));
-static void add_label_notes    PARAMS ((rtx, rtx));
-static void alloc_code_hoist_mem PARAMS ((int, int));
-static void free_code_hoist_mem        PARAMS ((void));
-static void compute_code_hoist_vbeinout        PARAMS ((void));
-static void compute_code_hoist_data PARAMS ((void));
-static int hoist_expr_reaches_here_p PARAMS ((basic_block, int, basic_block,
-                                             char *));
-static void hoist_code         PARAMS ((void));
-static int one_code_hoisting_pass PARAMS ((void));
-static void alloc_rd_mem       PARAMS ((int, int));
-static void free_rd_mem                PARAMS ((void));
-static void handle_rd_kill_set PARAMS ((rtx, int, basic_block));
-static void compute_kill_rd    PARAMS ((void));
-static void compute_rd         PARAMS ((void));
-static void alloc_avail_expr_mem PARAMS ((int, int));
-static void free_avail_expr_mem PARAMS ((void));
-static void compute_ae_gen     PARAMS ((struct hash_table *));
-static int expr_killed_p       PARAMS ((rtx, basic_block));
-static void compute_ae_kill    PARAMS ((sbitmap *, sbitmap *, struct hash_table *));
-static int expr_reaches_here_p PARAMS ((struct occr *, struct expr *,
-                                        basic_block, int));
-static rtx computing_insn      PARAMS ((struct expr *, rtx));
-static int def_reaches_here_p  PARAMS ((rtx, rtx));
-static int can_disregard_other_sets PARAMS ((struct reg_set **, rtx, int));
-static int handle_avail_expr   PARAMS ((rtx, struct expr *));
-static int classic_gcse                PARAMS ((void));
-static int one_classic_gcse_pass PARAMS ((int));
-static void invalidate_nonnull_info PARAMS ((rtx, rtx, void *));
-static int delete_null_pointer_checks_1 PARAMS ((unsigned int *,
-                                                 sbitmap *, sbitmap *,
-                                                 struct null_pointer_info *));
-static rtx process_insert_insn PARAMS ((struct expr *));
-static int pre_edge_insert     PARAMS ((struct edge_list *, struct expr **));
-static int expr_reaches_here_p_work PARAMS ((struct occr *, struct expr *,
-                                            basic_block, int, char *));
-static int pre_expr_reaches_here_p_work        PARAMS ((basic_block, struct expr *,
-                                                basic_block, char *));
-static struct ls_expr * ldst_entry     PARAMS ((rtx));
-static void free_ldst_entry            PARAMS ((struct ls_expr *));
-static void free_ldst_mems             PARAMS ((void));
-static void print_ldst_list            PARAMS ((FILE *));
-static struct ls_expr * find_rtx_in_ldst PARAMS ((rtx));
-static int enumerate_ldsts             PARAMS ((void));
-static inline struct ls_expr * first_ls_expr PARAMS ((void));
-static inline struct ls_expr * next_ls_expr  PARAMS ((struct ls_expr *));
-static int simple_mem                  PARAMS ((rtx));
-static void invalidate_any_buried_refs PARAMS ((rtx));
-static void compute_ld_motion_mems     PARAMS ((void));
-static void trim_ld_motion_mems                PARAMS ((void));
-static void update_ld_motion_stores    PARAMS ((struct expr *));
-static void reg_set_info               PARAMS ((rtx, rtx, void *));
-static bool store_ops_ok               PARAMS ((rtx, int *));
-static rtx extract_mentioned_regs      PARAMS ((rtx));
-static rtx extract_mentioned_regs_helper PARAMS ((rtx, rtx));
-static void find_moveable_store                PARAMS ((rtx, int *, int *));
-static int compute_store_table         PARAMS ((void));
-static bool load_kills_store           PARAMS ((rtx, rtx));
-static bool find_loads                 PARAMS ((rtx, rtx));
-static bool store_killed_in_insn       PARAMS ((rtx, rtx, rtx));
-static bool store_killed_after         PARAMS ((rtx, rtx, rtx, basic_block,
-                                                int *, rtx *));
-static bool store_killed_before                PARAMS ((rtx, rtx, rtx, basic_block,
-                                                int *));
-static void build_store_vectors                PARAMS ((void));
-static void insert_insn_start_bb       PARAMS ((rtx, basic_block));
-static int insert_store                        PARAMS ((struct ls_expr *, edge));
-static void replace_store_insn         PARAMS ((rtx, rtx, basic_block));
-static void delete_store               PARAMS ((struct ls_expr *,
-                                                basic_block));
-static void free_store_memory          PARAMS ((void));
-static void store_motion               PARAMS ((void));
-static void free_insn_expr_list_list   PARAMS ((rtx *));
-static void clear_modify_mem_tables    PARAMS ((void));
-static void free_modify_mem_tables     PARAMS ((void));
-static rtx gcse_emit_move_after                PARAMS ((rtx, rtx, rtx));
-static void local_cprop_find_used_regs PARAMS ((rtx *, void *));
-static bool do_local_cprop             PARAMS ((rtx, rtx, int, rtx*));
-static bool adjust_libcall_notes       PARAMS ((rtx, rtx, rtx, rtx*));
-static void local_cprop_pass           PARAMS ((int));
+static void compute_can_copy (void);
+static void *gmalloc (size_t) ATTRIBUTE_MALLOC;
+static void *gcalloc (size_t, size_t) ATTRIBUTE_MALLOC;
+static void *grealloc (void *, size_t);
+static void *gcse_alloc (unsigned long);
+static void alloc_gcse_mem (rtx);
+static void free_gcse_mem (void);
+static void alloc_reg_set_mem (int);
+static void free_reg_set_mem (void);
+static int get_bitmap_width (int, int, int);
+static void record_one_set (int, rtx);
+static void replace_one_set (int, rtx, rtx);
+static void record_set_info (rtx, rtx, void *);
+static void compute_sets (rtx);
+static void hash_scan_insn (rtx, struct hash_table *, int);
+static void hash_scan_set (rtx, rtx, struct hash_table *);
+static void hash_scan_clobber (rtx, rtx, struct hash_table *);
+static void hash_scan_call (rtx, rtx, struct hash_table *);
+static int want_to_gcse_p (rtx);
+static bool gcse_constant_p (rtx);
+static int oprs_unchanged_p (rtx, rtx, int);
+static int oprs_anticipatable_p (rtx, rtx);
+static int oprs_available_p (rtx, rtx);
+static void insert_expr_in_table (rtx, enum machine_mode, rtx, int, int,
+                                 struct hash_table *);
+static void insert_set_in_table (rtx, rtx, struct hash_table *);
+static unsigned int hash_expr (rtx, enum machine_mode, int *, int);
+static unsigned int hash_expr_1 (rtx, enum machine_mode, int *);
+static unsigned int hash_string_1 (const char *);
+static unsigned int hash_set (int, int);
+static int expr_equiv_p (rtx, rtx);
+static void record_last_reg_set_info (rtx, int);
+static void record_last_mem_set_info (rtx);
+static void record_last_set_info (rtx, rtx, void *);
+static void compute_hash_table (struct hash_table *);
+static void alloc_hash_table (int, struct hash_table *, int);
+static void free_hash_table (struct hash_table *);
+static void compute_hash_table_work (struct hash_table *);
+static void dump_hash_table (FILE *, const char *, struct hash_table *);
+static struct expr *lookup_expr (rtx, struct hash_table *);
+static struct expr *lookup_set (unsigned int, struct hash_table *);
+static struct expr *next_set (unsigned int, struct expr *);
+static void reset_opr_set_tables (void);
+static int oprs_not_set_p (rtx, rtx);
+static void mark_call (rtx);
+static void mark_set (rtx, rtx);
+static void mark_clobber (rtx, rtx);
+static void mark_oprs_set (rtx);
+static void alloc_cprop_mem (int, int);
+static void free_cprop_mem (void);
+static void compute_transp (rtx, int, sbitmap *, int);
+static void compute_transpout (void);
+static void compute_local_properties (sbitmap *, sbitmap *, sbitmap *,
+                                     struct hash_table *);
+static void compute_cprop_data (void);
+static void find_used_regs (rtx *, void *);
+static int try_replace_reg (rtx, rtx, rtx);
+static struct expr *find_avail_set (int, rtx);
+static int cprop_jump (basic_block, rtx, rtx, rtx, rtx);
+static void mems_conflict_for_gcse_p (rtx, rtx, void *);
+static int load_killed_in_block_p (basic_block, int, rtx, int);
+static void canon_list_insert (rtx, rtx, void *);
+static int cprop_insn (rtx, int);
+static int cprop (int);
+static void find_implicit_sets (void);
+static int one_cprop_pass (int, int, int);
+static bool constprop_register (rtx, rtx, rtx, int);
+static struct expr *find_bypass_set (int, int);
+static bool reg_killed_on_edge (rtx, edge);
+static int bypass_block (basic_block, rtx, rtx);
+static int bypass_conditional_jumps (void);
+static void alloc_pre_mem (int, int);
+static void free_pre_mem (void);
+static void compute_pre_data (void);
+static int pre_expr_reaches_here_p (basic_block, struct expr *,
+                                   basic_block);
+static void insert_insn_end_bb (struct expr *, basic_block, int);
+static void pre_insert_copy_insn (struct expr *, rtx);
+static void pre_insert_copies (void);
+static int pre_delete (void);
+static int pre_gcse (void);
+static int one_pre_gcse_pass (int);
+static void add_label_notes (rtx, rtx);
+static void alloc_code_hoist_mem (int, int);
+static void free_code_hoist_mem (void);
+static void compute_code_hoist_vbeinout (void);
+static void compute_code_hoist_data (void);
+static int hoist_expr_reaches_here_p (basic_block, int, basic_block, char *);
+static void hoist_code (void);
+static int one_code_hoisting_pass (void);
+static void alloc_rd_mem (int, int);
+static void free_rd_mem (void);
+static void handle_rd_kill_set (rtx, int, basic_block);
+static void compute_kill_rd (void);
+static void compute_rd (void);
+static void alloc_avail_expr_mem (int, int);
+static void free_avail_expr_mem (void);
+static void compute_ae_gen (struct hash_table *);
+static int expr_killed_p (rtx, basic_block);
+static void compute_ae_kill (sbitmap *, sbitmap *, struct hash_table *);
+static int expr_reaches_here_p (struct occr *, struct expr *, basic_block,
+                               int);
+static rtx computing_insn (struct expr *, rtx);
+static int def_reaches_here_p (rtx, rtx);
+static int can_disregard_other_sets (struct reg_set **, rtx, int);
+static int handle_avail_expr (rtx, struct expr *);
+static int classic_gcse (void);
+static int one_classic_gcse_pass (int);
+static void invalidate_nonnull_info (rtx, rtx, void *);
+static int delete_null_pointer_checks_1 (unsigned int *, sbitmap *, sbitmap *,
+                                        struct null_pointer_info *);
+static rtx process_insert_insn (struct expr *);
+static int pre_edge_insert (struct edge_list *, struct expr **);
+static int expr_reaches_here_p_work (struct occr *, struct expr *,
+                                    basic_block, int, char *);
+static int pre_expr_reaches_here_p_work (basic_block, struct expr *,
+                                        basic_block, char *);
+static struct ls_expr * ldst_entry (rtx);
+static void free_ldst_entry (struct ls_expr *);
+static void free_ldst_mems (void);
+static void print_ldst_list (FILE *);
+static struct ls_expr * find_rtx_in_ldst (rtx);
+static int enumerate_ldsts (void);
+static inline struct ls_expr * first_ls_expr (void);
+static inline struct ls_expr * next_ls_expr (struct ls_expr *);
+static int simple_mem (rtx);
+static void invalidate_any_buried_refs (rtx);
+static void compute_ld_motion_mems (void);
+static void trim_ld_motion_mems (void);
+static void update_ld_motion_stores (struct expr *);
+static void reg_set_info (rtx, rtx, void *);
+static bool store_ops_ok (rtx, int *);
+static rtx extract_mentioned_regs (rtx);
+static rtx extract_mentioned_regs_helper (rtx, rtx);
+static void find_moveable_store (rtx, int *, int *);
+static int compute_store_table (void);
+static bool load_kills_store (rtx, rtx, int);
+static bool find_loads (rtx, rtx, int);
+static bool store_killed_in_insn (rtx, rtx, rtx, int);
+static bool store_killed_after (rtx, rtx, rtx, basic_block, int *, rtx *);
+static bool store_killed_before (rtx, rtx, rtx, basic_block, int *);
+static void build_store_vectors (void);
+static void insert_insn_start_bb (rtx, basic_block);
+static int insert_store (struct ls_expr *, edge);
+static void remove_reachable_equiv_notes (basic_block, struct ls_expr *);
+static void replace_store_insn (rtx, rtx, basic_block, struct ls_expr *);
+static void delete_store (struct ls_expr *, basic_block);
+static void free_store_memory (void);
+static void store_motion (void);
+static void free_insn_expr_list_list (rtx *);
+static void clear_modify_mem_tables (void);
+static void free_modify_mem_tables (void);
+static rtx gcse_emit_move_after (rtx, rtx, rtx);
+static void local_cprop_find_used_regs (rtx *, void *);
+static bool do_local_cprop (rtx, rtx, int, rtx*);
+static bool adjust_libcall_notes (rtx, rtx, rtx, rtx*);
+static void local_cprop_pass (int);
+static bool is_too_expensive (const char *);
 \f
+
 /* Entry point for global common subexpression elimination.
    F is the first instruction in the function.  */
 
 int
-gcse_main (f, file)
-     rtx f;
-     FILE *file;
+gcse_main (rtx f, FILE *file)
 {
   int changed, pass;
   /* Bytes used at start of pass.  */
@@ -744,39 +741,10 @@ gcse_main (f, file)
   if (file)
     dump_flow_info (file);
 
-  /* Return if there's nothing to do.  */
-  if (n_basic_blocks <= 1)
+  /* Return if there's nothing to do, or it is too expensive.  */
+  if (n_basic_blocks <= 1 || is_too_expensive (_("GCSE disabled")))
     return 0;
-
-  /* Trying to perform global optimizations on flow graphs which have
-     a high connectivity will take a long time and is unlikely to be
-     particularly useful.
-
-     In normal circumstances a cfg should have about twice as many edges
-     as blocks.  But we do not want to punish small functions which have
-     a couple switch statements.  So we require a relatively large number
-     of basic blocks and the ratio of edges to blocks to be high.  */
-  if (n_basic_blocks > 1000 && n_edges / n_basic_blocks >= 20)
-    {
-      if (warn_disabled_optimization)
-       warning ("GCSE disabled: %d > 1000 basic blocks and %d >= 20 edges/basic block",
-                n_basic_blocks, n_edges / n_basic_blocks);
-      return 0;
-    }
-
-  /* If allocating memory for the cprop bitmap would take up too much
-     storage it's better just to disable the optimization.  */
-  if ((n_basic_blocks
-       * SBITMAP_SET_SIZE (max_gcse_regno)
-       * sizeof (SBITMAP_ELT_TYPE)) > MAX_GCSE_MEMORY)
-    {
-      if (warn_disabled_optimization)
-       warning ("GCSE disabled: %d basic blocks and %d registers",
-                n_basic_blocks, max_gcse_regno);
-
-      return 0;
-    }
-
+  
   gcc_obstack_init (&gcse_obstack);
   bytes_used = 0;
 
@@ -829,12 +797,8 @@ gcse_main (f, file)
          if (changed)
            {
              free_modify_mem_tables ();
-             modify_mem_list
-               = (rtx *) gmalloc (last_basic_block * sizeof (rtx));
-             canon_modify_mem_list
-               = (rtx *) gmalloc (last_basic_block * sizeof (rtx));
-             memset ((char *) modify_mem_list, 0, last_basic_block * sizeof (rtx));
-             memset ((char *) canon_modify_mem_list, 0, last_basic_block * sizeof (rtx));
+             modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
+             canon_modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
            }
          free_reg_set_mem ();
          alloc_reg_set_mem (max_reg_num ());
@@ -917,7 +881,7 @@ static char can_copy[(int) NUM_MACHINE_MODES];
 /* Compute which modes support reg/reg copy operations.  */
 
 static void
-compute_can_copy ()
+compute_can_copy (void)
 {
   int i;
 #ifndef AVOID_CCMODE_COPIES
@@ -947,8 +911,7 @@ compute_can_copy ()
 /* Returns whether the mode supports reg/reg copy operations.  */
 
 bool
-can_copy_p (mode)
-     enum machine_mode mode;
+can_copy_p (enum machine_mode mode)
 {
   static bool can_copy_init_p = false;
 
@@ -963,34 +926,39 @@ can_copy_p (mode)
 \f
 /* Cover function to xmalloc to record bytes allocated.  */
 
-static char *
-gmalloc (size)
-     unsigned int size;
+static void *
+gmalloc (size_t size)
 {
   bytes_used += size;
   return xmalloc (size);
 }
 
+/* Cover function to xcalloc to record bytes allocated.  */
+
+static void *
+gcalloc (size_t nelem, size_t elsize)
+{
+  bytes_used += nelem * elsize;
+  return xcalloc (nelem, elsize);
+}
+
 /* Cover function to xrealloc.
    We don't record the additional size since we don't know it.
    It won't affect memory usage stats much anyway.  */
 
-static char *
-grealloc (ptr, size)
-     char *ptr;
-     unsigned int size;
+static void *
+grealloc (void *ptr, size_t size)
 {
   return xrealloc (ptr, size);
 }
 
 /* Cover function to obstack_alloc.  */
 
-static char *
-gcse_alloc (size)
-     unsigned long size;
+static void *
+gcse_alloc (unsigned long size)
 {
   bytes_used += size;
-  return (char *) obstack_alloc (&gcse_obstack, size);
+  return obstack_alloc (&gcse_obstack, size);
 }
 
 /* Allocate memory for the cuid mapping array,
@@ -999,10 +967,9 @@ gcse_alloc (size)
    This is called at the start of each pass.  */
 
 static void
-alloc_gcse_mem (f)
-     rtx f;
+alloc_gcse_mem (rtx f)
 {
-  int i, n;
+  int i;
   rtx insn;
 
   /* Find the largest UID and create a mapping from UIDs to CUIDs.
@@ -1010,9 +977,7 @@ alloc_gcse_mem (f)
      and only apply to real insns.  */
 
   max_uid = get_max_uid ();
-  n = (max_uid + 1) * sizeof (int);
-  uid_cuid = (int *) gmalloc (n);
-  memset ((char *) uid_cuid, 0, n);
+  uid_cuid = gcalloc (max_uid + 1, sizeof (int));
   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
     {
       if (INSN_P (insn))
@@ -1024,9 +989,7 @@ alloc_gcse_mem (f)
   /* Create a table mapping cuids to insns.  */
 
   max_cuid = i;
-  n = (max_cuid + 1) * sizeof (rtx);
-  cuid_insn = (rtx *) gmalloc (n);
-  memset ((char *) cuid_insn, 0, n);
+  cuid_insn = gcalloc (max_cuid + 1, sizeof (rtx));
   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
     if (INSN_P (insn))
       CUID_INSN (i++) = insn;
@@ -1035,14 +998,11 @@ alloc_gcse_mem (f)
   reg_set_bitmap = BITMAP_XMALLOC ();
 
   /* Allocate vars to track sets of regs, memory per block.  */
-  reg_set_in_block = (sbitmap *) sbitmap_vector_alloc (last_basic_block,
-                                                      max_gcse_regno);
+  reg_set_in_block = sbitmap_vector_alloc (last_basic_block, max_gcse_regno);
   /* Allocate array to keep a list of insns which modify memory in each
      basic block.  */
-  modify_mem_list = (rtx *) gmalloc (last_basic_block * sizeof (rtx));
-  canon_modify_mem_list = (rtx *) gmalloc (last_basic_block * sizeof (rtx));
-  memset ((char *) modify_mem_list, 0, last_basic_block * sizeof (rtx));
-  memset ((char *) canon_modify_mem_list, 0, last_basic_block * sizeof (rtx));
+  modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
+  canon_modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
   modify_mem_list_set = BITMAP_XMALLOC ();
   canon_modify_mem_list_set = BITMAP_XMALLOC ();
 }
@@ -1050,7 +1010,7 @@ alloc_gcse_mem (f)
 /* Free memory allocated by alloc_gcse_mem.  */
 
 static void
-free_gcse_mem ()
+free_gcse_mem (void)
 {
   free (uid_cuid);
   free (cuid_insn);
@@ -1081,10 +1041,7 @@ free_gcse_mem ()
    less space.  */
 
 static int
-get_bitmap_width (n, x, y)
-     int n;
-     int x;
-     int y;
+get_bitmap_width (int n, int x, int y)
 {
   /* It's not really worth figuring out *exactly* how much memory will
      be used by a particular choice.  The important thing is to get
@@ -1134,11 +1091,7 @@ get_bitmap_width (n, x, y)
    ABSALTERED.  */
 
 static void
-compute_local_properties (transp, comp, antloc, table)
-     sbitmap *transp;
-     sbitmap *comp;
-     sbitmap *antloc;
-     struct hash_table *table;
+compute_local_properties (sbitmap *transp, sbitmap *comp, sbitmap *antloc, struct hash_table *table)
 {
   unsigned int i;
 
@@ -1210,32 +1163,43 @@ compute_local_properties (transp, comp, antloc, table)
 static struct obstack reg_set_obstack;
 
 static void
-alloc_reg_set_mem (n_regs)
-     int n_regs;
+alloc_reg_set_mem (int n_regs)
 {
-  unsigned int n;
-
   reg_set_table_size = n_regs + REG_SET_TABLE_SLOP;
-  n = reg_set_table_size * sizeof (struct reg_set *);
-  reg_set_table = (struct reg_set **) gmalloc (n);
-  memset ((char *) reg_set_table, 0, n);
+  reg_set_table = gcalloc (reg_set_table_size, sizeof (struct reg_set *));
 
   gcc_obstack_init (&reg_set_obstack);
 }
 
 static void
-free_reg_set_mem ()
+free_reg_set_mem (void)
 {
   free (reg_set_table);
   obstack_free (&reg_set_obstack, NULL);
 }
 
+/* An OLD_INSN that used to set REGNO was replaced by NEW_INSN.
+   Update the corresponding `reg_set_table' entry accordingly.
+   We assume that NEW_INSN is not already recorded in reg_set_table[regno].  */
+
+static void
+replace_one_set (int regno, rtx old_insn, rtx new_insn)
+{
+  struct reg_set *reg_info;
+  if (regno >= reg_set_table_size)
+    return;
+  for (reg_info = reg_set_table[regno]; reg_info; reg_info = reg_info->next)
+    if (reg_info->insn == old_insn)
+      {
+        reg_info->insn = new_insn;
+        break;
+      }
+}
+
 /* Record REGNO in the reg_set table.  */
 
 static void
-record_one_set (regno, insn)
-     int regno;
-     rtx insn;
+record_one_set (int regno, rtx insn)
 {
   /* Allocate a new reg_set element and link it onto the list.  */
   struct reg_set *new_reg_info;
@@ -1245,16 +1209,14 @@ record_one_set (regno, insn)
     {
       int new_size = regno + REG_SET_TABLE_SLOP;
 
-      reg_set_table
-       = (struct reg_set **) grealloc ((char *) reg_set_table,
-                                       new_size * sizeof (struct reg_set *));
-      memset ((char *) (reg_set_table + reg_set_table_size), 0,
+      reg_set_table = grealloc (reg_set_table,
+                               new_size * sizeof (struct reg_set *));
+      memset (reg_set_table + reg_set_table_size, 0,
              (new_size - reg_set_table_size) * sizeof (struct reg_set *));
       reg_set_table_size = new_size;
     }
 
-  new_reg_info = (struct reg_set *) obstack_alloc (&reg_set_obstack,
-                                                  sizeof (struct reg_set));
+  new_reg_info = obstack_alloc (&reg_set_obstack, sizeof (struct reg_set));
   bytes_used += sizeof (struct reg_set);
   new_reg_info->insn = insn;
   new_reg_info->next = reg_set_table[regno];
@@ -1266,9 +1228,7 @@ record_one_set (regno, insn)
    occurring.  */
 
 static void
-record_set_info (dest, setter, data)
-     rtx dest, setter ATTRIBUTE_UNUSED;
-     void *data;
+record_set_info (rtx dest, rtx setter ATTRIBUTE_UNUSED, void *data)
 {
   rtx record_set_insn = (rtx) data;
 
@@ -1282,8 +1242,7 @@ record_set_info (dest, setter, data)
    `reg_set_table' for further documentation.  */
 
 static void
-compute_sets (f)
-     rtx f;
+compute_sets (rtx f)
 {
   rtx insn;
 
@@ -1310,8 +1269,7 @@ static basic_block current_bb;
 
 static GTY(()) rtx test_insn;
 static int
-want_to_gcse_p (x)
-     rtx x;
+want_to_gcse_p (rtx x)
 {
   int num_clobbers = 0;
   int icode;
@@ -1362,9 +1320,7 @@ want_to_gcse_p (x)
    or from INSN to the end of INSN's basic block (if AVAIL_P != 0).  */
 
 static int
-oprs_unchanged_p (x, insn, avail_p)
-     rtx x, insn;
-     int avail_p;
+oprs_unchanged_p (rtx x, rtx insn, int avail_p)
 {
   int i, j;
   enum rtx_code code;
@@ -1457,9 +1413,8 @@ static rtx gcse_mem_operand;
    gcse_mems_conflict_p to a nonzero value.  */
 
 static void
-mems_conflict_for_gcse_p (dest, setter, data)
-     rtx dest, setter ATTRIBUTE_UNUSED;
-     void *data ATTRIBUTE_UNUSED;
+mems_conflict_for_gcse_p (rtx dest, rtx setter ATTRIBUTE_UNUSED,
+                         void *data ATTRIBUTE_UNUSED)
 {
   while (GET_CODE (dest) == SUBREG
         || GET_CODE (dest) == ZERO_EXTRACT
@@ -1497,11 +1452,7 @@ mems_conflict_for_gcse_p (dest, setter, data)
    AVAIL_P to 0.  */
 
 static int
-load_killed_in_block_p (bb, uid_limit, x, avail_p)
-     basic_block bb;
-     int uid_limit;
-     rtx x;
-     int avail_p;
+load_killed_in_block_p (basic_block bb, int uid_limit, rtx x, int avail_p)
 {
   rtx list_entry = modify_mem_list[bb->index];
   while (list_entry)
@@ -1544,8 +1495,7 @@ load_killed_in_block_p (bb, uid_limit, x, avail_p)
    the start of INSN's basic block up to but not including INSN.  */
 
 static int
-oprs_anticipatable_p (x, insn)
-     rtx x, insn;
+oprs_anticipatable_p (rtx x, rtx insn)
 {
   return oprs_unchanged_p (x, insn, 0);
 }
@@ -1554,8 +1504,7 @@ oprs_anticipatable_p (x, insn)
    INSN to the end of INSN's basic block.  */
 
 static int
-oprs_available_p (x, insn)
-     rtx x, insn;
+oprs_available_p (rtx x, rtx insn)
 {
   return oprs_unchanged_p (x, insn, 1);
 }
@@ -1569,11 +1518,7 @@ oprs_available_p (x, insn)
    ??? One might want to merge this with canon_hash.  Later.  */
 
 static unsigned int
-hash_expr (x, mode, do_not_record_p, hash_table_size)
-     rtx x;
-     enum machine_mode mode;
-     int *do_not_record_p;
-     int hash_table_size;
+hash_expr (rtx x, enum machine_mode mode, int *do_not_record_p, int hash_table_size)
 {
   unsigned int hash;
 
@@ -1586,8 +1531,7 @@ hash_expr (x, mode, do_not_record_p, hash_table_size)
 /* Hash a string.  Just add its bytes up.  */
 
 static inline unsigned
-hash_string_1 (ps)
-     const char *ps;
+hash_string_1 (const char *ps)
 {
   unsigned hash = 0;
   const unsigned char *p = (const unsigned char *) ps;
@@ -1602,10 +1546,7 @@ hash_string_1 (ps)
 /* Subroutine of hash_expr to do the actual work.  */
 
 static unsigned int
-hash_expr_1 (x, mode, do_not_record_p)
-     rtx x;
-     enum machine_mode mode;
-     int *do_not_record_p;
+hash_expr_1 (rtx x, enum machine_mode mode, int *do_not_record_p)
 {
   int i, j;
   unsigned hash = 0;
@@ -1793,9 +1734,7 @@ hash_expr_1 (x, mode, do_not_record_p)
    ??? May need to make things more elaborate.  Later, as necessary.  */
 
 static unsigned int
-hash_set (regno, hash_table_size)
-     int regno;
-     int hash_table_size;
+hash_set (int regno, int hash_table_size)
 {
   unsigned int hash;
 
@@ -1807,8 +1746,7 @@ hash_set (regno, hash_table_size)
    ??? Borrowed from cse.c.  Might want to remerge with cse.c.  Later.  */
 
 static int
-expr_equiv_p (x, y)
-     rtx x, y;
+expr_equiv_p (rtx x, rtx y)
 {
   int i, j;
   enum rtx_code code;
@@ -1850,6 +1788,10 @@ expr_equiv_p (x, y)
         due to it being set with the different alias set.  */
       if (MEM_ALIAS_SET (x) != MEM_ALIAS_SET (y))
        return 0;
+
+      /* A volatile mem should not be considered equivalent to any other.  */
+      if (MEM_VOLATILE_P (x) || MEM_VOLATILE_P (y))
+       return 0;
       break;
 
     /*  For commutative operations, check both orders.  */
@@ -1955,12 +1897,8 @@ expr_equiv_p (x, y)
    AVAIL_P is nonzero if X is an available expression.  */
 
 static void
-insert_expr_in_table (x, mode, insn, antic_p, avail_p, table)
-     rtx x;
-     enum machine_mode mode;
-     rtx insn;
-     int antic_p, avail_p;
-     struct hash_table *table;
+insert_expr_in_table (rtx x, enum machine_mode mode, rtx insn, int antic_p,
+                     int avail_p, struct hash_table *table)
 {
   int found, do_not_record_p;
   unsigned int hash;
@@ -1989,7 +1927,7 @@ insert_expr_in_table (x, mode, insn, antic_p, avail_p, table)
 
   if (! found)
     {
-      cur_expr = (struct expr *) gcse_alloc (sizeof (struct expr));
+      cur_expr = gcse_alloc (sizeof (struct expr));
       bytes_used += sizeof (struct expr);
       if (table->table[hash] == NULL)
        /* This is the first pattern that hashed to this index.  */
@@ -2028,7 +1966,7 @@ insert_expr_in_table (x, mode, insn, antic_p, avail_p, table)
       else
        {
          /* First occurrence of this expression in this basic block.  */
-         antic_occr = (struct occr *) gcse_alloc (sizeof (struct occr));
+         antic_occr = gcse_alloc (sizeof (struct occr));
          bytes_used += sizeof (struct occr);
          /* First occurrence of this expression in any block?  */
          if (cur_expr->antic_occr == NULL)
@@ -2063,7 +2001,7 @@ insert_expr_in_table (x, mode, insn, antic_p, avail_p, table)
       else
        {
          /* First occurrence of this expression in this basic block.  */
-         avail_occr = (struct occr *) gcse_alloc (sizeof (struct occr));
+         avail_occr = gcse_alloc (sizeof (struct occr));
          bytes_used += sizeof (struct occr);
 
          /* First occurrence of this expression in any block?  */
@@ -2084,10 +2022,7 @@ insert_expr_in_table (x, mode, insn, antic_p, avail_p, table)
    basic block.  */
 
 static void
-insert_set_in_table (x, insn, table)
-     rtx x;
-     rtx insn;
-     struct hash_table *table;
+insert_set_in_table (rtx x, rtx insn, struct hash_table *table)
 {
   int found;
   unsigned int hash;
@@ -2113,7 +2048,7 @@ insert_set_in_table (x, insn, table)
 
   if (! found)
     {
-      cur_expr = (struct expr *) gcse_alloc (sizeof (struct expr));
+      cur_expr = gcse_alloc (sizeof (struct expr));
       bytes_used += sizeof (struct expr);
       if (table->table[hash] == NULL)
        /* This is the first pattern that hashed to this index.  */
@@ -2152,7 +2087,7 @@ insert_set_in_table (x, insn, table)
   else
     {
       /* First occurrence of this expression in this basic block.  */
-      cur_occr = (struct occr *) gcse_alloc (sizeof (struct occr));
+      cur_occr = gcse_alloc (sizeof (struct occr));
       bytes_used += sizeof (struct occr);
 
       /* First occurrence of this expression in any block?  */
@@ -2170,8 +2105,7 @@ insert_set_in_table (x, insn, table)
    the purposes of GCSE's constant propagation.  */
 
 static bool
-gcse_constant_p (x)
-     rtx x;
+gcse_constant_p (rtx x)
 {
   /* Consider a COMPARE of two integers constant.  */
   if (GET_CODE (x) == COMPARE
@@ -2179,6 +2113,17 @@ gcse_constant_p (x)
       && GET_CODE (XEXP (x, 1)) == CONST_INT)
     return true;
 
+
+  /* Consider a COMPARE of the same registers is a constant
+    if they are not floating point registers.  */
+  if (GET_CODE(x) == COMPARE
+      && GET_CODE (XEXP (x, 0)) == REG
+      && GET_CODE (XEXP (x, 1)) == REG
+      && REGNO (XEXP (x, 0)) == REGNO (XEXP (x, 1))
+      && ! FLOAT_MODE_P (GET_MODE (XEXP (x, 0)))
+      && ! FLOAT_MODE_P (GET_MODE (XEXP (x, 1))))
+    return true;
+
   if (GET_CODE (x) == CONSTANT_P_RTX)
     return false;
 
@@ -2189,9 +2134,7 @@ gcse_constant_p (x)
    expression one).  */
 
 static void
-hash_scan_set (pat, insn, table)
-     rtx pat, insn;
-     struct hash_table *table;
+hash_scan_set (rtx pat, rtx insn, struct hash_table *table)
 {
   rtx src = SET_SRC (pat);
   rtx dest = SET_DEST (pat);
@@ -2262,20 +2205,61 @@ hash_scan_set (pat, insn, table)
                       && oprs_available_p (pat, tmp))))
        insert_set_in_table (pat, insn, table);
     }
+  /* In case of store we want to consider the memory value as available in
+     the REG stored in that memory. This makes it possible to remove
+     redundant loads from due to stores to the same location.  */
+  else if (flag_gcse_las && GET_CODE (src) == REG && GET_CODE (dest) == MEM)
+      {
+        unsigned int regno = REGNO (src);
+
+        /* Do not do this for constant/copy propagation.  */
+        if (! table->set_p
+            /* Only record sets of pseudo-regs in the hash table.  */
+           && regno >= FIRST_PSEUDO_REGISTER
+          /* Don't GCSE something if we can't do a reg/reg copy.  */
+          && can_copy_p (GET_MODE (src))
+          /* GCSE commonly inserts instruction after the insn.  We can't
+             do that easily for EH_REGION notes so disable GCSE on these
+             for now.  */
+          && ! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
+          /* Is SET_DEST something we want to gcse?  */
+          && want_to_gcse_p (dest)
+          /* Don't CSE a nop.  */
+          && ! set_noop_p (pat)
+          /* Don't GCSE if it has attached REG_EQUIV note.
+             At this point this only function parameters should have
+             REG_EQUIV notes and if the argument slot is used somewhere
+             explicitly, it means address of parameter has been taken,
+             so we should not extend the lifetime of the pseudo.  */
+          && ((note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) == 0
+              || GET_CODE (XEXP (note, 0)) != MEM))
+             {
+               /* Stores are never anticipatable.  */
+               int antic_p = 0;
+              /* An expression is not available if its operands are
+                 subsequently modified, including this insn.  It's also not
+                 available if this is a branch, because we can't insert
+                 a set after the branch.  */
+               int avail_p = oprs_available_p (dest, insn)
+                            && ! JUMP_P (insn);
+
+              /* Record the memory expression (DEST) in the hash table.  */
+              insert_expr_in_table (dest, GET_MODE (dest), insn,
+                                    antic_p, avail_p, table);
+             }
+      }
 }
 
 static void
-hash_scan_clobber (x, insn, table)
-     rtx x ATTRIBUTE_UNUSED, insn ATTRIBUTE_UNUSED;
-     struct hash_table *table ATTRIBUTE_UNUSED;
+hash_scan_clobber (rtx x ATTRIBUTE_UNUSED, rtx insn ATTRIBUTE_UNUSED,
+                  struct hash_table *table ATTRIBUTE_UNUSED)
 {
   /* Currently nothing to do.  */
 }
 
 static void
-hash_scan_call (x, insn, table)
-     rtx x ATTRIBUTE_UNUSED, insn ATTRIBUTE_UNUSED;
-     struct hash_table *table ATTRIBUTE_UNUSED;
+hash_scan_call (rtx x ATTRIBUTE_UNUSED, rtx insn ATTRIBUTE_UNUSED,
+               struct hash_table *table ATTRIBUTE_UNUSED)
 {
   /* Currently nothing to do.  */
 }
@@ -2294,10 +2278,7 @@ hash_scan_call (x, insn, table)
    not record any expressions.  */
 
 static void
-hash_scan_insn (insn, table, in_libcall_block)
-     rtx insn;
-     struct hash_table *table;
-     int in_libcall_block;
+hash_scan_insn (rtx insn, struct hash_table *table, int in_libcall_block)
 {
   rtx pat = PATTERN (insn);
   int i;
@@ -2330,10 +2311,7 @@ hash_scan_insn (insn, table, in_libcall_block)
 }
 
 static void
-dump_hash_table (file, name, table)
-     FILE *file;
-     const char *name;
-     struct hash_table *table;
+dump_hash_table (FILE *file, const char *name, struct hash_table *table)
 {
   int i;
   /* Flattened out table, so it's printed in proper order.  */
@@ -2341,9 +2319,8 @@ dump_hash_table (file, name, table)
   unsigned int *hash_val;
   struct expr *expr;
 
-  flat_table
-    = (struct expr **) xcalloc (table->n_elems, sizeof (struct expr *));
-  hash_val = (unsigned int *) xmalloc (table->n_elems * sizeof (unsigned int));
+  flat_table = xcalloc (table->n_elems, sizeof (struct expr *));
+  hash_val = xmalloc (table->n_elems * sizeof (unsigned int));
 
   for (i = 0; i < (int) table->size; i++)
     for (expr = table->table[i]; expr != NULL; expr = expr->next_same_hash)
@@ -2386,9 +2363,7 @@ dump_hash_table (file, name, table)
    and is used to compute "transparency".  */
 
 static void
-record_last_reg_set_info (insn, regno)
-     rtx insn;
-     int regno;
+record_last_reg_set_info (rtx insn, int regno)
 {
   struct reg_avail_info *info = &reg_avail_info[regno];
   int cuid = INSN_CUID (insn);
@@ -2408,10 +2383,8 @@ record_last_reg_set_info (insn, regno)
    taken off pairwise.  */
 
 static void
-canon_list_insert (dest, unused1, v_insn)
-     rtx    dest ATTRIBUTE_UNUSED;
-     rtx    unused1 ATTRIBUTE_UNUSED;
-     void * v_insn;
+canon_list_insert (rtx dest ATTRIBUTE_UNUSED, rtx unused1 ATTRIBUTE_UNUSED,
+                  void * v_insn)
 {
   rtx dest_addr, insn;
   int bb;
@@ -2446,8 +2419,7 @@ canon_list_insert (dest, unused1, v_insn)
    a CALL_INSN).  We merely need to record which insns modify memory.  */
 
 static void
-record_last_mem_set_info (insn)
-     rtx insn;
+record_last_mem_set_info (rtx insn)
 {
   int bb = BLOCK_NUM (insn);
 
@@ -2474,9 +2446,7 @@ record_last_mem_set_info (insn)
    the SET is taking place.  */
 
 static void
-record_last_set_info (dest, setter, data)
-     rtx dest, setter ATTRIBUTE_UNUSED;
-     void *data;
+record_last_set_info (rtx dest, rtx setter ATTRIBUTE_UNUSED, void *data)
 {
   rtx last_set_insn = (rtx) data;
 
@@ -2508,8 +2478,7 @@ record_last_set_info (dest, setter, data)
    TABLE is the table computed.  */
 
 static void
-compute_hash_table_work (table)
-     struct hash_table *table;
+compute_hash_table_work (struct hash_table *table)
 {
   unsigned int i;
 
@@ -2522,8 +2491,7 @@ compute_hash_table_work (table)
   /* re-Cache any INSN_LIST nodes we have allocated.  */
   clear_modify_mem_tables ();
   /* Some working arrays used to track first and last set in each block.  */
-  reg_avail_info = (struct reg_avail_info*)
-    gmalloc (max_gcse_regno * sizeof (struct reg_avail_info));
+  reg_avail_info = gmalloc (max_gcse_regno * sizeof (struct reg_avail_info));
 
   for (i = 0; i < max_gcse_regno; ++i)
     reg_avail_info[i].last_bb = NULL;
@@ -2600,10 +2568,7 @@ compute_hash_table_work (table)
    be created.  */
 
 static void
-alloc_hash_table (n_insns, table, set_p)
-     int n_insns;
-     struct hash_table *table;
-     int set_p;
+alloc_hash_table (int n_insns, struct hash_table *table, int set_p)
 {
   int n;
 
@@ -2616,15 +2581,14 @@ alloc_hash_table (n_insns, table, set_p)
      ??? Later take some measurements.  */
   table->size |= 1;
   n = table->size * sizeof (struct expr *);
-  table->table = (struct expr **) gmalloc (n);
+  table->table = gmalloc (n);
   table->set_p = set_p;
 }
 
 /* Free things allocated by alloc_hash_table.  */
 
 static void
-free_hash_table (table)
-     struct hash_table *table;
+free_hash_table (struct hash_table *table)
 {
   free (table->table);
 }
@@ -2633,13 +2597,11 @@ free_hash_table (table)
    expression hash table.  */
 
 static void
-compute_hash_table (table)
-    struct hash_table *table;
+compute_hash_table (struct hash_table *table)
 {
   /* Initialize count of number of entries in hash table.  */
   table->n_elems = 0;
-  memset ((char *) table->table, 0,
-         table->size * sizeof (struct expr *));
+  memset (table->table, 0, table->size * sizeof (struct expr *));
 
   compute_hash_table_work (table);
 }
@@ -2650,9 +2612,7 @@ compute_hash_table (table)
    The result is a pointer to the table entry, or NULL if not found.  */
 
 static struct expr *
-lookup_expr (pat, table)
-     rtx pat;
-     struct hash_table *table;
+lookup_expr (rtx pat, struct hash_table *table)
 {
   int do_not_record_p;
   unsigned int hash = hash_expr (pat, GET_MODE (pat), &do_not_record_p,
@@ -2674,9 +2634,7 @@ lookup_expr (pat, table)
    table entry, or NULL if not found.  */
 
 static struct expr *
-lookup_set (regno, table)
-     unsigned int regno;
-     struct hash_table *table;
+lookup_set (unsigned int regno, struct hash_table *table)
 {
   unsigned int hash = hash_set (regno, table->size);
   struct expr *expr;
@@ -2692,9 +2650,7 @@ lookup_set (regno, table)
 /* Return the next entry for REGNO in list EXPR.  */
 
 static struct expr *
-next_set (regno, expr)
-     unsigned int regno;
-     struct expr *expr;
+next_set (unsigned int regno, struct expr *expr)
 {
   do
     expr = expr->next_same_hash;
@@ -2707,8 +2663,7 @@ next_set (regno, expr)
    types may be mixed.  */
 
 static void
-free_insn_expr_list_list (listp)
-     rtx *listp;
+free_insn_expr_list_list (rtx *listp)
 {
   rtx list, next;
 
@@ -2726,7 +2681,7 @@ free_insn_expr_list_list (listp)
 
 /* Clear canon_modify_mem_list and modify_mem_list tables.  */
 static void
-clear_modify_mem_tables ()
+clear_modify_mem_tables (void)
 {
   int i;
 
@@ -2743,7 +2698,7 @@ clear_modify_mem_tables ()
 /* Release memory used by modify_mem_list_set and canon_modify_mem_list_set.  */
 
 static void
-free_modify_mem_tables ()
+free_modify_mem_tables (void)
 {
   clear_modify_mem_tables ();
   free (modify_mem_list);
@@ -2756,7 +2711,7 @@ free_modify_mem_tables ()
    start of the block].  */
 
 static void
-reset_opr_set_tables ()
+reset_opr_set_tables (void)
 {
   /* Maintain a bitmap of which regs have been set since beginning of
      the block.  */
@@ -2772,8 +2727,7 @@ reset_opr_set_tables ()
    INSN's basic block.  */
 
 static int
-oprs_not_set_p (x, insn)
-     rtx x, insn;
+oprs_not_set_p (rtx x, rtx insn)
 {
   int i, j;
   enum rtx_code code;
@@ -2836,8 +2790,7 @@ oprs_not_set_p (x, insn)
 /* Mark things set by a CALL.  */
 
 static void
-mark_call (insn)
-     rtx insn;
+mark_call (rtx insn)
 {
   if (! CONST_OR_PURE_CALL_P (insn))
     record_last_mem_set_info (insn);
@@ -2846,8 +2799,7 @@ mark_call (insn)
 /* Mark things set by a SET.  */
 
 static void
-mark_set (pat, insn)
-     rtx pat, insn;
+mark_set (rtx pat, rtx insn)
 {
   rtx dest = SET_DEST (pat);
 
@@ -2869,8 +2821,7 @@ mark_set (pat, insn)
 /* Record things set by a CLOBBER.  */
 
 static void
-mark_clobber (pat, insn)
-     rtx pat, insn;
+mark_clobber (rtx pat, rtx insn)
 {
   rtx clob = XEXP (pat, 0);
 
@@ -2887,8 +2838,7 @@ mark_clobber (pat, insn)
    This data is used by oprs_not_set_p.  */
 
 static void
-mark_oprs_set (insn)
-     rtx insn;
+mark_oprs_set (rtx insn)
 {
   rtx pat = PATTERN (insn);
   int i;
@@ -2920,26 +2870,25 @@ mark_oprs_set (insn)
 /* Allocate reaching def variables.  */
 
 static void
-alloc_rd_mem (n_blocks, n_insns)
-     int n_blocks, n_insns;
+alloc_rd_mem (int n_blocks, int n_insns)
 {
-  rd_kill = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_insns);
+  rd_kill = sbitmap_vector_alloc (n_blocks, n_insns);
   sbitmap_vector_zero (rd_kill, n_blocks);
 
-  rd_gen = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_insns);
+  rd_gen = sbitmap_vector_alloc (n_blocks, n_insns);
   sbitmap_vector_zero (rd_gen, n_blocks);
 
-  reaching_defs = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_insns);
+  reaching_defs = sbitmap_vector_alloc (n_blocks, n_insns);
   sbitmap_vector_zero (reaching_defs, n_blocks);
 
-  rd_out = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_insns);
+  rd_out = sbitmap_vector_alloc (n_blocks, n_insns);
   sbitmap_vector_zero (rd_out, n_blocks);
 }
 
 /* Free reaching def variables.  */
 
 static void
-free_rd_mem ()
+free_rd_mem (void)
 {
   sbitmap_vector_free (rd_kill);
   sbitmap_vector_free (rd_gen);
@@ -2950,10 +2899,7 @@ free_rd_mem ()
 /* Add INSN to the kills of BB.  REGNO, set in BB, is killed by INSN.  */
 
 static void
-handle_rd_kill_set (insn, regno, bb)
-     rtx insn;
-     int regno;
-     basic_block bb;
+handle_rd_kill_set (rtx insn, int regno, basic_block bb)
 {
   struct reg_set *this_reg;
 
@@ -2965,7 +2911,7 @@ handle_rd_kill_set (insn, regno, bb)
 /* Compute the set of kill's for reaching definitions.  */
 
 static void
-compute_kill_rd ()
+compute_kill_rd (void)
 {
   int cuid;
   unsigned int regno;
@@ -3020,7 +2966,7 @@ compute_kill_rd ()
    expressions but applied to the gens and kills of reaching definitions.  */
 
 static void
-compute_rd ()
+compute_rd (void)
 {
   int changed, passes;
   basic_block bb;
@@ -3051,24 +2997,23 @@ compute_rd ()
 /* Allocate memory for available expression computation.  */
 
 static void
-alloc_avail_expr_mem (n_blocks, n_exprs)
-     int n_blocks, n_exprs;
+alloc_avail_expr_mem (int n_blocks, int n_exprs)
 {
-  ae_kill = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_exprs);
+  ae_kill = sbitmap_vector_alloc (n_blocks, n_exprs);
   sbitmap_vector_zero (ae_kill, n_blocks);
 
-  ae_gen = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_exprs);
+  ae_gen = sbitmap_vector_alloc (n_blocks, n_exprs);
   sbitmap_vector_zero (ae_gen, n_blocks);
 
-  ae_in = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_exprs);
+  ae_in = sbitmap_vector_alloc (n_blocks, n_exprs);
   sbitmap_vector_zero (ae_in, n_blocks);
 
-  ae_out = (sbitmap *) sbitmap_vector_alloc (n_blocks, n_exprs);
+  ae_out = sbitmap_vector_alloc (n_blocks, n_exprs);
   sbitmap_vector_zero (ae_out, n_blocks);
 }
 
 static void
-free_avail_expr_mem ()
+free_avail_expr_mem (void)
 {
   sbitmap_vector_free (ae_kill);
   sbitmap_vector_free (ae_gen);
@@ -3079,8 +3024,7 @@ free_avail_expr_mem ()
 /* Compute the set of available expressions generated in each basic block.  */
 
 static void
-compute_ae_gen (expr_hash_table)
-     struct hash_table *expr_hash_table;
+compute_ae_gen (struct hash_table *expr_hash_table)
 {
   unsigned int i;
   struct expr *expr;
@@ -3099,9 +3043,7 @@ compute_ae_gen (expr_hash_table)
 /* Return nonzero if expression X is killed in BB.  */
 
 static int
-expr_killed_p (x, bb)
-     rtx x;
-     basic_block bb;
+expr_killed_p (rtx x, basic_block bb)
 {
   int i, j;
   enum rtx_code code;
@@ -3162,9 +3104,8 @@ expr_killed_p (x, bb)
 /* Compute the set of available expressions killed in each basic block.  */
 
 static void
-compute_ae_kill (ae_gen, ae_kill, expr_hash_table)
-     sbitmap *ae_gen, *ae_kill;
-     struct hash_table *expr_hash_table;
+compute_ae_kill (sbitmap *ae_gen, sbitmap *ae_kill,
+                struct hash_table *expr_hash_table)
 {
   basic_block bb;
   unsigned int i;
@@ -3202,12 +3143,8 @@ compute_ae_kill (ae_gen, ae_kill, expr_hash_table)
    the closest such expression.  */
 
 static int
-expr_reaches_here_p_work (occr, expr, bb, check_self_loop, visited)
-     struct occr *occr;
-     struct expr *expr;
-     basic_block bb;
-     int check_self_loop;
-     char *visited;
+expr_reaches_here_p_work (struct occr *occr, struct expr *expr,
+                         basic_block bb, int check_self_loop, char *visited)
 {
   edge pred;
 
@@ -3264,14 +3201,11 @@ expr_reaches_here_p_work (occr, expr, bb, check_self_loop, visited)
    memory allocated for that function is returned.  */
 
 static int
-expr_reaches_here_p (occr, expr, bb, check_self_loop)
-     struct occr *occr;
-     struct expr *expr;
-     basic_block bb;
-     int check_self_loop;
+expr_reaches_here_p (struct occr *occr, struct expr *expr, basic_block bb,
+                    int check_self_loop)
 {
   int rval;
-  char *visited = (char *) xcalloc (last_basic_block, 1);
+  char *visited = xcalloc (last_basic_block, 1);
 
   rval = expr_reaches_here_p_work (occr, expr, bb, check_self_loop, visited);
 
@@ -3285,9 +3219,7 @@ expr_reaches_here_p (occr, expr, bb, check_self_loop)
    Called only by handle_avail_expr.  */
 
 static rtx
-computing_insn (expr, insn)
-     struct expr *expr;
-     rtx insn;
+computing_insn (struct expr *expr, rtx insn)
 {
   basic_block bb = BLOCK_FOR_INSN (insn);
 
@@ -3350,8 +3282,7 @@ computing_insn (expr, insn)
    Only called by can_disregard_other_sets.  */
 
 static int
-def_reaches_here_p (insn, def_insn)
-     rtx insn, def_insn;
+def_reaches_here_p (rtx insn, rtx def_insn)
 {
   rtx reg;
 
@@ -3387,10 +3318,7 @@ def_reaches_here_p (insn, def_insn)
    always safe to return zero.  */
 
 static int
-can_disregard_other_sets (addr_this_reg, insn, for_combine)
-     struct reg_set **addr_this_reg;
-     rtx insn;
-     int for_combine;
+can_disregard_other_sets (struct reg_set **addr_this_reg, rtx insn, int for_combine)
 {
   int number_of_reaching_defs = 0;
   struct reg_set *this_reg;
@@ -3435,9 +3363,7 @@ can_disregard_other_sets (addr_this_reg, insn, for_combine)
    The result is nonzero if any changes were made.  */
 
 static int
-handle_avail_expr (insn, expr)
-     rtx insn;
-     struct expr *expr;
+handle_avail_expr (rtx insn, struct expr *expr)
 {
   rtx pat, insn_computes_expr, expr_set;
   rtx to;
@@ -3593,7 +3519,7 @@ handle_avail_expr (insn, expr)
    The result is nonzero if a change was made.  */
 
 static int
-classic_gcse ()
+classic_gcse (void)
 {
   int changed;
   rtx insn;
@@ -3652,8 +3578,7 @@ classic_gcse ()
    Return nonzero if a change was made.  */
 
 static int
-one_classic_gcse_pass (pass)
-     int pass;
+one_classic_gcse_pass (int pass)
 {
   int changed = 0;
 
@@ -3706,8 +3631,7 @@ static sbitmap *cprop_avout;
    basic blocks.  N_SETS is the number of sets.  */
 
 static void
-alloc_cprop_mem (n_blocks, n_sets)
-     int n_blocks, n_sets;
+alloc_cprop_mem (int n_blocks, int n_sets)
 {
   cprop_pavloc = sbitmap_vector_alloc (n_blocks, n_sets);
   cprop_absaltered = sbitmap_vector_alloc (n_blocks, n_sets);
@@ -3719,7 +3643,7 @@ alloc_cprop_mem (n_blocks, n_sets)
 /* Free vars used by copy/const propagation.  */
 
 static void
-free_cprop_mem ()
+free_cprop_mem (void)
 {
   sbitmap_vector_free (cprop_pavloc);
   sbitmap_vector_free (cprop_absaltered);
@@ -3734,11 +3658,7 @@ free_cprop_mem ()
    bit in BMAP.  */
 
 static void
-compute_transp (x, indx, bmap, set_p)
-     rtx x;
-     int indx;
-     sbitmap *bmap;
-     int set_p;
+compute_transp (rtx x, int indx, sbitmap *bmap, int set_p)
 {
   int i, j;
   basic_block bb;
@@ -3869,7 +3789,7 @@ compute_transp (x, indx, bmap, set_p)
    propagation.  */
 
 static void
-compute_cprop_data ()
+compute_cprop_data (void)
 {
   compute_local_properties (cprop_absaltered, cprop_pavloc, NULL, &set_hash_table);
   compute_available (cprop_pavloc, cprop_absaltered,
@@ -3896,9 +3816,7 @@ static int reg_use_count;
    This doesn't hurt anything but it will slow things down.  */
 
 static void
-find_used_regs (xptr, data)
-     rtx *xptr;
-     void *data ATTRIBUTE_UNUSED;
+find_used_regs (rtx *xptr, void *data ATTRIBUTE_UNUSED)
 {
   int i, j;
   enum rtx_code code;
@@ -3948,8 +3866,7 @@ find_used_regs (xptr, data)
    Returns nonzero is successful.  */
 
 static int
-try_replace_reg (from, to, insn)
-     rtx from, to, insn;
+try_replace_reg (rtx from, rtx to, rtx insn)
 {
   rtx note = find_reg_equal_equiv_note (insn);
   rtx src = 0;
@@ -3969,6 +3886,11 @@ try_replace_reg (from, to, insn)
        validate_change (insn, &SET_SRC (set), src, 0);
     }
 
+  /* If there is already a NOTE, update the expression in it with our
+     replacement.  */
+  if (note != 0)
+    XEXP (note, 0) = simplify_replace_rtx (XEXP (note, 0), from, to);
+
   if (!success && set && reg_mentioned_p (from, SET_SRC (set)))
     {
       /* If above failed and this is a single set, try to simplify the source of
@@ -3980,17 +3902,15 @@ try_replace_reg (from, to, insn)
          && validate_change (insn, &SET_SRC (set), src, 0))
        success = 1;
 
-      /* If we've failed to do replacement, have a single SET, and don't already
-        have a note, add a REG_EQUAL note to not lose information.  */
-      if (!success && note == 0 && set != 0)
+      /* If we've failed to do replacement, have a single SET, don't already
+        have a note, and have no special SET, add a REG_EQUAL note to not
+        lose information.  */
+      if (!success && note == 0 && set != 0
+         && GET_CODE (XEXP (set, 0)) != ZERO_EXTRACT
+         && GET_CODE (XEXP (set, 0)) != SIGN_EXTRACT)
        note = set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src));
     }
 
-  /* If there is already a NOTE, update the expression in it with our
-     replacement.  */
-  else if (note != 0)
-    XEXP (note, 0) = simplify_replace_rtx (XEXP (note, 0), from, to);
-
   /* REG_EQUAL may get simplified into register.
      We don't allow that. Remove that note. This code ought
      not to happen, because previous code ought to synthesize
@@ -4005,9 +3925,7 @@ try_replace_reg (from, to, insn)
    NULL no such set is found.  */
 
 static struct expr *
-find_avail_set (regno, insn)
-     int regno;
-     rtx insn;
+find_avail_set (int regno, rtx insn)
 {
   /* SET1 contains the last set found that can be returned to the caller for
      use in a substitution.  */
@@ -4079,12 +3997,7 @@ find_avail_set (regno, insn)
    if a change was made.  */
 
 static int
-cprop_jump (bb, setcc, jump, from, src)
-     basic_block bb;
-     rtx setcc;
-     rtx jump;
-     rtx from;
-     rtx src;
+cprop_jump (basic_block bb, rtx setcc, rtx jump, rtx from, rtx src)
 {
   rtx new, set_src, note_src;
   rtx set = pc_set (jump);
@@ -4183,11 +4096,7 @@ cprop_jump (bb, setcc, jump, from, src)
 }
 
 static bool
-constprop_register (insn, from, to, alter_jumps)
-     rtx insn;
-     rtx from;
-     rtx to;
-     int alter_jumps;
+constprop_register (rtx insn, rtx from, rtx to, int alter_jumps)
 {
   rtx sset;
 
@@ -4224,9 +4133,7 @@ constprop_register (insn, from, to, alter_jumps)
    The result is nonzero if a change was made.  */
 
 static int
-cprop_insn (insn, alter_jumps)
-     rtx insn;
-     int alter_jumps;
+cprop_insn (rtx insn, int alter_jumps)
 {
   struct reg_use *reg_used;
   int changed = 0;
@@ -4325,9 +4232,7 @@ cprop_insn (insn, alter_jumps)
    can legitimately make replacements.  */
 
 static void
-local_cprop_find_used_regs (xptr, data)
-     rtx *xptr;
-     void *data;
+local_cprop_find_used_regs (rtx *xptr, void *data)
 {
   rtx x = *xptr;
 
@@ -4365,16 +4270,12 @@ local_cprop_find_used_regs (xptr, data)
 
   find_used_regs (xptr, data);
 }
-  
+
 /* LIBCALL_SP is a zero-terminated array of insns at the end of a libcall;
    their REG_EQUAL notes need updating.  */
 
 static bool
-do_local_cprop (x, insn, alter_jumps, libcall_sp)
-     rtx x;
-     rtx insn;
-     int alter_jumps;
-     rtx *libcall_sp;
+do_local_cprop (rtx x, rtx insn, int alter_jumps, rtx *libcall_sp)
 {
   rtx newreg = NULL, newcnst = NULL;
 
@@ -4453,8 +4354,7 @@ do_local_cprop (x, insn, alter_jumps, libcall_sp)
    replaced with NEWVAL in INSN.  Return true if all substitutions could
    be made.  */
 static bool
-adjust_libcall_notes (oldreg, newval, insn, libcall_sp)
-     rtx oldreg, newval, insn, *libcall_sp;
+adjust_libcall_notes (rtx oldreg, rtx newval, rtx insn, rtx *libcall_sp)
 {
   rtx end;
 
@@ -4490,8 +4390,7 @@ adjust_libcall_notes (oldreg, newval, insn, libcall_sp)
 #define MAX_NESTED_LIBCALLS 9
 
 static void
-local_cprop_pass (alter_jumps)
-     int alter_jumps;
+local_cprop_pass (int alter_jumps)
 {
   rtx insn;
   struct reg_use *reg_used;
@@ -4554,8 +4453,7 @@ local_cprop_pass (alter_jumps)
    nonzero if a change was made.  */
 
 static int
-cprop (alter_jumps)
-     int alter_jumps;
+cprop (int alter_jumps)
 {
   int changed;
   basic_block bb;
@@ -4608,8 +4506,7 @@ cprop (alter_jumps)
    but this would require some code reorganization.  */
 
 rtx
-fis_get_condition (jump)
-     rtx jump;
+fis_get_condition (rtx jump)
 {
   rtx cond, set, tmp, insn, earliest;
   bool reverse;
@@ -4627,7 +4524,8 @@ fis_get_condition (jump)
 
   /* Use canonicalize_condition to do the dirty work of manipulating
      MODE_CC values and COMPARE rtx codes.  */
-  tmp = canonicalize_condition (jump, cond, reverse, &earliest, NULL_RTX);
+  tmp = canonicalize_condition (jump, cond, reverse, &earliest, NULL_RTX,
+                               false);
   if (!tmp)
     return NULL_RTX;
 
@@ -4645,7 +4543,8 @@ fis_get_condition (jump)
   tmp = XEXP (tmp, 0);
   if (!REG_P (tmp) || GET_MODE_CLASS (GET_MODE (tmp)) != MODE_INT)
     return NULL_RTX;
-  tmp = canonicalize_condition (jump, cond, reverse, &earliest, tmp);
+  tmp = canonicalize_condition (jump, cond, reverse, &earliest, tmp,
+                               false);
   if (!tmp)
     return NULL_RTX;
 
@@ -4665,7 +4564,7 @@ fis_get_condition (jump)
    basic block.  */
 
 static void
-find_implicit_sets ()
+find_implicit_sets (void)
 {
   basic_block bb, dest;
   unsigned int count;
@@ -4673,7 +4572,7 @@ find_implicit_sets ()
 
   count = 0;
   FOR_EACH_BB (bb)
-    /* Check for more than one sucessor.  */
+    /* Check for more than one successor.  */
     if (bb->succ && bb->succ->succ_next)
       {
        cond = fis_get_condition (bb->end);
@@ -4714,10 +4613,7 @@ find_implicit_sets ()
    perform conditional jump bypassing optimizations.  */
 
 static int
-one_cprop_pass (pass, cprop_jumps, bypass_jumps)
-     int pass;
-     int cprop_jumps;
-     int bypass_jumps;
+one_cprop_pass (int pass, int cprop_jumps, int bypass_jumps)
 {
   int changed = 0;
 
@@ -4727,7 +4623,7 @@ one_cprop_pass (pass, cprop_jumps, bypass_jumps)
   local_cprop_pass (cprop_jumps);
 
   /* Determine implicit sets.  */
-  implicit_sets = (rtx *) xcalloc (last_basic_block, sizeof (rtx));
+  implicit_sets = xcalloc (last_basic_block, sizeof (rtx));
   find_implicit_sets ();
 
   alloc_hash_table (max_cuid, &set_hash_table, 1);
@@ -4779,9 +4675,7 @@ static int bypass_last_basic_block;
    find_avail_set.  */
 
 static struct expr *
-find_bypass_set (regno, bb)
-     int regno;
-     int bb;
+find_bypass_set (int regno, int bb)
 {
   struct expr *result = 0;
 
@@ -4823,9 +4717,7 @@ find_bypass_set (regno, bb)
    valid prior to commit_edge_insertions.  */
 
 static bool
-reg_killed_on_edge (reg, e)
-     rtx reg;
-     edge e;
+reg_killed_on_edge (rtx reg, edge e)
 {
   rtx insn;
 
@@ -4847,9 +4739,7 @@ reg_killed_on_edge (reg, e)
    these inserted insns when performing its transformations.  */
 
 static int
-bypass_block (bb, setcc, jump)
-     basic_block bb;
-     rtx setcc, jump;
+bypass_block (basic_block bb, rtx setcc, rtx jump)
 {
   rtx insn, note;
   edge e, enext, edest;
@@ -4921,7 +4811,7 @@ bypass_block (bb, setcc, jump)
          new = simplify_replace_rtx (src, reg_used->reg_rtx,
                                      SET_SRC (set->expr));
 
-         /* Jump bypassing may have already placed instructions on 
+         /* Jump bypassing may have already placed instructions on
             edges of the CFG.  We can't bypass an outgoing edge that
             has instructions associated with it, as these insns won't
             get executed if the incoming edge is redirected.  */
@@ -4985,7 +4875,7 @@ bypass_block (bb, setcc, jump)
    This function is now mis-named, because we also handle indirect jumps.  */
 
 static int
-bypass_conditional_jumps ()
+bypass_conditional_jumps (void)
 {
   basic_block bb;
   int changed;
@@ -5083,8 +4973,7 @@ static sbitmap pre_redundant_insns;
 /* Allocate vars used for PRE analysis.  */
 
 static void
-alloc_pre_mem (n_blocks, n_exprs)
-     int n_blocks, n_exprs;
+alloc_pre_mem (int n_blocks, int n_exprs)
 {
   transp = sbitmap_vector_alloc (n_blocks, n_exprs);
   comp = sbitmap_vector_alloc (n_blocks, n_exprs);
@@ -5104,7 +4993,7 @@ alloc_pre_mem (n_blocks, n_exprs)
 /* Free vars used for PRE analysis.  */
 
 static void
-free_pre_mem ()
+free_pre_mem (void)
 {
   sbitmap_vector_free (transp);
   sbitmap_vector_free (comp);
@@ -5132,7 +5021,7 @@ free_pre_mem ()
 /* Top level routine to do the dataflow analysis needed by PRE.  */
 
 static void
-compute_pre_data ()
+compute_pre_data (void)
 {
   sbitmap trapping_expr;
   basic_block bb;
@@ -5203,11 +5092,7 @@ compute_pre_data ()
    the closest such expression.  */
 
 static int
-pre_expr_reaches_here_p_work (occr_bb, expr, bb, visited)
-     basic_block occr_bb;
-     struct expr *expr;
-     basic_block bb;
-     char *visited;
+pre_expr_reaches_here_p_work (basic_block occr_bb, struct expr *expr, basic_block bb, char *visited)
 {
   edge pred;
 
@@ -5252,13 +5137,10 @@ pre_expr_reaches_here_p_work (occr_bb, expr, bb, visited)
    memory allocated for that function is returned.  */
 
 static int
-pre_expr_reaches_here_p (occr_bb, expr, bb)
-     basic_block occr_bb;
-     struct expr *expr;
-     basic_block bb;
+pre_expr_reaches_here_p (basic_block occr_bb, struct expr *expr, basic_block bb)
 {
   int rval;
-  char *visited = (char *) xcalloc (last_basic_block, 1);
+  char *visited = xcalloc (last_basic_block, 1);
 
   rval = pre_expr_reaches_here_p_work (occr_bb, expr, bb, visited);
 
@@ -5272,8 +5154,7 @@ pre_expr_reaches_here_p (occr_bb, expr, bb)
    the value of BB.  */
 
 static rtx
-process_insert_insn (expr)
-     struct expr *expr;
+process_insert_insn (struct expr *expr)
 {
   rtx reg = expr->reaching_reg;
   rtx exp = copy_rtx (expr->expr);
@@ -5307,10 +5188,7 @@ process_insert_insn (expr)
    no sense for code hoisting.  */
 
 static void
-insert_insn_end_bb (expr, bb, pre)
-     struct expr *expr;
-     basic_block bb;
-     int pre;
+insert_insn_end_bb (struct expr *expr, basic_block bb, int pre)
 {
   rtx insn = bb->end;
   rtx new_insn;
@@ -5439,9 +5317,7 @@ insert_insn_end_bb (expr, bb, pre)
    the expressions fully redundant.  */
 
 static int
-pre_edge_insert (edge_list, index_map)
-     struct edge_list *edge_list;
-     struct expr **index_map;
+pre_edge_insert (struct edge_list *edge_list, struct expr **index_map)
 {
   int e, i, j, num_edges, set_size, did_insert = 0;
   sbitmap *inserted;
@@ -5520,26 +5396,90 @@ pre_edge_insert (edge_list, index_map)
   return did_insert;
 }
 
-/* Copy the result of INSN to REG.  INDX is the expression number.  */
+/* Copy the result of EXPR->EXPR generated by INSN to EXPR->REACHING_REG.
+   Given "old_reg <- expr" (INSN), instead of adding after it
+     reaching_reg <- old_reg
+   it's better to do the following:
+     reaching_reg <- expr
+     old_reg      <- reaching_reg
+   because this way copy propagation can discover additional PRE
+   opportunities.  But if this fails, we try the old way.
+   When "expr" is a store, i.e.
+   given "MEM <- old_reg", instead of adding after it
+     reaching_reg <- old_reg
+   it's better to add it before as follows:
+     reaching_reg <- old_reg
+     MEM          <- reaching_reg.  */
 
 static void
-pre_insert_copy_insn (expr, insn)
-     struct expr *expr;
-     rtx insn;
+pre_insert_copy_insn (struct expr *expr, rtx insn)
 {
   rtx reg = expr->reaching_reg;
   int regno = REGNO (reg);
   int indx = expr->bitmap_index;
-  rtx set = single_set (insn);
-  rtx new_insn;
+  rtx pat = PATTERN (insn);
+  rtx set, new_insn;
+  rtx old_reg;
+  int i;
 
-  if (!set)
+  /* This block matches the logic in hash_scan_insn.  */
+  if (GET_CODE (pat) == SET)
+    set = pat;
+  else if (GET_CODE (pat) == PARALLEL)
+    {
+      /* Search through the parallel looking for the set whose
+        source was the expression that we're interested in.  */
+      set = NULL_RTX;
+      for (i = 0; i < XVECLEN (pat, 0); i++)
+       {
+         rtx x = XVECEXP (pat, 0, i);
+         if (GET_CODE (x) == SET
+             && expr_equiv_p (SET_SRC (x), expr->expr))
+           {
+             set = x;
+             break;
+           }
+       }
+    }
+  else
     abort ();
 
-  new_insn = emit_insn_after (gen_move_insn (reg, copy_rtx (SET_DEST (set))), insn);
+  if (GET_CODE (SET_DEST (set)) == REG)
+    {
+      old_reg = SET_DEST (set);
+      /* Check if we can modify the set destination in the original insn.  */
+      if (validate_change (insn, &SET_DEST (set), reg, 0))
+        {
+          new_insn = gen_move_insn (old_reg, reg);
+          new_insn = emit_insn_after (new_insn, insn);
+
+          /* Keep register set table up to date.  */
+          replace_one_set (REGNO (old_reg), insn, new_insn);
+          record_one_set (regno, insn);
+        }
+      else
+        {
+          new_insn = gen_move_insn (reg, old_reg);
+          new_insn = emit_insn_after (new_insn, insn);
+
+          /* Keep register set table up to date.  */
+          record_one_set (regno, new_insn);
+        }
+    }
+  else /* This is possible only in case of a store to memory.  */
+    {
+      old_reg = SET_SRC (set);
+      new_insn = gen_move_insn (reg, old_reg);
 
-  /* Keep register set table up to date.  */
-  record_one_set (regno, new_insn);
+      /* Check if we can modify the set source in the original insn.  */
+      if (validate_change (insn, &SET_SRC (set), reg, 0))
+        new_insn = emit_insn_before (new_insn, insn);
+      else
+        new_insn = emit_insn_after (new_insn, insn);
+
+      /* Keep register set table up to date.  */
+      record_one_set (regno, new_insn);
+    }
 
   gcse_create_count++;
 
@@ -5548,16 +5488,15 @@ pre_insert_copy_insn (expr, insn)
             "PRE: bb %d, insn %d, copy expression %d in insn %d to reg %d\n",
              BLOCK_NUM (insn), INSN_UID (new_insn), indx,
              INSN_UID (insn), regno);
-  update_ld_motion_stores (expr);
 }
 
 /* Copy available expressions that reach the redundant expression
    to `reaching_reg'.  */
 
 static void
-pre_insert_copies ()
+pre_insert_copies (void)
 {
-  unsigned int i;
+  unsigned int i, added_copy;
   struct expr *expr;
   struct occr *occr;
   struct occr *avail;
@@ -5578,6 +5517,9 @@ pre_insert_copies ()
           expression wasn't deleted anywhere.  */
        if (expr->reaching_reg == NULL)
          continue;
+       
+       /* Set when we add a copy for that expression.  */
+       added_copy = 0; 
 
        for (occr = expr->antic_occr; occr != NULL; occr = occr->next)
          {
@@ -5602,19 +5544,23 @@ pre_insert_copies ()
                                               BLOCK_FOR_INSN (occr->insn)))
                  continue;
 
+                added_copy = 1;
+
                /* Copy the result of avail to reaching_reg.  */
                pre_insert_copy_insn (expr, insn);
                avail->copied_p = 1;
              }
          }
+
+         if (added_copy)
+            update_ld_motion_stores (expr);
       }
 }
 
 /* Emit move from SRC to DEST noting the equivalence with expression computed
    in INSN.  */
 static rtx
-gcse_emit_move_after (src, dest, insn)
-     rtx src, dest, insn;
+gcse_emit_move_after (rtx src, rtx dest, rtx insn)
 {
   rtx new;
   rtx set = single_set (insn), set2;
@@ -5648,7 +5594,7 @@ gcse_emit_move_after (src, dest, insn)
    Returns nonzero if a change is made.  */
 
 static int
-pre_delete ()
+pre_delete (void)
 {
   unsigned int i;
   int changed;
@@ -5657,7 +5603,9 @@ pre_delete ()
 
   changed = 0;
   for (i = 0; i < expr_hash_table.size; i++)
-    for (expr = expr_hash_table.table[i]; expr != NULL; expr = expr->next_same_hash)
+    for (expr = expr_hash_table.table[i];
+        expr != NULL;
+        expr = expr->next_same_hash)
       {
        int indx = expr->bitmap_index;
 
@@ -5670,12 +5618,10 @@ pre_delete ()
            rtx set;
            basic_block bb = BLOCK_FOR_INSN (insn);
 
-           if (TEST_BIT (pre_delete_map[bb->index], indx))
+           /* We only delete insns that have a single_set.  */
+           if (TEST_BIT (pre_delete_map[bb->index], indx)
+               && (set = single_set (insn)) != 0)
              {
-               set = single_set (insn);
-               if (! set)
-                 abort ();
-
                /* Create a pseudo-reg to store the result of reaching
                   expressions into.  Get the mode for the new pseudo from
                   the mode of the original destination pseudo.  */
@@ -5726,7 +5672,7 @@ pre_delete ()
    redundancies.  */
 
 static int
-pre_gcse ()
+pre_gcse (void)
 {
   unsigned int i;
   int did_insert, changed;
@@ -5736,7 +5682,7 @@ pre_gcse ()
   /* Compute a mapping from expression number (`bitmap_index') to
      hash table entry.  */
 
-  index_map = (struct expr **) xcalloc (expr_hash_table.n_elems, sizeof (struct expr *));
+  index_map = xcalloc (expr_hash_table.n_elems, sizeof (struct expr *));
   for (i = 0; i < expr_hash_table.size; i++)
     for (expr = expr_hash_table.table[i]; expr != NULL; expr = expr->next_same_hash)
       index_map[expr->bitmap_index] = expr;
@@ -5773,8 +5719,7 @@ pre_gcse ()
    Return nonzero if a change was made.  */
 
 static int
-one_pre_gcse_pass (pass)
-     int pass;
+one_pre_gcse_pass (int pass)
 {
   int changed = 0;
 
@@ -5828,9 +5773,7 @@ one_pre_gcse_pass (pass)
    necessary REG_LABEL notes.  */
 
 static void
-add_label_notes (x, insn)
-     rtx x;
-     rtx insn;
+add_label_notes (rtx x, rtx insn)
 {
   enum rtx_code code = GET_CODE (x);
   int i, j;
@@ -5875,7 +5818,7 @@ add_label_notes (x, insn)
    EH table sizes, this may not be worthwhile.  */
 
 static void
-compute_transpout ()
+compute_transpout (void)
 {
   basic_block bb;
   unsigned int i;
@@ -5916,10 +5859,7 @@ compute_transpout ()
    We ignore hard registers.  */
 
 static void
-invalidate_nonnull_info (x, setter, data)
-     rtx x;
-     rtx setter ATTRIBUTE_UNUSED;
-     void *data;
+invalidate_nonnull_info (rtx x, rtx setter ATTRIBUTE_UNUSED, void *data)
 {
   unsigned int regno;
   struct null_pointer_info *npi = (struct null_pointer_info *) data;
@@ -5944,12 +5884,9 @@ invalidate_nonnull_info (x, setter, data)
    they are not our responsibility to free.  */
 
 static int
-delete_null_pointer_checks_1 (block_reg, nonnull_avin,
-                             nonnull_avout, npi)
-     unsigned int *block_reg;
-     sbitmap *nonnull_avin;
-     sbitmap *nonnull_avout;
-     struct null_pointer_info *npi;
+delete_null_pointer_checks_1 (unsigned int *block_reg, sbitmap *nonnull_avin,
+                             sbitmap *nonnull_avout,
+                             struct null_pointer_info *npi)
 {
   basic_block bb, current_block;
   sbitmap *nonnull_local = npi->nonnull_local;
@@ -6044,7 +5981,7 @@ delete_null_pointer_checks_1 (block_reg, nonnull_avin,
        continue;
 
       /* LAST_INSN is a conditional jump.  Get its condition.  */
-      condition = get_condition (last_insn, &earliest);
+      condition = get_condition (last_insn, &earliest, false);
 
       /* If we can't determine the condition then skip.  */
       if (! condition)
@@ -6116,36 +6053,24 @@ delete_null_pointer_checks_1 (block_reg, nonnull_avin,
    This could probably be integrated with global cprop with a little work.  */
 
 int
-delete_null_pointer_checks (f)
-     rtx f ATTRIBUTE_UNUSED;
+delete_null_pointer_checks (rtx f ATTRIBUTE_UNUSED)
 {
   sbitmap *nonnull_avin, *nonnull_avout;
   unsigned int *block_reg;
   basic_block bb;
   int reg;
   int regs_per_pass;
-  int max_reg;
+  int max_reg = max_reg_num ();
   struct null_pointer_info npi;
   int something_changed = 0;
 
-  /* If we have only a single block, then there's nothing to do.  */
-  if (n_basic_blocks <= 1)
-    return 0;
-
-  /* Trying to perform global optimizations on flow graphs which have
-     a high connectivity will take a long time and is unlikely to be
-     particularly useful.
-
-     In normal circumstances a cfg should have about twice as many edges
-     as blocks.  But we do not want to punish small functions which have
-     a couple switch statements.  So we require a relatively large number
-     of basic blocks and the ratio of edges to blocks to be high.  */
-  if (n_basic_blocks > 1000 && n_edges / n_basic_blocks >= 20)
+  /* If we have only a single block, or it is too expensive, give up.  */
+  if (n_basic_blocks <= 1
+      || is_too_expensive (_ ("NULL pointer checks disabled")))
     return 0;
 
   /* We need four bitmaps, each with a bit for each register in each
      basic block.  */
-  max_reg = max_reg_num ();
   regs_per_pass = get_bitmap_width (4, last_basic_block, max_reg);
 
   /* Allocate bitmaps to hold local and global properties.  */
@@ -6157,7 +6082,7 @@ delete_null_pointer_checks (f)
   /* Go through the basic blocks, seeing whether or not each block
      ends with a conditional branch whose condition is a comparison
      against zero.  Record the register compared in BLOCK_REG.  */
-  block_reg = (unsigned int *) xcalloc (last_basic_block, sizeof (int));
+  block_reg = xcalloc (last_basic_block, sizeof (int));
   FOR_EACH_BB (bb)
     {
       rtx last_insn = bb->end;
@@ -6170,7 +6095,7 @@ delete_null_pointer_checks (f)
        continue;
 
       /* LAST_INSN is a conditional jump.  Get its condition.  */
-      condition = get_condition (last_insn, &earliest);
+      condition = get_condition (last_insn, &earliest, false);
 
       /* If we were unable to get the condition, or it is not an equality
         comparison against zero then there's nothing we can do.  */
@@ -6234,8 +6159,7 @@ dominance_info dominators;
 /* Allocate vars used for code hoisting analysis.  */
 
 static void
-alloc_code_hoist_mem (n_blocks, n_exprs)
-     int n_blocks, n_exprs;
+alloc_code_hoist_mem (int n_blocks, int n_exprs)
 {
   antloc = sbitmap_vector_alloc (n_blocks, n_exprs);
   transp = sbitmap_vector_alloc (n_blocks, n_exprs);
@@ -6250,7 +6174,7 @@ alloc_code_hoist_mem (n_blocks, n_exprs)
 /* Free vars used for code hoisting analysis.  */
 
 static void
-free_code_hoist_mem ()
+free_code_hoist_mem (void)
 {
   sbitmap_vector_free (antloc);
   sbitmap_vector_free (transp);
@@ -6270,7 +6194,7 @@ free_code_hoist_mem ()
    compute the expression.  */
 
 static void
-compute_code_hoist_vbeinout ()
+compute_code_hoist_vbeinout (void)
 {
   int changed, passes;
   basic_block bb;
@@ -6305,7 +6229,7 @@ compute_code_hoist_vbeinout ()
 /* Top level routine to do the dataflow analysis needed by code hoisting.  */
 
 static void
-compute_code_hoist_data ()
+compute_code_hoist_data (void)
 {
   compute_local_properties (transp, comp, antloc, &expr_hash_table);
   compute_transpout ();
@@ -6329,11 +6253,7 @@ compute_code_hoist_data ()
    paths.  */
 
 static int
-hoist_expr_reaches_here_p (expr_bb, expr_index, bb, visited)
-     basic_block expr_bb;
-     int expr_index;
-     basic_block bb;
-     char *visited;
+hoist_expr_reaches_here_p (basic_block expr_bb, int expr_index, basic_block bb, char *visited)
 {
   edge pred;
   int visited_allocated_locally = 0;
@@ -6380,7 +6300,7 @@ hoist_expr_reaches_here_p (expr_bb, expr_index, bb, visited)
 /* Actually perform code hoisting.  */
 
 static void
-hoist_code ()
+hoist_code (void)
 {
   basic_block bb, dominated;
   basic_block *domby;
@@ -6394,7 +6314,7 @@ hoist_code ()
   /* Compute a mapping from expression number (`bitmap_index') to
      hash table entry.  */
 
-  index_map = (struct expr **) xcalloc (expr_hash_table.n_elems, sizeof (struct expr *));
+  index_map = xcalloc (expr_hash_table.n_elems, sizeof (struct expr *));
   for (i = 0; i < expr_hash_table.size; i++)
     for (expr = expr_hash_table.table[i]; expr != NULL; expr = expr->next_same_hash)
       index_map[expr->bitmap_index] = expr;
@@ -6460,7 +6380,7 @@ hoist_code ()
       /* If we found nothing to hoist, then quit now.  */
       if (! found)
         {
-         free (domby);
+         free (domby);
        continue;
        }
 
@@ -6546,7 +6466,7 @@ hoist_code ()
    Return nonzero if a change was made.  */
 
 static int
-one_code_hoisting_pass ()
+one_code_hoisting_pass (void)
 {
   int changed = 0;
 
@@ -6597,8 +6517,7 @@ one_code_hoisting_pass ()
    doesn't find one, we create one and initialize it.  */
 
 static struct ls_expr *
-ldst_entry (x)
-     rtx x;
+ldst_entry (rtx x)
 {
   struct ls_expr * ptr;
 
@@ -6608,7 +6527,7 @@ ldst_entry (x)
 
   if (!ptr)
     {
-      ptr = (struct ls_expr *) xmalloc (sizeof (struct ls_expr));
+      ptr = xmalloc (sizeof (struct ls_expr));
 
       ptr->next         = pre_ldst_mems;
       ptr->expr         = NULL;
@@ -6629,8 +6548,7 @@ ldst_entry (x)
 /* Free up an individual ldst entry.  */
 
 static void
-free_ldst_entry (ptr)
-     struct ls_expr * ptr;
+free_ldst_entry (struct ls_expr * ptr)
 {
   free_INSN_LIST_list (& ptr->loads);
   free_INSN_LIST_list (& ptr->stores);
@@ -6641,7 +6559,7 @@ free_ldst_entry (ptr)
 /* Free up all memory associated with the ldst list.  */
 
 static void
-free_ldst_mems ()
+free_ldst_mems (void)
 {
   while (pre_ldst_mems)
     {
@@ -6658,8 +6576,7 @@ free_ldst_mems ()
 /* Dump debugging info about the ldst list.  */
 
 static void
-print_ldst_list (file)
-     FILE * file;
+print_ldst_list (FILE * file)
 {
   struct ls_expr * ptr;
 
@@ -6694,8 +6611,7 @@ print_ldst_list (file)
 /* Returns 1 if X is in the list of ldst only expressions.  */
 
 static struct ls_expr *
-find_rtx_in_ldst (x)
-     rtx x;
+find_rtx_in_ldst (rtx x)
 {
   struct ls_expr * ptr;
 
@@ -6709,7 +6625,7 @@ find_rtx_in_ldst (x)
 /* Assign each element of the list of mems a monotonically increasing value.  */
 
 static int
-enumerate_ldsts ()
+enumerate_ldsts (void)
 {
   struct ls_expr * ptr;
   int n = 0;
@@ -6723,7 +6639,7 @@ enumerate_ldsts ()
 /* Return first item in the list.  */
 
 static inline struct ls_expr *
-first_ls_expr ()
+first_ls_expr (void)
 {
   return pre_ldst_mems;
 }
@@ -6731,8 +6647,7 @@ first_ls_expr ()
 /* Return the next item in the list after the specified one.  */
 
 static inline struct ls_expr *
-next_ls_expr (ptr)
-     struct ls_expr * ptr;
+next_ls_expr (struct ls_expr * ptr)
 {
   return ptr->next;
 }
@@ -6744,8 +6659,7 @@ next_ls_expr (ptr)
    ld_motion list, otherwise we let the usual aliasing take care of it.  */
 
 static int
-simple_mem (x)
-     rtx x;
+simple_mem (rtx x)
 {
   if (GET_CODE (x) != MEM)
     return 0;
@@ -6784,8 +6698,7 @@ simple_mem (x)
    fix it up.  */
 
 static void
-invalidate_any_buried_refs (x)
-     rtx x;
+invalidate_any_buried_refs (rtx x)
 {
   const char * fmt;
   int i, j;
@@ -6820,7 +6733,7 @@ invalidate_any_buried_refs (x)
    later.  */
 
 static void
-compute_ld_motion_mems ()
+compute_ld_motion_mems (void)
 {
   struct ls_expr * ptr;
   basic_block bb;
@@ -6885,7 +6798,7 @@ compute_ld_motion_mems ()
    expression list for pre gcse.  */
 
 static void
-trim_ld_motion_mems ()
+trim_ld_motion_mems (void)
 {
   struct ls_expr * last = NULL;
   struct ls_expr * ptr = first_ls_expr ();
@@ -6947,13 +6860,12 @@ trim_ld_motion_mems ()
 /* This routine will take an expression which we are replacing with
    a reaching register, and update any stores that are needed if
    that expression is in the ld_motion list.  Stores are updated by
-   copying their SRC to the reaching register, and then storeing
+   copying their SRC to the reaching register, and then storing
    the reaching register into the store location. These keeps the
    correct value in the reaching register for the loads.  */
 
 static void
-update_ld_motion_stores (expr)
-     struct expr * expr;
+update_ld_motion_stores (struct expr * expr)
 {
   struct ls_expr * mem_ptr;
 
@@ -7024,9 +6936,8 @@ static int num_stores;
 /* Checks to set if we need to mark a register set. Called from note_stores.  */
 
 static void
-reg_set_info (dest, setter, data)
-     rtx dest, setter ATTRIBUTE_UNUSED;
-     void * data ATTRIBUTE_UNUSED;
+reg_set_info (rtx dest, rtx setter ATTRIBUTE_UNUSED,
+             void *data ATTRIBUTE_UNUSED)
 {
   if (GET_CODE (dest) == SUBREG)
     dest = SUBREG_REG (dest);
@@ -7037,11 +6948,9 @@ reg_set_info (dest, setter, data)
 
 /* Return zero if some of the registers in list X are killed
    due to set of registers in bitmap REGS_SET.  */
-  
+
 static bool
-store_ops_ok (x, regs_set)
-     rtx x;
-     int *regs_set;
+store_ops_ok (rtx x, int *regs_set)
 {
   rtx reg;
 
@@ -7049,7 +6958,7 @@ store_ops_ok (x, regs_set)
     {
       reg = XEXP (x, 0);
       if (regs_set[REGNO(reg)])
-       return false; 
+       return false;
     }
 
   return true;
@@ -7057,8 +6966,7 @@ store_ops_ok (x, regs_set)
 
 /* Returns a list of registers mentioned in X.  */
 static rtx
-extract_mentioned_regs (x)
-     rtx x;
+extract_mentioned_regs (rtx x)
 {
   return extract_mentioned_regs_helper (x, NULL_RTX);
 }
@@ -7066,9 +6974,7 @@ extract_mentioned_regs (x)
 /* Helper for extract_mentioned_regs; ACCUM is used to accumulate used
    registers.  */
 static rtx
-extract_mentioned_regs_helper (x, accum)
-     rtx x;
-     rtx accum;
+extract_mentioned_regs_helper (rtx x, rtx accum)
 {
   int i;
   enum rtx_code code;
@@ -7149,7 +7055,7 @@ extract_mentioned_regs_helper (x, accum)
    current insn, REGS_SET_AFTER is bitmap of registers set after (and
    including) the insn in this basic block.  We must be passing through BB from
    head to end, as we are using this fact to speed things up.
-   
+
    The results are stored this way:
 
    -- the first anticipatable expression is added into ANTIC_STORE_LIST
@@ -7167,10 +7073,7 @@ extract_mentioned_regs_helper (x, accum)
    */
 
 static void
-find_moveable_store (insn, regs_set_before, regs_set_after)
-     rtx insn;
-     int *regs_set_before;
-     int *regs_set_after;
+find_moveable_store (rtx insn, int *regs_set_before, int *regs_set_after)
 {
   struct ls_expr * ptr;
   rtx dest, set, tmp;
@@ -7195,7 +7098,7 @@ find_moveable_store (insn, regs_set_before, regs_set_after)
      continue.  */
   if (flag_non_call_exceptions && may_trap_p (dest))
     return;
-    
+
   ptr = ldst_entry (dest);
   if (!ptr->pattern_regs)
     ptr->pattern_regs = extract_mentioned_regs (dest);
@@ -7255,11 +7158,11 @@ find_moveable_store (insn, regs_set_before, regs_set_after)
   if (!check_available)
     AVAIL_STORE_LIST (ptr) = alloc_INSN_LIST (insn, AVAIL_STORE_LIST (ptr));
 }
-  
+
 /* Find available and anticipatable stores.  */
 
 static int
-compute_store_table ()
+compute_store_table (void)
 {
   int ret;
   basic_block bb;
@@ -7270,7 +7173,7 @@ compute_store_table ()
 
   max_gcse_regno = max_reg_num ();
 
-  reg_set_in_block = (sbitmap *) sbitmap_vector_alloc (last_basic_block,
+  reg_set_in_block = sbitmap_vector_alloc (last_basic_block,
                                                       max_gcse_regno);
   sbitmap_vector_zero (reg_set_in_block, last_basic_block);
   pre_ldst_mems = 0;
@@ -7391,23 +7294,27 @@ compute_store_table ()
   return ret;
 }
 
-/* Check to see if the load X is aliased with STORE_PATTERN.  */
+/* Check to see if the load X is aliased with STORE_PATTERN.
+   AFTER is true if we are checking the case when STORE_PATTERN occurs
+   after the X.  */
 
 static bool
-load_kills_store (x, store_pattern)
-     rtx x, store_pattern;
+load_kills_store (rtx x, rtx store_pattern, int after)
 {
-  if (true_dependence (x, GET_MODE (x), store_pattern, rtx_addr_varies_p))
-    return true;
-  return false;
+  if (after)
+    return anti_dependence (x, store_pattern);
+  else
+    return true_dependence (store_pattern, GET_MODE (store_pattern), x,
+                           rtx_addr_varies_p);
 }
 
 /* Go through the entire insn X, looking for any loads which might alias
-   STORE_PATTERN.  Return true if found.  */
+   STORE_PATTERN.  Return true if found.
+   AFTER is true if we are checking the case when STORE_PATTERN occurs
+   after the insn X.  */
 
 static bool
-find_loads (x, store_pattern)
-     rtx x, store_pattern;
+find_loads (rtx x, rtx store_pattern, int after)
 {
   const char * fmt;
   int i, j;
@@ -7421,7 +7328,7 @@ find_loads (x, store_pattern)
 
   if (GET_CODE (x) == MEM)
     {
-      if (load_kills_store (x, store_pattern))
+      if (load_kills_store (x, store_pattern, after))
        return true;
     }
 
@@ -7431,22 +7338,22 @@ find_loads (x, store_pattern)
   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0 && !ret; i--)
     {
       if (fmt[i] == 'e')
-       ret |= find_loads (XEXP (x, i), store_pattern);
+       ret |= find_loads (XEXP (x, i), store_pattern, after);
       else if (fmt[i] == 'E')
        for (j = XVECLEN (x, i) - 1; j >= 0; j--)
-         ret |= find_loads (XVECEXP (x, i, j), store_pattern);
+         ret |= find_loads (XVECEXP (x, i, j), store_pattern, after);
     }
   return ret;
 }
 
 /* Check if INSN kills the store pattern X (is aliased with it).
-   Return true if it it does.  */
+   AFTER is true if we are checking the case when store X occurs
+   after the insn.  Return true if it it does.  */
 
 static bool
-store_killed_in_insn (x, x_regs, insn)
-     rtx x, x_regs, insn;
+store_killed_in_insn (rtx x, rtx x_regs, rtx insn, int after)
 {
-  rtx reg, base;
+  rtx reg, base, note;
 
   if (!INSN_P (insn))
     return false;
@@ -7476,15 +7383,47 @@ store_killed_in_insn (x, x_regs, insn)
   if (GET_CODE (PATTERN (insn)) == SET)
     {
       rtx pat = PATTERN (insn);
+      rtx dest = SET_DEST (pat);
+
+      if (GET_CODE (dest) == SIGN_EXTRACT
+         || GET_CODE (dest) == ZERO_EXTRACT)
+       dest = XEXP (dest, 0);
+
       /* Check for memory stores to aliased objects.  */
-      if (GET_CODE (SET_DEST (pat)) == MEM && !expr_equiv_p (SET_DEST (pat), x))
-       /* pretend its a load and check for aliasing.  */
-       if (find_loads (SET_DEST (pat), x))
-         return true;
-      return find_loads (SET_SRC (pat), x);
+      if (GET_CODE (dest) == MEM
+         && !expr_equiv_p (dest, x))
+       {
+         if (after)
+           {
+             if (output_dependence (dest, x))
+               return true;
+           }
+         else
+           {
+             if (output_dependence (x, dest))
+               return true;
+           }
+       }
+      if (find_loads (SET_SRC (pat), x, after))
+       return true;
     }
-  else
-    return find_loads (PATTERN (insn), x);
+  else if (find_loads (PATTERN (insn), x, after))
+    return true;
+
+  /* If this insn has a REG_EQUAL or REG_EQUIV note referencing a memory
+     location aliased with X, then this insn kills X.  */
+  note = find_reg_equal_equiv_note (insn);
+  if (! note)
+    return false;
+  note = XEXP (note, 0);
+
+  /* However, if the note represents a must alias rather than a may
+     alias relationship, then it does not kill X.  */
+  if (expr_equiv_p (note, x))
+    return false;
+
+  /* See if there are any aliased loads in the note.  */
+  return find_loads (note, x, after);
 }
 
 /* Returns true if the expression X is loaded or clobbered on or after INSN
@@ -7493,16 +7432,13 @@ store_killed_in_insn (x, x_regs, insn)
    is killed, return the last insn in that it occurs in FAIL_INSN.  */
 
 static bool
-store_killed_after (x, x_regs, insn, bb, regs_set_after, fail_insn)
-     rtx x, x_regs, insn;
-     basic_block bb;
-     int *regs_set_after;
-     rtx *fail_insn;
+store_killed_after (rtx x, rtx x_regs, rtx insn, basic_block bb,
+                   int *regs_set_after, rtx *fail_insn)
 {
   rtx last = bb->end, act;
 
   if (!store_ops_ok (x_regs, regs_set_after))
-    { 
+    {
       /* We do not know where it will happen.  */
       if (fail_insn)
        *fail_insn = NULL_RTX;
@@ -7511,7 +7447,7 @@ store_killed_after (x, x_regs, insn, bb, regs_set_after, fail_insn)
 
   /* Scan from the end, so that fail_insn is determined correctly.  */
   for (act = last; act != PREV_INSN (insn); act = PREV_INSN (act))
-    if (store_killed_in_insn (x, x_regs, act))
+    if (store_killed_in_insn (x, x_regs, act, false))
       {
        if (fail_insn)
          *fail_insn = act;
@@ -7520,15 +7456,13 @@ store_killed_after (x, x_regs, insn, bb, regs_set_after, fail_insn)
 
   return false;
 }
-  
+
 /* Returns true if the expression X is loaded or clobbered on or before INSN
    within basic block BB. X_REGS is list of registers mentioned in X.
    REGS_SET_BEFORE is bitmap of registers set before or in this insn.  */
 static bool
-store_killed_before (x, x_regs, insn, bb, regs_set_before)
-     rtx x, x_regs, insn;
-     basic_block bb;
-     int *regs_set_before;
+store_killed_before (rtx x, rtx x_regs, rtx insn, basic_block bb,
+                    int *regs_set_before)
 {
   rtx first = bb->head;
 
@@ -7536,16 +7470,16 @@ store_killed_before (x, x_regs, insn, bb, regs_set_before)
     return true;
 
   for ( ; insn != PREV_INSN (first); insn = PREV_INSN (insn))
-    if (store_killed_in_insn (x, x_regs, insn))
+    if (store_killed_in_insn (x, x_regs, insn, true))
       return true;
 
   return false;
 }
-  
+
 /* Fill in available, anticipatable, transparent and kill vectors in
    STORE_DATA, based on lists of available and anticipatable stores.  */
 static void
-build_store_vectors ()
+build_store_vectors (void)
 {
   basic_block bb;
   int *regs_set_in_block;
@@ -7555,10 +7489,10 @@ build_store_vectors ()
 
   /* Build the gen_vector. This is any store in the table which is not killed
      by aliasing later in its block.  */
-  ae_gen = (sbitmap *) sbitmap_vector_alloc (last_basic_block, num_stores);
+  ae_gen = sbitmap_vector_alloc (last_basic_block, num_stores);
   sbitmap_vector_zero (ae_gen, last_basic_block);
 
-  st_antloc = (sbitmap *) sbitmap_vector_alloc (last_basic_block, num_stores);
+  st_antloc = sbitmap_vector_alloc (last_basic_block, num_stores);
   sbitmap_vector_zero (st_antloc, last_basic_block);
 
   for (ptr = first_ls_expr (); ptr != NULL; ptr = next_ls_expr (ptr))
@@ -7577,7 +7511,7 @@ build_store_vectors ()
              rtx r = gen_reg_rtx (GET_MODE (ptr->pattern));
              if (gcse_file)
                fprintf (gcse_file, "Removing redundant store:\n");
-             replace_store_insn (r, XEXP (st, 0), bb);
+             replace_store_insn (r, XEXP (st, 0), bb, ptr);
              continue;
            }
          SET_BIT (ae_gen[bb->index], ptr->index);
@@ -7591,10 +7525,10 @@ build_store_vectors ()
        }
     }
 
-  ae_kill = (sbitmap *) sbitmap_vector_alloc (last_basic_block, num_stores);
+  ae_kill = sbitmap_vector_alloc (last_basic_block, num_stores);
   sbitmap_vector_zero (ae_kill, last_basic_block);
 
-  transp = (sbitmap *) sbitmap_vector_alloc (last_basic_block, num_stores);
+  transp = sbitmap_vector_alloc (last_basic_block, num_stores);
   sbitmap_vector_zero (transp, last_basic_block);
   regs_set_in_block = xmalloc (sizeof (int) * max_gcse_regno);
 
@@ -7613,10 +7547,10 @@ build_store_vectors ()
              if (!TEST_BIT (st_antloc[bb->index], ptr->index)
                  || !TEST_BIT (ae_gen[bb->index], ptr->index))
                SET_BIT (ae_kill[bb->index], ptr->index);
-           }
-         else
-           SET_BIT (transp[bb->index], ptr->index);
-               }
+           }
+         else
+           SET_BIT (transp[bb->index], ptr->index);
+       }
     }
 
   free (regs_set_in_block);
@@ -7634,9 +7568,7 @@ build_store_vectors ()
    the BLOCK_HEAD if needed.  */
 
 static void
-insert_insn_start_bb (insn, bb)
-     rtx insn;
-     basic_block bb;
+insert_insn_start_bb (rtx insn, basic_block bb)
 {
   /* Insert at start of successor block.  */
   rtx prev = PREV_INSN (bb->head);
@@ -7669,9 +7601,7 @@ insert_insn_start_bb (insn, bb)
    if an edge insertion was performed.  */
 
 static int
-insert_store (expr, e)
-     struct ls_expr * expr;
-     edge e;
+insert_store (struct ls_expr * expr, edge e)
 {
   rtx reg, insn;
   basic_block bb;
@@ -7682,6 +7612,9 @@ insert_store (expr, e)
   if (expr->reaching_reg == NULL_RTX)
     return 0;
 
+  if (e->flags & EDGE_FAKE)
+    return 0;
+
   reg = expr->reaching_reg;
   insn = gen_move_insn (copy_rtx (expr->pattern), reg);
 
@@ -7690,13 +7623,14 @@ insert_store (expr, e)
      edges so we don't try to insert it on the other edges.  */
   bb = e->dest;
   for (tmp = e->dest->pred; tmp ; tmp = tmp->pred_next)
-    {
-      int index = EDGE_INDEX (edge_list, tmp->src, tmp->dest);
-      if (index == EDGE_INDEX_NO_EDGE)
-       abort ();
-      if (! TEST_BIT (pre_insert_map[index], expr->index))
-       break;
-    }
+    if (!(tmp->flags & EDGE_FAKE))
+      {
+       int index = EDGE_INDEX (edge_list, tmp->src, tmp->dest);
+       if (index == EDGE_INDEX_NO_EDGE)
+         abort ();
+       if (! TEST_BIT (pre_insert_map[index], expr->index))
+         break;
+      }
 
   /* If tmp is NULL, we found an insertion on every edge, blank the
      insertion vector for these edges, and insert at the start of the BB.  */
@@ -7732,15 +7666,87 @@ insert_store (expr, e)
   return 1;
 }
 
+/* Remove any REG_EQUAL or REG_EQUIV notes containing a reference to the
+   memory location in SMEXPR set in basic block BB.
+
+   This could be rather expensive.  */
+
+static void
+remove_reachable_equiv_notes (basic_block bb, struct ls_expr *smexpr)
+{
+  edge *stack = xmalloc (sizeof (edge) * n_basic_blocks), act;
+  sbitmap visited = sbitmap_alloc (last_basic_block);
+  int stack_top = 0;
+  rtx last, insn, note;
+  rtx mem = smexpr->pattern;
+
+  sbitmap_zero (visited);
+  act = bb->succ;
+
+  while (1)
+    {
+      if (!act)
+       {
+         if (!stack_top)
+           {
+             free (stack);
+             sbitmap_free (visited);
+             return;
+           }
+         act = stack[--stack_top];
+       }
+      bb = act->dest;
+      
+      if (bb == EXIT_BLOCK_PTR
+         || TEST_BIT (visited, bb->index)
+         || TEST_BIT (ae_kill[bb->index], smexpr->index))
+       {
+         act = act->succ_next;
+         continue;
+       }
+      SET_BIT (visited, bb->index);
+
+      if (TEST_BIT (st_antloc[bb->index], smexpr->index))
+       {
+         for (last = ANTIC_STORE_LIST (smexpr);
+              BLOCK_FOR_INSN (XEXP (last, 0)) != bb;
+              last = XEXP (last, 1))
+           continue;
+         last = XEXP (last, 0);
+       }
+      else
+       last = NEXT_INSN (bb->end);
+  
+      for (insn = bb->head; insn != last; insn = NEXT_INSN (insn))
+       if (INSN_P (insn))
+         {
+           note = find_reg_equal_equiv_note (insn);
+           if (!note || !expr_equiv_p (XEXP (note, 0), mem))
+             continue;
+
+           if (gcse_file)
+             fprintf (gcse_file, "STORE_MOTION  drop REG_EQUAL note at insn %d:\n",
+                      INSN_UID (insn));
+           remove_note (insn, note);
+         }
+      act = act->succ_next;
+      if (bb->succ)
+       {
+         if (act)
+           stack[stack_top++] = act;
+         act = bb->succ;
+       }
+    }
+}
+
 /* This routine will replace a store with a SET to a specified register.  */
 
 static void
-replace_store_insn (reg, del, bb)
-     rtx reg, del;
-     basic_block bb;
+replace_store_insn (rtx reg, rtx del, basic_block bb, struct ls_expr *smexpr)
 {
-  rtx insn;
+  rtx insn, mem, note, set, ptr;
 
+  mem = smexpr->pattern;
   insn = gen_move_insn (reg, SET_SRC (single_set (del)));
   insn = emit_insn_after (insn, del);
 
@@ -7754,7 +7760,35 @@ replace_store_insn (reg, del, bb)
       fprintf (gcse_file, "\n");
     }
 
+  for (ptr = ANTIC_STORE_LIST (smexpr); ptr; ptr = XEXP (ptr, 1))
+    if (XEXP (ptr, 0) == del)
+      {
+       XEXP (ptr, 0) = insn;
+       break;
+      }
   delete_insn (del);
+
+  /* Now we must handle REG_EQUAL notes whose contents is equal to the mem;
+     they are no longer accurate provided that they are reached by this
+     definition, so drop them.  */
+  for (; insn != NEXT_INSN (bb->end); insn = NEXT_INSN (insn))
+    if (INSN_P (insn))
+      {
+       set = single_set (insn);
+       if (!set)
+         continue;
+       if (expr_equiv_p (SET_DEST (set), mem))
+         return;
+       note = find_reg_equal_equiv_note (insn);
+       if (!note || !expr_equiv_p (XEXP (note, 0), mem))
+         continue;
+
+       if (gcse_file)
+         fprintf (gcse_file, "STORE_MOTION  drop REG_EQUAL note at insn %d:\n",
+                  INSN_UID (insn));
+       remove_note (insn, note);
+      }
+  remove_reachable_equiv_notes (bb, smexpr);
 }
 
 
@@ -7762,9 +7796,7 @@ replace_store_insn (reg, del, bb)
    the reaching_reg for later storing.  */
 
 static void
-delete_store (expr, bb)
-     struct ls_expr * expr;
-     basic_block bb;
+delete_store (struct ls_expr * expr, basic_block bb)
 {
   rtx reg, i, del;
 
@@ -7780,7 +7812,7 @@ delete_store (expr, bb)
        {
          /* We know there is only one since we deleted redundant
             ones during the available computation.  */
-         replace_store_insn (reg, del, bb);
+         replace_store_insn (reg, del, bb, expr);
          break;
        }
     }
@@ -7789,7 +7821,7 @@ delete_store (expr, bb)
 /* Free memory used by store motion.  */
 
 static void
-free_store_memory ()
+free_store_memory (void)
 {
   free_ldst_mems ();
 
@@ -7816,7 +7848,7 @@ free_store_memory ()
    other way by looking at the flowgraph in reverse.  */
 
 static void
-store_motion ()
+store_motion (void)
 {
   basic_block bb;
   int x;
@@ -7843,6 +7875,7 @@ store_motion ()
   /* Now compute kill & transp vectors.  */
   build_store_vectors ();
   add_noreturn_fake_exit_edges ();
+  connect_infinite_loops_to_exit ();
 
   edge_list = pre_edge_rev_lcm (gcse_file, num_stores, transp, ae_gen,
                                st_antloc, ae_kill, &pre_insert_map,
@@ -7873,8 +7906,7 @@ store_motion ()
 /* Entry point for jump bypassing optimization pass.  */
 
 int
-bypass_jumps (file)
-     FILE *file;
+bypass_jumps (FILE *file)
 {
   int changed;
 
@@ -7894,39 +7926,10 @@ bypass_jumps (file)
   if (file)
     dump_flow_info (file);
 
-  /* Return if there's nothing to do.  */
-  if (n_basic_blocks <= 1)
+  /* Return if there's nothing to do, or it is too expensive  */
+  if (n_basic_blocks <= 1 || is_too_expensive (_ ("jump bypassing disabled")))
     return 0;
 
-  /* Trying to perform global optimizations on flow graphs which have
-     a high connectivity will take a long time and is unlikely to be
-     particularly useful.
-
-     In normal circumstances a cfg should have about twice as many edges
-     as blocks.  But we do not want to punish small functions which have
-     a couple switch statements.  So we require a relatively large number
-     of basic blocks and the ratio of edges to blocks to be high.  */
-  if (n_basic_blocks > 1000 && n_edges / n_basic_blocks >= 20)
-    {
-      if (warn_disabled_optimization)
-        warning ("BYPASS disabled: %d > 1000 basic blocks and %d >= 20 edges/basic block",
-                 n_basic_blocks, n_edges / n_basic_blocks);
-      return 0;
-    }
-
-  /* If allocating memory for the cprop bitmap would take up too much
-     storage it's better just to disable the optimization.  */
-  if ((n_basic_blocks
-       * SBITMAP_SET_SIZE (max_gcse_regno)
-       * sizeof (SBITMAP_ELT_TYPE)) > MAX_GCSE_MEMORY)
-    {
-      if (warn_disabled_optimization)
-        warning ("GCSE disabled: %d basic blocks and %d registers",
-                 n_basic_blocks, max_gcse_regno);
-
-      return 0;
-    }
-
   gcc_obstack_init (&gcse_obstack);
   bytes_used = 0;
 
@@ -7967,4 +7970,44 @@ bypass_jumps (file)
   return changed;
 }
 
+/* Return true if the graph is too expensive to optimize. PASS is the
+   optimization about to be performed.  */
+
+static bool
+is_too_expensive (const char *pass)
+{
+  /* Trying to perform global optimizations on flow graphs which have
+     a high connectivity will take a long time and is unlikely to be
+     particularly useful.
+     
+     In normal circumstances a cfg should have about twice as many
+     edges as blocks.  But we do not want to punish small functions
+     which have a couple switch statements.  Rather than simply
+     threshold the number of blocks, uses something with a more
+     graceful degradation.  */
+  if (n_edges > 20000 + n_basic_blocks * 4)
+    {
+      if (warn_disabled_optimization)
+       warning ("%s: %d basic blocks and %d edges/basic block",
+                pass, n_basic_blocks, n_edges / n_basic_blocks);
+      
+      return true;
+    }
+
+  /* If allocating memory for the cprop bitmap would take up too much
+     storage it's better just to disable the optimization.  */
+  if ((n_basic_blocks
+       * SBITMAP_SET_SIZE (max_reg_num ())
+       * sizeof (SBITMAP_ELT_TYPE)) > MAX_GCSE_MEMORY)
+    {
+      if (warn_disabled_optimization)
+       warning ("%s: %d basic blocks and %d registers",
+                pass, n_basic_blocks, max_reg_num ());
+
+      return true;
+    }
+
+  return false;
+}
+
 #include "gt-gcse.h"