OSDN Git Service

* typeck.c (comptypes): First determine if the types are compatible
[pf3gnuchains/gcc-fork.git] / gcc / gcse.c
index b9a7874..467a50a 100644 (file)
@@ -1,6 +1,6 @@
 /* Global common subexpression elimination/Partial redundancy elimination
    and global constant/copy propagation for GNU compiler.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -264,19 +264,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    the result of the expression is copied to a new register, and the redundant
    expression is deleted by replacing it with this new register.  Classic GCSE
    doesn't have this problem as much as it computes the reaching defs of
-   each register in each block and thus can try to use an existing register.
-
-   **********************
-
-   A fair bit of simplicity is created by creating small functions for simple
-   tasks, even when the function is only called in one place.  This may
-   measurably slow things down [or may not] by creating more function call
-   overhead than is necessary.  The source is laid out so that it's trivial
-   to make the affected functions inline so that one can measure what speed
-   up, if any, can be achieved, and maybe later when things settle things can
-   be rearranged.
-
-   Help stamp out big monolithic functions!  */
+   each register in each block and thus can try to use an existing
+   register.  */
 \f
 /* GCSE global vars.  */
 
@@ -389,7 +378,8 @@ static int max_uid;
 
 /* Get the cuid of an insn.  */
 #ifdef ENABLE_CHECKING
-#define INSN_CUID(INSN) (INSN_UID (INSN) > max_uid ? (abort (), 0) : uid_cuid[INSN_UID (INSN)])
+#define INSN_CUID(INSN) \
+  (gcc_assert (INSN_UID (INSN) <= max_uid), uid_cuid[INSN_UID (INSN)])
 #else
 #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
 #endif
@@ -435,8 +425,8 @@ typedef struct reg_set
 {
   /* The next setting of this register.  */
   struct reg_set *next;
-  /* The insn where it was set.  */
-  rtx insn;
+  /* The index of the block where it was set.  */
+  int bb_index;
 } reg_set;
 
 static reg_set **reg_set_table;
@@ -452,7 +442,7 @@ static int reg_set_table_size;
 /* This is a list of expressions which are MEMs and will be used by load
    or store motion.
    Load motion tracks MEMs which aren't killed by
-   anything except itself. (ie, loads and stores to a single location).
+   anything except itself. (i.e., loads and stores to a single location).
    We can then allow movement of these MEM refs with a little special
    allowance. (all stores copy the same value to the reaching reg used
    for the loads).  This means all values used to store into memory must have
@@ -495,11 +485,15 @@ static sbitmap *reg_set_in_block;
 /* Array, indexed by basic block number for a list of insns which modify
    memory within that block.  */
 static rtx * modify_mem_list;
-bitmap modify_mem_list_set;
+static bitmap modify_mem_list_set;
 
 /* This array parallels modify_mem_list, but is kept canonicalized.  */
 static rtx * canon_modify_mem_list;
-bitmap canon_modify_mem_list_set;
+
+/* Bitmap indexed by block numbers to record which blocks contain
+   function calls.  */
+static bitmap blocks_with_calls;
+
 /* Various variables for statistics gathering.  */
 
 /* Memory used in a pass.
@@ -522,20 +516,6 @@ static int global_copy_prop_count;
 \f
 /* For available exprs */
 static sbitmap *ae_kill, *ae_gen;
-
-/* Objects of this type are passed around by the null-pointer check
-   removal routines.  */
-struct null_pointer_info
-{
-  /* The basic block being processed.  */
-  basic_block current_block;
-  /* The first register to be handled in this pass.  */
-  unsigned int min_reg;
-  /* One greater than the last register to be handled in this pass.  */
-  unsigned int max_reg;
-  sbitmap *nonnull_local;
-  sbitmap *nonnull_killed;
-};
 \f
 static void compute_can_copy (void);
 static void *gmalloc (size_t) ATTRIBUTE_MALLOC;
@@ -547,7 +527,6 @@ static void free_gcse_mem (void);
 static void alloc_reg_set_mem (int);
 static void free_reg_set_mem (void);
 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);
@@ -564,8 +543,6 @@ 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);
@@ -576,7 +553,6 @@ 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);
@@ -676,7 +652,8 @@ static bool is_too_expensive (const char *);
 \f
 
 /* Entry point for global common subexpression elimination.
-   F is the first instruction in the function.  */
+   F is the first instruction in the function.  Return nonzero if a
+   change is mode.  */
 
 int
 gcse_main (rtx f, FILE *file)
@@ -974,7 +951,7 @@ alloc_gcse_mem (rtx f)
       CUID_INSN (i++) = insn;
 
   /* Allocate vars to track sets of regs.  */
-  reg_set_bitmap = BITMAP_XMALLOC ();
+  reg_set_bitmap = BITMAP_ALLOC (NULL);
 
   /* Allocate vars to track sets of regs, memory per block.  */
   reg_set_in_block = sbitmap_vector_alloc (last_basic_block, max_gcse_regno);
@@ -982,8 +959,8 @@ alloc_gcse_mem (rtx f)
      basic block.  */
   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 ();
+  modify_mem_list_set = BITMAP_ALLOC (NULL);
+  blocks_with_calls = BITMAP_ALLOC (NULL);
 }
 
 /* Free memory allocated by alloc_gcse_mem.  */
@@ -994,12 +971,12 @@ free_gcse_mem (void)
   free (uid_cuid);
   free (cuid_insn);
 
-  BITMAP_XFREE (reg_set_bitmap);
+  BITMAP_FREE (reg_set_bitmap);
 
   sbitmap_vector_free (reg_set_in_block);
   free_modify_mem_tables ();
-  BITMAP_XFREE (modify_mem_list_set);
-  BITMAP_XFREE (canon_modify_mem_list_set);
+  BITMAP_FREE (modify_mem_list_set);
+  BITMAP_FREE (blocks_with_calls);
 }
 \f
 /* Compute the local properties of each recorded expression.
@@ -1118,24 +1095,6 @@ free_reg_set_mem (void)
   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
@@ -1158,7 +1117,7 @@ record_one_set (int regno, rtx insn)
 
   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->bb_index = BLOCK_NUM (insn);
   new_reg_info->next = reg_set_table[regno];
   reg_set_table[regno] = new_reg_info;
 }
@@ -1366,7 +1325,6 @@ mems_conflict_for_gcse_p (rtx dest, rtx setter ATTRIBUTE_UNUSED,
 {
   while (GET_CODE (dest) == SUBREG
         || GET_CODE (dest) == ZERO_EXTRACT
-        || GET_CODE (dest) == SIGN_EXTRACT
         || GET_CODE (dest) == STRICT_LOW_PART)
     dest = XEXP (dest, 0);
 
@@ -1462,9 +1420,7 @@ oprs_available_p (rtx x, rtx insn)
    MODE is only used if X is a CONST_INT.  DO_NOT_RECORD_P is a boolean
    indicating if a volatile operand is found or if the expression contains
    something we don't want to insert in the table.  HASH_TABLE_SIZE is
-   the current size of the hash table to be probed.
-
-   ??? One might want to merge this with canon_hash.  Later.  */
+   the current size of the hash table to be probed.  */
 
 static unsigned int
 hash_expr (rtx x, enum machine_mode mode, int *do_not_record_p,
@@ -1474,208 +1430,11 @@ hash_expr (rtx x, enum machine_mode mode, int *do_not_record_p,
 
   *do_not_record_p = 0;
 
-  hash = hash_expr_1 (x, mode, do_not_record_p);
+  hash = hash_rtx (x, mode, do_not_record_p,
+                  NULL,  /*have_reg_qty=*/false);
   return hash % hash_table_size;
 }
 
-/* Hash a string.  Just add its bytes up.  */
-
-static inline unsigned
-hash_string_1 (const char *ps)
-{
-  unsigned hash = 0;
-  const unsigned char *p = (const unsigned char *) ps;
-
-  if (p)
-    while (*p)
-      hash += *p++;
-
-  return hash;
-}
-
-/* Subroutine of hash_expr to do the actual work.  */
-
-static unsigned int
-hash_expr_1 (rtx x, enum machine_mode mode, int *do_not_record_p)
-{
-  int i, j;
-  unsigned hash = 0;
-  enum rtx_code code;
-  const char *fmt;
-
-  if (x == 0)
-    return hash;
-
-  /* Used to turn recursion into iteration.  We can't rely on GCC's
-     tail-recursion elimination since we need to keep accumulating values
-     in HASH.  */
- repeat:
-
-  code = GET_CODE (x);
-  switch (code)
-    {
-    case REG:
-      hash += ((unsigned int) REG << 7) + REGNO (x);
-      return hash;
-
-    case CONST_INT:
-      hash += (((unsigned int) CONST_INT << 7) + (unsigned int) mode
-              + (unsigned int) INTVAL (x));
-      return hash;
-
-    case CONST_DOUBLE:
-      /* This is like the general case, except that it only counts
-        the integers representing the constant.  */
-      hash += (unsigned int) code + (unsigned int) GET_MODE (x);
-      if (GET_MODE (x) != VOIDmode)
-       for (i = 2; i < GET_RTX_LENGTH (CONST_DOUBLE); i++)
-         hash += (unsigned int) XWINT (x, i);
-      else
-       hash += ((unsigned int) CONST_DOUBLE_LOW (x)
-                + (unsigned int) CONST_DOUBLE_HIGH (x));
-      return hash;
-
-    case CONST_VECTOR:
-      {
-       int units;
-       rtx elt;
-
-       units = CONST_VECTOR_NUNITS (x);
-
-       for (i = 0; i < units; ++i)
-         {
-           elt = CONST_VECTOR_ELT (x, i);
-           hash += hash_expr_1 (elt, GET_MODE (elt), do_not_record_p);
-         }
-
-       return hash;
-      }
-
-      /* Assume there is only one rtx object for any given label.  */
-    case LABEL_REF:
-      /* We don't hash on the address of the CODE_LABEL to avoid bootstrap
-        differences and differences between each stage's debugging dumps.  */
-      hash += (((unsigned int) LABEL_REF << 7)
-              + CODE_LABEL_NUMBER (XEXP (x, 0)));
-      return hash;
-
-    case SYMBOL_REF:
-      {
-       /* Don't hash on the symbol's address to avoid bootstrap differences.
-          Different hash values may cause expressions to be recorded in
-          different orders and thus different registers to be used in the
-          final assembler.  This also avoids differences in the dump files
-          between various stages.  */
-       unsigned int h = 0;
-       const unsigned char *p = (const unsigned char *) XSTR (x, 0);
-
-       while (*p)
-         h += (h << 7) + *p++; /* ??? revisit */
-
-       hash += ((unsigned int) SYMBOL_REF << 7) + h;
-       return hash;
-      }
-
-    case MEM:
-      if (MEM_VOLATILE_P (x))
-       {
-         *do_not_record_p = 1;
-         return 0;
-       }
-
-      hash += (unsigned int) MEM;
-      /* We used alias set for hashing, but this is not good, since the alias
-        set may differ in -fprofile-arcs and -fbranch-probabilities compilation
-        causing the profiles to fail to match.  */
-      x = XEXP (x, 0);
-      goto repeat;
-
-    case PRE_DEC:
-    case PRE_INC:
-    case POST_DEC:
-    case POST_INC:
-    case PC:
-    case CC0:
-    case CALL:
-    case UNSPEC_VOLATILE:
-      *do_not_record_p = 1;
-      return 0;
-
-    case ASM_OPERANDS:
-      if (MEM_VOLATILE_P (x))
-       {
-         *do_not_record_p = 1;
-         return 0;
-       }
-      else
-       {
-         /* We don't want to take the filename and line into account.  */
-         hash += (unsigned) code + (unsigned) GET_MODE (x)
-           + hash_string_1 (ASM_OPERANDS_TEMPLATE (x))
-           + hash_string_1 (ASM_OPERANDS_OUTPUT_CONSTRAINT (x))
-           + (unsigned) ASM_OPERANDS_OUTPUT_IDX (x);
-
-         if (ASM_OPERANDS_INPUT_LENGTH (x))
-           {
-             for (i = 1; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
-               {
-                 hash += (hash_expr_1 (ASM_OPERANDS_INPUT (x, i),
-                                       GET_MODE (ASM_OPERANDS_INPUT (x, i)),
-                                       do_not_record_p)
-                          + hash_string_1 (ASM_OPERANDS_INPUT_CONSTRAINT
-                                           (x, i)));
-               }
-
-             hash += hash_string_1 (ASM_OPERANDS_INPUT_CONSTRAINT (x, 0));
-             x = ASM_OPERANDS_INPUT (x, 0);
-             mode = GET_MODE (x);
-             goto repeat;
-           }
-         return hash;
-       }
-
-    default:
-      break;
-    }
-
-  hash += (unsigned) code + (unsigned) GET_MODE (x);
-  for (i = GET_RTX_LENGTH (code) - 1, fmt = GET_RTX_FORMAT (code); i >= 0; i--)
-    {
-      if (fmt[i] == 'e')
-       {
-         /* If we are about to do the last recursive call
-            needed at this level, change it into iteration.
-            This function is called enough to be worth it.  */
-         if (i == 0)
-           {
-             x = XEXP (x, i);
-             goto repeat;
-           }
-
-         hash += hash_expr_1 (XEXP (x, i), 0, do_not_record_p);
-         if (*do_not_record_p)
-           return 0;
-       }
-
-      else if (fmt[i] == 'E')
-       for (j = 0; j < XVECLEN (x, i); j++)
-         {
-           hash += hash_expr_1 (XVECEXP (x, i, j), 0, do_not_record_p);
-           if (*do_not_record_p)
-             return 0;
-         }
-
-      else if (fmt[i] == 's')
-       hash += hash_string_1 (XSTR (x, i));
-      else if (fmt[i] == 'i')
-       hash += (unsigned int) XINT (x, i);
-      else
-       abort ();
-    }
-
-  return hash;
-}
-
 /* Hash a set of register REGNO.
 
    Sets are hashed on the register that is set.  This simplifies the PRE copy
@@ -1692,148 +1451,12 @@ hash_set (int regno, int hash_table_size)
   return hash % hash_table_size;
 }
 
-/* Return nonzero if exp1 is equivalent to exp2.
-   ??? Borrowed from cse.c.  Might want to remerge with cse.c.  Later.  */
+/* Return nonzero if exp1 is equivalent to exp2.  */
 
 static int
 expr_equiv_p (rtx x, rtx y)
 {
-  int i, j;
-  enum rtx_code code;
-  const char *fmt;
-
-  if (x == y)
-    return 1;
-
-  if (x == 0 || y == 0)
-    return 0;
-
-  code = GET_CODE (x);
-  if (code != GET_CODE (y))
-    return 0;
-
-  /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
-  if (GET_MODE (x) != GET_MODE (y))
-    return 0;
-
-  switch (code)
-    {
-    case PC:
-    case CC0:
-    case CONST_INT:
-      return 0;
-
-    case LABEL_REF:
-      return XEXP (x, 0) == XEXP (y, 0);
-
-    case SYMBOL_REF:
-      return XSTR (x, 0) == XSTR (y, 0);
-
-    case REG:
-      return REGNO (x) == REGNO (y);
-
-    case MEM:
-      /* Can't merge two expressions in different alias sets, since we can
-        decide that the expression is transparent in a block when it isn't,
-        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.  */
-    case PLUS:
-    case MULT:
-    case AND:
-    case IOR:
-    case XOR:
-    case NE:
-    case EQ:
-      return ((expr_equiv_p (XEXP (x, 0), XEXP (y, 0))
-              && expr_equiv_p (XEXP (x, 1), XEXP (y, 1)))
-             || (expr_equiv_p (XEXP (x, 0), XEXP (y, 1))
-                 && expr_equiv_p (XEXP (x, 1), XEXP (y, 0))));
-
-    case ASM_OPERANDS:
-      /* We don't use the generic code below because we want to
-        disregard filename and line numbers.  */
-
-      /* A volatile asm isn't equivalent to any other.  */
-      if (MEM_VOLATILE_P (x) || MEM_VOLATILE_P (y))
-       return 0;
-
-      if (GET_MODE (x) != GET_MODE (y)
-         || strcmp (ASM_OPERANDS_TEMPLATE (x), ASM_OPERANDS_TEMPLATE (y))
-         || strcmp (ASM_OPERANDS_OUTPUT_CONSTRAINT (x),
-                    ASM_OPERANDS_OUTPUT_CONSTRAINT (y))
-         || ASM_OPERANDS_OUTPUT_IDX (x) != ASM_OPERANDS_OUTPUT_IDX (y)
-         || ASM_OPERANDS_INPUT_LENGTH (x) != ASM_OPERANDS_INPUT_LENGTH (y))
-       return 0;
-
-      if (ASM_OPERANDS_INPUT_LENGTH (x))
-       {
-         for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
-           if (! expr_equiv_p (ASM_OPERANDS_INPUT (x, i),
-                               ASM_OPERANDS_INPUT (y, i))
-               || strcmp (ASM_OPERANDS_INPUT_CONSTRAINT (x, i),
-                          ASM_OPERANDS_INPUT_CONSTRAINT (y, i)))
-             return 0;
-       }
-
-      return 1;
-
-    default:
-      break;
-    }
-
-  /* Compare the elements.  If any pair of corresponding elements
-     fail to match, return 0 for the whole thing.  */
-
-  fmt = GET_RTX_FORMAT (code);
-  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
-    {
-      switch (fmt[i])
-       {
-       case 'e':
-         if (! expr_equiv_p (XEXP (x, i), XEXP (y, i)))
-           return 0;
-         break;
-
-       case 'E':
-         if (XVECLEN (x, i) != XVECLEN (y, i))
-           return 0;
-         for (j = 0; j < XVECLEN (x, i); j++)
-           if (! expr_equiv_p (XVECEXP (x, i, j), XVECEXP (y, i, j)))
-             return 0;
-         break;
-
-       case 's':
-         if (strcmp (XSTR (x, i), XSTR (y, i)))
-           return 0;
-         break;
-
-       case 'i':
-         if (XINT (x, i) != XINT (y, i))
-           return 0;
-         break;
-
-       case 'w':
-         if (XWINT (x, i) != XWINT (y, i))
-           return 0;
-       break;
-
-       case '0':
-         break;
-
-       default:
-         abort ();
-       }
-    }
-
-  return 1;
+  return exp_equiv_p (x, y, 0, true);
 }
 
 /* Insert expression X in INSN in the hash TABLE.
@@ -1854,7 +1477,6 @@ insert_expr_in_table (rtx x, enum machine_mode mode, rtx insn, int antic_p,
   unsigned int hash;
   struct expr *cur_expr, *last_expr = NULL;
   struct occr *antic_occr, *avail_occr;
-  struct occr *last_occr = NULL;
 
   hash = hash_expr (x, mode, &do_not_record_p, table->size);
 
@@ -1899,14 +1521,8 @@ insert_expr_in_table (rtx x, enum machine_mode mode, rtx insn, int antic_p,
     {
       antic_occr = cur_expr->antic_occr;
 
-      /* Search for another occurrence in the same basic block.  */
-      while (antic_occr && BLOCK_NUM (antic_occr->insn) != BLOCK_NUM (insn))
-       {
-         /* If an occurrence isn't found, save a pointer to the end of
-            the list.  */
-         last_occr = antic_occr;
-         antic_occr = antic_occr->next;
-       }
+      if (antic_occr && BLOCK_NUM (antic_occr->insn) != BLOCK_NUM (insn))
+       antic_occr = NULL;
 
       if (antic_occr)
        /* Found another instance of the expression in the same basic block.
@@ -1918,15 +1534,10 @@ insert_expr_in_table (rtx x, enum machine_mode mode, rtx insn, int antic_p,
          /* First occurrence of this expression in this basic block.  */
          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)
-           cur_expr->antic_occr = antic_occr;
-         else
-           last_occr->next = antic_occr;
-
          antic_occr->insn = insn;
-         antic_occr->next = NULL;
+         antic_occr->next = cur_expr->antic_occr;
          antic_occr->deleted_p = 0;
+         cur_expr->antic_occr = antic_occr;
        }
     }
 
@@ -1934,36 +1545,23 @@ insert_expr_in_table (rtx x, enum machine_mode mode, rtx insn, int antic_p,
     {
       avail_occr = cur_expr->avail_occr;
 
-      /* Search for another occurrence in the same basic block.  */
-      while (avail_occr && BLOCK_NUM (avail_occr->insn) != BLOCK_NUM (insn))
+      if (avail_occr && BLOCK_NUM (avail_occr->insn) == BLOCK_NUM (insn))
        {
-         /* If an occurrence isn't found, save a pointer to the end of
-            the list.  */
-         last_occr = avail_occr;
-         avail_occr = avail_occr->next;
+         /* Found another instance of the expression in the same basic block.
+            Prefer this occurrence to the currently recorded one.  We want
+            the last one in the block and the block is scanned from start
+            to end.  */
+         avail_occr->insn = insn;
        }
-
-      if (avail_occr)
-       /* Found another instance of the expression in the same basic block.
-          Prefer this occurrence to the currently recorded one.  We want
-          the last one in the block and the block is scanned from start
-          to end.  */
-       avail_occr->insn = insn;
       else
        {
          /* First occurrence of this expression in this basic block.  */
          avail_occr = gcse_alloc (sizeof (struct occr));
          bytes_used += sizeof (struct occr);
-
-         /* First occurrence of this expression in any block?  */
-         if (cur_expr->avail_occr == NULL)
-           cur_expr->avail_occr = avail_occr;
-         else
-           last_occr->next = avail_occr;
-
          avail_occr->insn = insn;
-         avail_occr->next = NULL;
+         avail_occr->next = cur_expr->avail_occr;
          avail_occr->deleted_p = 0;
+         cur_expr->avail_occr = avail_occr;
        }
     }
 }
@@ -1979,11 +1577,9 @@ insert_set_in_table (rtx x, rtx insn, struct hash_table *table)
   int found;
   unsigned int hash;
   struct expr *cur_expr, *last_expr = NULL;
-  struct occr *cur_occr, *last_occr = NULL;
+  struct occr *cur_occr;
 
-  if (GET_CODE (x) != SET
-      || ! REG_P (SET_DEST (x)))
-    abort ();
+  gcc_assert (GET_CODE (x) == SET && REG_P (SET_DEST (x)));
 
   hash = hash_set (REGNO (SET_DEST (x)), table->size);
 
@@ -2022,35 +1618,24 @@ insert_set_in_table (rtx x, rtx insn, struct hash_table *table)
   /* Now record the occurrence.  */
   cur_occr = cur_expr->avail_occr;
 
-  /* Search for another occurrence in the same basic block.  */
-  while (cur_occr && BLOCK_NUM (cur_occr->insn) != BLOCK_NUM (insn))
+  if (cur_occr && BLOCK_NUM (cur_occr->insn) == BLOCK_NUM (insn))
     {
-      /* If an occurrence isn't found, save a pointer to the end of
-        the list.  */
-      last_occr = cur_occr;
-      cur_occr = cur_occr->next;
+      /* Found another instance of the expression in the same basic block.
+        Prefer this occurrence to the currently recorded one.  We want
+        the last one in the block and the block is scanned from start
+        to end.  */
+      cur_occr->insn = insn;
     }
-
-  if (cur_occr)
-    /* Found another instance of the expression in the same basic block.
-       Prefer this occurrence to the currently recorded one.  We want the
-       last one in the block and the block is scanned from start to end.  */
-    cur_occr->insn = insn;
   else
     {
       /* First occurrence of this expression in this basic block.  */
       cur_occr = gcse_alloc (sizeof (struct occr));
       bytes_used += sizeof (struct occr);
 
-      /* First occurrence of this expression in any block?  */
-      if (cur_expr->avail_occr == NULL)
-       cur_expr->avail_occr = cur_occr;
-      else
-       last_occr->next = cur_occr;
-
-      cur_occr->insn = insn;
-      cur_occr->next = NULL;
-      cur_occr->deleted_p = 0;
+         cur_occr->insn = insn;
+         cur_occr->next = cur_expr->avail_occr;
+         cur_occr->deleted_p = 0;
+         cur_expr->avail_occr = cur_occr;
     }
 }
 
@@ -2339,7 +1924,6 @@ canon_list_insert (rtx dest ATTRIBUTE_UNUSED, rtx unused1 ATTRIBUTE_UNUSED,
 
   while (GET_CODE (dest) == SUBREG
       || GET_CODE (dest) == ZERO_EXTRACT
-      || GET_CODE (dest) == SIGN_EXTRACT
       || GET_CODE (dest) == STRICT_LOW_PART)
     dest = XEXP (dest, 0);
 
@@ -2359,7 +1943,6 @@ canon_list_insert (rtx dest ATTRIBUTE_UNUSED, rtx unused1 ATTRIBUTE_UNUSED,
     alloc_EXPR_LIST (VOIDmode, dest_addr, canon_modify_mem_list[bb]);
   canon_modify_mem_list[bb] =
     alloc_EXPR_LIST (VOIDmode, dest, canon_modify_mem_list[bb]);
-  bitmap_set_bit (canon_modify_mem_list_set, bb);
 }
 
 /* Record memory modification information for INSN.  We do not actually care
@@ -2383,7 +1966,7 @@ record_last_mem_set_info (rtx insn)
         need to insert a pair of items, as canon_list_insert does.  */
       canon_modify_mem_list[bb] =
        alloc_INSN_LIST (insn, canon_modify_mem_list[bb]);
-      bitmap_set_bit (canon_modify_mem_list_set, bb);
+      bitmap_set_bit (blocks_with_calls, bb);
     }
   else
     note_stores (PATTERN (insn), canon_list_insert, (void*) insn);
@@ -2464,16 +2047,8 @@ compute_hash_table_work (struct hash_table *table)
 
          if (CALL_P (insn))
            {
-             bool clobbers_all = false;
-#ifdef NON_SAVING_SETJMP
-             if (NON_SAVING_SETJMP
-                 && find_reg_note (insn, REG_SETJMP, NULL_RTX))
-               clobbers_all = true;
-#endif
-
              for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-               if (clobbers_all
-                   || TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
+               if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
                  record_last_reg_set_info (insn, regno);
 
              mark_call (insn);
@@ -2556,28 +2131,6 @@ compute_hash_table (struct hash_table *table)
 \f
 /* Expression tracking support.  */
 
-/* Lookup pattern PAT in the expression TABLE.
-   The result is a pointer to the table entry, or NULL if not found.  */
-
-static struct expr *
-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,
-                                table->size);
-  struct expr *expr;
-
-  if (do_not_record_p)
-    return NULL;
-
-  expr = table->table[hash];
-
-  while (expr && ! expr_equiv_p (expr->expr, pat))
-    expr = expr->next_same_hash;
-
-  return expr;
-}
-
 /* Lookup REGNO in the set TABLE.  The result is a pointer to the
    table entry, or NULL if not found.  */
 
@@ -2631,19 +2184,19 @@ free_insn_expr_list_list (rtx *listp)
 static void
 clear_modify_mem_tables (void)
 {
-  int i;
+  unsigned i;
+  bitmap_iterator bi;
 
-  EXECUTE_IF_SET_IN_BITMAP
-    (modify_mem_list_set, 0, i, free_INSN_LIST_list (modify_mem_list + i));
+  EXECUTE_IF_SET_IN_BITMAP (modify_mem_list_set, 0, i, bi)
+    {
+      free_INSN_LIST_list (modify_mem_list + i);
+      free_insn_expr_list_list (canon_modify_mem_list + i);
+    }
   bitmap_clear (modify_mem_list_set);
-
-  EXECUTE_IF_SET_IN_BITMAP
-    (canon_modify_mem_list_set, 0, i,
-     free_insn_expr_list_list (canon_modify_mem_list + i));
-  bitmap_clear (canon_modify_mem_list_set);
+  bitmap_clear (blocks_with_calls);
 }
 
-/* Release memory used by modify_mem_list_set and canon_modify_mem_list_set.  */
+/* Release memory used by modify_mem_list_set.  */
 
 static void
 free_modify_mem_tables (void)
@@ -2753,7 +2306,6 @@ mark_set (rtx pat, rtx insn)
 
   while (GET_CODE (dest) == SUBREG
         || GET_CODE (dest) == ZERO_EXTRACT
-        || GET_CODE (dest) == SIGN_EXTRACT
         || GET_CODE (dest) == STRICT_LOW_PART)
     dest = XEXP (dest, 0);
 
@@ -2884,7 +2436,7 @@ compute_transp (rtx x, int indx, sbitmap *bmap, int set_p)
          else
            {
              for (r = reg_set_table[REGNO (x)]; r != NULL; r = r->next)
-               SET_BIT (bmap[BLOCK_NUM (r->insn)], indx);
+               SET_BIT (bmap[r->bb_index], indx);
            }
        }
       else
@@ -2898,48 +2450,58 @@ compute_transp (rtx x, int indx, sbitmap *bmap, int set_p)
          else
            {
              for (r = reg_set_table[REGNO (x)]; r != NULL; r = r->next)
-               RESET_BIT (bmap[BLOCK_NUM (r->insn)], indx);
+               RESET_BIT (bmap[r->bb_index], indx);
            }
        }
 
       return;
 
     case MEM:
-      FOR_EACH_BB (bb)
-       {
-         rtx list_entry = canon_modify_mem_list[bb->index];
+      {
+       bitmap_iterator bi;
+       unsigned bb_index;
 
-         while (list_entry)
-           {
-             rtx dest, dest_addr;
+       /* First handle all the blocks with calls.  We don't need to
+          do any list walking for them.  */
+       EXECUTE_IF_SET_IN_BITMAP (blocks_with_calls, 0, bb_index, bi)
+         {
+           if (set_p)
+             SET_BIT (bmap[bb_index], indx);
+           else
+             RESET_BIT (bmap[bb_index], indx);
+         }
 
-             if (CALL_P (XEXP (list_entry, 0)))
-               {
-                 if (set_p)
-                   SET_BIT (bmap[bb->index], indx);
-                 else
-                   RESET_BIT (bmap[bb->index], indx);
-                 break;
-               }
-             /* LIST_ENTRY must be an INSN of some kind that sets memory.
-                Examine each hunk of memory that is modified.  */
+       /* Now iterate over the blocks which have memory modifications
+          but which do not have any calls.  */
+       EXECUTE_IF_AND_COMPL_IN_BITMAP (modify_mem_list_set, blocks_with_calls,
+                                       0, bb_index, bi)
+         {
+           rtx list_entry = canon_modify_mem_list[bb_index];
 
-             dest = XEXP (list_entry, 0);
-             list_entry = XEXP (list_entry, 1);
-             dest_addr = XEXP (list_entry, 0);
+           while (list_entry)
+             {
+               rtx dest, dest_addr;
 
-             if (canon_true_dependence (dest, GET_MODE (dest), dest_addr,
-                                        x, rtx_addr_varies_p))
-               {
-                 if (set_p)
-                   SET_BIT (bmap[bb->index], indx);
-                 else
-                   RESET_BIT (bmap[bb->index], indx);
-                 break;
-               }
-             list_entry = XEXP (list_entry, 1);
-           }
-       }
+               /* LIST_ENTRY must be an INSN of some kind that sets memory.
+                  Examine each hunk of memory that is modified.  */
+
+               dest = XEXP (list_entry, 0);
+               list_entry = XEXP (list_entry, 1);
+               dest_addr = XEXP (list_entry, 0);
+
+               if (canon_true_dependence (dest, GET_MODE (dest), dest_addr,
+                                          x, rtx_addr_varies_p))
+                 {
+                   if (set_p)
+                     SET_BIT (bmap[bb_index], indx);
+                   else
+                     RESET_BIT (bmap[bb_index], indx);
+                   break;
+                 }
+               list_entry = XEXP (list_entry, 1);
+             }
+         }
+      }
 
       x = XEXP (x, 0);
       goto repeat;
@@ -3102,8 +2664,7 @@ try_replace_reg (rtx from, rtx to, rtx insn)
         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)
+         && GET_CODE (SET_DEST (set)) != ZERO_EXTRACT)
        note = set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src));
     }
 
@@ -3128,7 +2689,7 @@ find_avail_set (int regno, rtx insn)
   struct expr *set1 = 0;
 
   /* Loops are not possible here.  To get a loop we would need two sets
-     available at the start of the block containing INSN.  ie we would
+     available at the start of the block containing INSN.  i.e. we would
      need two sets like this available at the start of the block:
 
        (set (reg X) (reg Y))
@@ -3155,8 +2716,7 @@ find_avail_set (int regno, rtx insn)
       if (set == 0)
        break;
 
-      if (GET_CODE (set->expr) != SET)
-       abort ();
+      gcc_assert (GET_CODE (set->expr) == SET);
 
       src = SET_SRC (set->expr);
 
@@ -3175,7 +2735,7 @@ find_avail_set (int regno, rtx insn)
       if (! REG_P (src))
        break;
 
-      /* Follow the copy chain, ie start another iteration of the loop
+      /* Follow the copy chain, i.e. start another iteration of the loop
         and see if we have an available copy into SRC.  */
       regno = REGNO (src);
     }
@@ -3372,8 +2932,7 @@ cprop_insn (rtx insn, int alter_jumps)
 
       pat = set->expr;
       /* ??? We might be able to handle PARALLELs.  Later.  */
-      if (GET_CODE (pat) != SET)
-       abort ();
+      gcc_assert (GET_CODE (pat) == SET);
 
       src = SET_SRC (pat);
 
@@ -3492,7 +3051,8 @@ do_local_cprop (rtx x, rtx insn, int alter_jumps, rtx *libcall_sp)
          rtx this_rtx = l->loc;
          rtx note;
 
-         if (l->in_libcall)
+         /* Don't CSE non-constant values out of libcall blocks.  */
+         if (l->in_libcall && ! CONSTANT_P (this_rtx))
            continue;
 
          if (gcse_constant_p (this_rtx))
@@ -3514,8 +3074,11 @@ do_local_cprop (rtx x, rtx insn, int alter_jumps, rtx *libcall_sp)
             or fix delete_trivially_dead_insns to preserve the setting insn,
             or make it delete the REG_EUAQL note, and fix up all passes that
             require the REG_EQUAL note there.  */
-         if (!adjust_libcall_notes (x, newcnst, insn, libcall_sp))
-           abort ();
+         bool adjusted;
+
+         adjusted = adjust_libcall_notes (x, newcnst, insn, libcall_sp);
+         gcc_assert (adjusted);
+         
          if (gcse_file != NULL)
            {
              fprintf (gcse_file, "LOCAL CONST-PROP: Replacing reg %d in ",
@@ -3577,7 +3140,7 @@ adjust_libcall_notes (rtx oldreg, rtx newval, rtx insn, rtx *libcall_sp)
              return true;
            }
        }
-      XEXP (note, 0) = replace_rtx (XEXP (note, 0), oldreg, newval);
+      XEXP (note, 0) = simplify_replace_rtx (XEXP (note, 0), oldreg, newval);
       insn = end;
     }
   return true;
@@ -3604,8 +3167,7 @@ local_cprop_pass (int alter_jumps)
 
          if (note)
            {
-             if (libcall_sp == libcall_stack)
-               abort ();
+             gcc_assert (libcall_sp != libcall_stack);
              *--libcall_sp = XEXP (note, 0);
            }
          note = find_reg_note (insn, REG_RETVAL, NULL_RTX);
@@ -3756,7 +3318,7 @@ find_implicit_sets (void)
   count = 0;
   FOR_EACH_BB (bb)
     /* Check for more than one successor.  */
-    if (bb->succ && bb->succ->succ_next)
+    if (EDGE_COUNT (bb->succs) > 1)
       {
        cond = fis_get_condition (BB_END (bb));
 
@@ -3769,7 +3331,7 @@ find_implicit_sets (void)
            dest = GET_CODE (cond) == EQ ? BRANCH_EDGE (bb)->dest
                                         : FALLTHRU_EDGE (bb)->dest;
 
-           if (dest && ! dest->pred->pred_next
+           if (dest && single_pred_p (dest)
                && dest != EXIT_BLOCK_PTR)
              {
                new = gen_rtx_SET (VOIDmode, XEXP (cond, 0),
@@ -3879,8 +3441,7 @@ find_bypass_set (int regno, int bb)
       if (set == 0)
        break;
 
-      if (GET_CODE (set->expr) != SET)
-       abort ();
+      gcc_assert (GET_CODE (set->expr) == SET);
 
       src = SET_SRC (set->expr);
       if (gcse_constant_p (src))
@@ -3927,9 +3488,11 @@ static int
 bypass_block (basic_block bb, rtx setcc, rtx jump)
 {
   rtx insn, note;
-  edge e, enext, edest;
+  edge e, edest;
   int i, change;
   int may_be_loop_header;
+  unsigned removed_p;
+  edge_iterator ei;
 
   insn = (setcc != NULL) ? setcc : jump;
 
@@ -3941,7 +3504,7 @@ bypass_block (basic_block bb, rtx setcc, rtx jump)
     find_used_regs (&XEXP (note, 0), NULL);
 
   may_be_loop_header = false;
-  for (e = bb->pred; e; e = e->pred_next)
+  FOR_EACH_EDGE (e, ei, bb->preds)
     if (e->flags & EDGE_DFS_BACK)
       {
        may_be_loop_header = true;
@@ -3949,22 +3512,32 @@ bypass_block (basic_block bb, rtx setcc, rtx jump)
       }
 
   change = 0;
-  for (e = bb->pred; e; e = enext)
+  for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); )
     {
-      enext = e->pred_next;
+      removed_p = 0;
+         
       if (e->flags & EDGE_COMPLEX)
-       continue;
+       {
+         ei_next (&ei);
+         continue;
+       }
 
       /* We can't redirect edges from new basic blocks.  */
       if (e->src->index >= bypass_last_basic_block)
-       continue;
+       {
+         ei_next (&ei);
+         continue;
+       }
 
       /* The irreducible loops created by redirecting of edges entering the
         loop from outside would decrease effectiveness of some of the following
         optimizations, so prevent this.  */
       if (may_be_loop_header
          && !(e->flags & EDGE_DFS_BACK))
-       continue;
+       {
+         ei_next (&ei);
+         continue;
+       }
 
       for (i = 0; i < reg_use_count; i++)
        {
@@ -4010,12 +3583,9 @@ bypass_block (basic_block bb, rtx setcc, rtx jump)
            {
              dest = BLOCK_FOR_INSN (XEXP (new, 0));
              /* Don't bypass edges containing instructions.  */
-             for (edest = bb->succ; edest; edest = edest->succ_next)
-               if (edest->dest == dest && edest->insns.r)
-                 {
-                   dest = NULL;
-                   break;
-                 }
+             edest = find_edge (bb, dest);
+             if (edest && edest->insns.r)
+               dest = NULL;
            }
          else
            dest = NULL;
@@ -4024,16 +3594,9 @@ bypass_block (basic_block bb, rtx setcc, rtx jump)
             branch.  We would end up emitting the instruction on "both"
             edges.  */
 
-         if (dest && setcc && !CC0_P (SET_DEST (PATTERN (setcc))))
-           {
-             edge e2;
-             for (e2 = e->src->succ; e2; e2 = e2->succ_next)
-               if (e2->dest == dest)
-                 {
-                   dest = NULL;
-                   break;
-                 }
-           }
+         if (dest && setcc && !CC0_P (SET_DEST (PATTERN (setcc)))
+             && find_edge (e->src, dest))
+           dest = NULL;
 
          old_dest = e->dest;
          if (dest != NULL
@@ -4061,9 +3624,12 @@ bypass_block (basic_block bb, rtx setcc, rtx jump)
                           e->src->index, old_dest->index, dest->index);
                }
              change = 1;
+             removed_p = 1;
              break;
            }
        }
+      if (!removed_p)
+       ei_next (&ei);
     }
   return change;
 }
@@ -4096,7 +3662,7 @@ bypass_conditional_jumps (void)
                  EXIT_BLOCK_PTR, next_bb)
     {
       /* Check for more than one predecessor.  */
-      if (bb->pred && bb->pred->pred_next)
+      if (!single_pred_p (bb))
        {
          setcc = NULL_RTX;
          for (insn = BB_HEAD (bb);
@@ -4243,12 +3809,13 @@ compute_pre_data (void)
   FOR_EACH_BB (bb)
     {
       edge e;
+      edge_iterator ei;
 
       /* If the current block is the destination of an abnormal edge, we
         kill all trapping expressions because we won't be able to properly
         place the instruction on the edge.  So make them neither
         anticipatable nor transparent.  This is fairly conservative.  */
-      for (e = bb->pred; e ; e = e->pred_next)
+      FOR_EACH_EDGE (e, ei, bb->preds)
        if (e->flags & EDGE_ABNORMAL)
          {
            sbitmap_difference (antloc[bb->index], antloc[bb->index], trapping_expr);
@@ -4288,8 +3855,9 @@ static int
 pre_expr_reaches_here_p_work (basic_block occr_bb, struct expr *expr, basic_block bb, char *visited)
 {
   edge pred;
-
-  for (pred = bb->pred; pred != NULL; pred = pred->pred_next)
+  edge_iterator ei;
+  
+  FOR_EACH_EDGE (pred, ei, bb->preds)
     {
       basic_block pred_bb = pred->src;
 
@@ -4363,8 +3931,14 @@ process_insert_insn (struct expr *expr)
   /* Otherwise, make a new insn to compute this expression and make sure the
      insn will be recognized (this also adds any needed CLOBBERs).  Copy the
      expression to make sure we don't have any sharing issues.  */
-  else if (insn_invalid_p (emit_insn (gen_rtx_SET (VOIDmode, reg, exp))))
-    abort ();
+  else
+    {
+      rtx insn = emit_insn (gen_rtx_SET (VOIDmode, reg, exp));
+
+      if (insn_invalid_p (insn))
+       gcc_unreachable ();
+    }
+  
 
   pat = get_insns ();
   end_sequence ();
@@ -4390,8 +3964,7 @@ insert_insn_end_bb (struct expr *expr, basic_block bb, int pre)
   rtx pat, pat_end;
 
   pat = process_insert_insn (expr);
-  if (pat == NULL_RTX || ! INSN_P (pat))
-    abort ();
+  gcc_assert (pat && INSN_P (pat));
 
   pat_end = pat;
   while (NEXT_INSN (pat_end) != NULL_RTX)
@@ -4403,7 +3976,8 @@ insert_insn_end_bb (struct expr *expr, basic_block bb, int pre)
 
   if (JUMP_P (insn)
       || (NONJUMP_INSN_P (insn)
-         && (bb->succ->succ_next || (bb->succ->flags & EDGE_ABNORMAL))))
+         && (!single_succ_p (bb)
+             || single_succ_edge (bb)->flags & EDGE_ABNORMAL)))
     {
 #ifdef HAVE_cc0
       rtx note;
@@ -4411,10 +3985,9 @@ insert_insn_end_bb (struct expr *expr, basic_block bb, int pre)
       /* It should always be the case that we can put these instructions
         anywhere in the basic block with performing PRE optimizations.
         Check this.  */
-      if (NONJUMP_INSN_P (insn) && pre
-         && !TEST_BIT (antloc[bb->index], expr->bitmap_index)
-         && !TEST_BIT (transp[bb->index], expr->bitmap_index))
-       abort ();
+      gcc_assert (!NONJUMP_INSN_P (insn) || !pre
+                 || TEST_BIT (antloc[bb->index], expr->bitmap_index)
+                 || TEST_BIT (transp[bb->index], expr->bitmap_index));
 
       /* If this is a jump table, then we can't insert stuff here.  Since
         we know the previous real insn must be the tablejump, we insert
@@ -4439,13 +4012,14 @@ insert_insn_end_bb (struct expr *expr, basic_block bb, int pre)
        }
 #endif
       /* FIXME: What if something in cc0/jump uses value set in new insn?  */
-      new_insn = emit_insn_before (pat, insn);
+      new_insn = emit_insn_before_noloc (pat, insn);
     }
 
   /* Likewise if the last insn is a call, as will happen in the presence
      of exception handling.  */
   else if (CALL_P (insn)
-          && (bb->succ->succ_next || (bb->succ->flags & EDGE_ABNORMAL)))
+          && (!single_succ_p (bb)
+              || single_succ_edge (bb)->flags & EDGE_ABNORMAL))
     {
       /* Keeping in mind SMALL_REGISTER_CLASSES and parameters in registers,
         we search backward and place the instructions before the first
@@ -4456,10 +4030,9 @@ insert_insn_end_bb (struct expr *expr, basic_block bb, int pre)
         anywhere in the basic block with performing PRE optimizations.
         Check this.  */
 
-      if (pre
-         && !TEST_BIT (antloc[bb->index], expr->bitmap_index)
-         && !TEST_BIT (transp[bb->index], expr->bitmap_index))
-       abort ();
+      gcc_assert (!pre
+                 || TEST_BIT (antloc[bb->index], expr->bitmap_index)
+                 || TEST_BIT (transp[bb->index], expr->bitmap_index));
 
       /* Since different machines initialize their parameter registers
         in different orders, assume nothing.  Collect the set of all
@@ -4478,10 +4051,10 @@ insert_insn_end_bb (struct expr *expr, basic_block bb, int pre)
             || NOTE_INSN_BASIC_BLOCK_P (insn))
        insn = NEXT_INSN (insn);
 
-      new_insn = emit_insn_before (pat, insn);
+      new_insn = emit_insn_before_noloc (pat, insn);
     }
   else
-    new_insn = emit_insn_after (pat, insn);
+    new_insn = emit_insn_after_noloc (pat, insn);
 
   while (1)
     {
@@ -4544,7 +4117,7 @@ pre_edge_insert (struct edge_list *edge_list, struct expr **index_map)
                    if (! occr->deleted_p)
                      continue;
 
-                   /* Insert this expression on this edge if if it would
+                   /* Insert this expression on this edge if it would
                       reach the deleted occurrence in BB.  */
                    if (!TEST_BIT (inserted[e], j))
                      {
@@ -4558,7 +4131,7 @@ pre_edge_insert (struct edge_list *edge_list, struct expr **index_map)
                           handling this situation.  This one is easiest for
                           now.  */
 
-                       if ((eg->flags & EDGE_ABNORMAL) == EDGE_ABNORMAL)
+                       if (eg->flags & EDGE_ABNORMAL)
                          insert_insn_end_bb (index_map[j], bb, 0);
                        else
                          {
@@ -4616,10 +4189,13 @@ pre_insert_copy_insn (struct expr *expr, rtx insn)
   int i;
 
   /* This block matches the logic in hash_scan_insn.  */
-  if (GET_CODE (pat) == SET)
-    set = pat;
-  else if (GET_CODE (pat) == PARALLEL)
+  switch (GET_CODE (pat))
     {
+    case SET:
+      set = pat;
+      break;
+
+    case PARALLEL:
       /* Search through the parallel looking for the set whose
         source was the expression that we're interested in.  */
       set = NULL_RTX;
@@ -4633,9 +4209,11 @@ pre_insert_copy_insn (struct expr *expr, rtx insn)
              break;
            }
        }
+      break;
+
+    default:
+      gcc_unreachable ();
     }
-  else
-    abort ();
 
   if (REG_P (SET_DEST (set)))
     {
@@ -4647,7 +4225,6 @@ pre_insert_copy_insn (struct expr *expr, rtx insn)
           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
@@ -5159,6 +4736,7 @@ static int
 hoist_expr_reaches_here_p (basic_block expr_bb, int expr_index, basic_block bb, char *visited)
 {
   edge pred;
+  edge_iterator ei;
   int visited_allocated_locally = 0;
 
 
@@ -5168,7 +4746,7 @@ hoist_expr_reaches_here_p (basic_block expr_bb, int expr_index, basic_block bb,
       visited = xcalloc (last_basic_block, 1);
     }
 
-  for (pred = bb->pred; pred != NULL; pred = pred->pred_next)
+  FOR_EACH_EDGE (pred, ei, bb->preds)
     {
       basic_block pred_bb = pred->src;
 
@@ -5329,15 +4907,10 @@ hoist_code (void)
                      while (BLOCK_FOR_INSN (occr->insn) != dominated && occr)
                        occr = occr->next;
 
-                     /* Should never happen.  */
-                     if (!occr)
-                       abort ();
-
+                     gcc_assert (occr);
                      insn = occr->insn;
-
                      set = single_set (insn);
-                     if (! set)
-                       abort ();
+                     gcc_assert (set);
 
                      /* Create a pseudo-reg to store the result of reaching
                         expressions into.  Get the mode for the new pseudo
@@ -5426,7 +4999,8 @@ ldst_entry (rtx x)
   struct ls_expr * ptr;
   unsigned int hash;
 
-  hash = hash_expr_1 (x, GET_MODE (x), & do_not_record_p);
+  hash = hash_rtx (x, GET_MODE (x), &do_not_record_p,
+                  NULL,  /*have_reg_qty=*/false);
 
   for (ptr = pre_ldst_mems; ptr != NULL; ptr = ptr->next)
     if (ptr->hash_index == hash && expr_equiv_p (ptr->pattern, x))
@@ -5914,7 +5488,7 @@ extract_mentioned_regs_helper (rtx x, rtx accum)
     case POST_DEC:
     case POST_INC:
       /* We do not run this function with arguments having side effects.  */
-      abort ();
+      gcc_unreachable ();
 
     case PC:
     case CC0: /*FIXME*/
@@ -6113,16 +5687,8 @@ compute_store_table (void)
 
          if (CALL_P (insn))
            {
-             bool clobbers_all = false;
-#ifdef NON_SAVING_SETJMP
-             if (NON_SAVING_SETJMP
-                 && find_reg_note (insn, REG_SETJMP, NULL_RTX))
-               clobbers_all = true;
-#endif
-
              for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-               if (clobbers_all
-                   || TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
+               if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
                  {
                    last_set_in[regno] = INSN_UID (insn);
                    SET_BIT (reg_set_in_block[bb->index], regno);
@@ -6146,16 +5712,8 @@ compute_store_table (void)
 
          if (CALL_P (insn))
            {
-             bool clobbers_all = false;
-#ifdef NON_SAVING_SETJMP
-             if (NON_SAVING_SETJMP
-                 && find_reg_note (insn, REG_SETJMP, NULL_RTX))
-               clobbers_all = true;
-#endif
-
              for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-               if (clobbers_all
-                   || TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
+               if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
                  already_set[regno] = 1;
            }
 
@@ -6170,16 +5728,8 @@ compute_store_table (void)
          note_stores (pat, reg_clear_last_set, last_set_in);
          if (CALL_P (insn))
            {
-             bool clobbers_all = false;
-#ifdef NON_SAVING_SETJMP
-             if (NON_SAVING_SETJMP
-                 && find_reg_note (insn, REG_SETJMP, NULL_RTX))
-               clobbers_all = true;
-#endif
-
              for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-               if ((clobbers_all
-                    || TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
+               if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)
                    && last_set_in[regno] == INSN_UID (insn))
                  last_set_in[regno] = 0;
            }
@@ -6188,8 +5738,7 @@ compute_store_table (void)
 #ifdef ENABLE_CHECKING
       /* last_set_in should now be all-zero.  */
       for (regno = 0; regno < max_gcse_regno; regno++)
-       if (last_set_in[regno] != 0)
-         abort ();
+       gcc_assert (!last_set_in[regno]);
 #endif
 
       /* Clear temporary marks.  */
@@ -6284,7 +5833,7 @@ find_loads (rtx x, rtx store_pattern, int after)
 
 /* Check if INSN kills the store pattern X (is aliased with it).
    AFTER is true if we are checking the case when store X occurs
-   after the insn.  Return true if it it does.  */
+   after the insn.  Return true if it does.  */
 
 static bool
 store_killed_in_insn (rtx x, rtx x_regs, rtx insn, int after)
@@ -6321,8 +5870,7 @@ store_killed_in_insn (rtx x, rtx x_regs, rtx insn, int after)
       rtx pat = PATTERN (insn);
       rtx dest = SET_DEST (pat);
 
-      if (GET_CODE (dest) == SIGN_EXTRACT
-         || GET_CODE (dest) == ZERO_EXTRACT)
+      if (GET_CODE (dest) == ZERO_EXTRACT)
        dest = XEXP (dest, 0);
 
       /* Check for memory stores to aliased objects.  */
@@ -6521,7 +6069,7 @@ insert_insn_start_bb (rtx insn, basic_block bb)
       before = NEXT_INSN (before);
     }
 
-  insn = emit_insn_after (insn, prev);
+  insn = emit_insn_after_noloc (insn, prev);
 
   if (gcse_file)
     {
@@ -6542,6 +6090,7 @@ insert_store (struct ls_expr * expr, edge e)
   rtx reg, insn;
   basic_block bb;
   edge tmp;
+  edge_iterator ei;
 
   /* We did all the deleted before this insert, so if we didn't delete a
      store, then we haven't set the reaching reg yet either.  */
@@ -6558,12 +6107,12 @@ insert_store (struct ls_expr * expr, edge e)
      insert it at the start of the BB, and reset the insert bits on the other
      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)
+  FOR_EACH_EDGE (tmp, ei, e->dest->preds)
     if (!(tmp->flags & EDGE_FAKE))
       {
        int index = EDGE_INDEX (edge_list, tmp->src, tmp->dest);
-       if (index == EDGE_INDEX_NO_EDGE)
-         abort ();
+       
+       gcc_assert (index != EDGE_INDEX_NO_EDGE);
        if (! TEST_BIT (pre_insert_map[index], expr->index))
          break;
       }
@@ -6572,7 +6121,7 @@ insert_store (struct ls_expr * expr, edge e)
      insertion vector for these edges, and insert at the start of the BB.  */
   if (!tmp && bb != EXIT_BLOCK_PTR)
     {
-      for (tmp = e->dest->pred; tmp ; tmp = tmp->pred_next)
+      FOR_EACH_EDGE (tmp, ei, e->dest->preds)
        {
          int index = EDGE_INDEX (edge_list, tmp->src, tmp->dest);
          RESET_BIT (pre_insert_map[index], expr->index);
@@ -6581,13 +6130,9 @@ insert_store (struct ls_expr * expr, edge e)
       return 0;
     }
 
-  /* We can't insert on this edge, so we'll insert at the head of the
-     successors block.  See Morgan, sec 10.5.  */
-  if ((e->flags & EDGE_ABNORMAL) == EDGE_ABNORMAL)
-    {
-      insert_insn_start_bb (insn, bb);
-      return 0;
-    }
+  /* We can't put stores in the front of blocks pointed to by abnormal
+     edges since that may put a store where one didn't used to be.  */
+  gcc_assert (!(e->flags & EDGE_ABNORMAL));
 
   insert_insn_on_edge (insn, e);
 
@@ -6610,33 +6155,40 @@ insert_store (struct ls_expr * expr, edge e)
 static void
 remove_reachable_equiv_notes (basic_block bb, struct ls_expr *smexpr)
 {
-  edge *stack = xmalloc (sizeof (edge) * n_basic_blocks), act;
+  edge_iterator *stack, ei;
+  int sp;
+  edge act;
   sbitmap visited = sbitmap_alloc (last_basic_block);
-  int stack_top = 0;
   rtx last, insn, note;
   rtx mem = smexpr->pattern;
 
+  stack = xmalloc (sizeof (edge_iterator) * n_basic_blocks);
+  sp = 0;
+  ei = ei_start (bb->succs);
+
   sbitmap_zero (visited);
-  act = bb->succ;
 
+  act = (EDGE_COUNT (ei_container (ei)) > 0 ? EDGE_I (ei_container (ei), 0) : NULL);
   while (1)
     {
       if (!act)
        {
-         if (!stack_top)
+         if (!sp)
            {
              free (stack);
              sbitmap_free (visited);
              return;
            }
-         act = stack[--stack_top];
+         act = ei_edge (stack[--sp]);
        }
       bb = act->dest;
 
       if (bb == EXIT_BLOCK_PTR
          || TEST_BIT (visited, bb->index))
        {
-         act = act->succ_next;
+         if (!ei_end_p (ei))
+             ei_next (&ei);
+         act = (! ei_end_p (ei)) ? ei_edge (ei) : NULL;
          continue;
        }
       SET_BIT (visited, bb->index);
@@ -6664,12 +6216,17 @@ remove_reachable_equiv_notes (basic_block bb, struct ls_expr *smexpr)
                       INSN_UID (insn));
            remove_note (insn, note);
          }
-      act = act->succ_next;
-      if (bb->succ)
+
+      if (!ei_end_p (ei))
+       ei_next (&ei);
+      act = (! ei_end_p (ei)) ? ei_edge (ei) : NULL;
+
+      if (EDGE_COUNT (bb->succs) > 0)
        {
          if (act)
-           stack[stack_top++] = act;
-         act = bb->succ;
+           stack[sp++] = ei;
+         ei = ei_start (bb->succs);
+         act = (EDGE_COUNT (ei_container (ei)) > 0 ? EDGE_I (ei_container (ei), 0) : NULL);
        }
     }
 }
@@ -6679,7 +6236,7 @@ remove_reachable_equiv_notes (basic_block bb, struct ls_expr *smexpr)
 static void
 replace_store_insn (rtx reg, rtx del, basic_block bb, struct ls_expr *smexpr)
 {
-  rtx insn, mem, note, set, ptr;
+  rtx insn, mem, note, set, ptr, pair;
 
   mem = smexpr->pattern;
   insn = gen_move_insn (reg, SET_SRC (single_set (del)));
@@ -6701,6 +6258,26 @@ replace_store_insn (rtx reg, rtx del, basic_block bb, struct ls_expr *smexpr)
        XEXP (ptr, 0) = insn;
        break;
       }
+
+  /* Move the notes from the deleted insn to its replacement, and patch
+     up the LIBCALL notes.  */
+  REG_NOTES (insn) = REG_NOTES (del);
+
+  note = find_reg_note (insn, REG_RETVAL, NULL_RTX);
+  if (note)
+    {
+      pair = XEXP (note, 0);
+      note = find_reg_note (pair, REG_LIBCALL, NULL_RTX);
+      XEXP (note, 0) = insn;
+    }
+  note = find_reg_note (insn, REG_LIBCALL, NULL_RTX);
+  if (note)
+    {
+      pair = XEXP (note, 0);
+      note = find_reg_note (pair, REG_RETVAL, NULL_RTX);
+      XEXP (note, 0) = insn;
+    }
+
   delete_insn (del);
 
   /* Now we must handle REG_EQUAL notes whose contents is equal to the mem;
@@ -6819,6 +6396,25 @@ store_motion (void)
   /* Now we want to insert the new stores which are going to be needed.  */
   for (ptr = first_ls_expr (); ptr != NULL; ptr = next_ls_expr (ptr))
     {
+      /* If any of the edges we have above are abnormal, we can't move this
+        store.  */
+      for (x = NUM_EDGES (edge_list) - 1; x >= 0; x--)
+       if (TEST_BIT (pre_insert_map[x], ptr->index)
+           && (INDEX_EDGE (edge_list, x)->flags & EDGE_ABNORMAL))
+         break;
+
+      if (x >= 0)
+       {
+         if (gcse_file != NULL)
+           fprintf (gcse_file,
+                    "Can't replace store %d: abnormal edge from %d to %d\n",
+                    ptr->index, INDEX_EDGE (edge_list, x)->src->index,
+                    INDEX_EDGE (edge_list, x)->dest->index);
+         continue;
+       }
+                     
+      /* Now we want to insert the new stores which are going to be needed.  */
+
       FOR_EACH_BB (bb)
        if (TEST_BIT (pre_delete_map[bb->index], ptr->index))
          delete_store (ptr, bb);
@@ -6945,654 +6541,4 @@ is_too_expensive (const char *pass)
   return false;
 }
 
-/* The following code implements gcse after reload, the purpose of this
-   pass is to cleanup redundant loads generated by reload and other
-   optimizations that come after gcse. It searches for simple inter-block
-   redundancies and tries to eliminate them by adding moves and loads
-   in cold places.  */
-
-/* The following structure holds the information about the occurrences of
-   the redundant instructions.  */
-struct unoccr
-{
-  struct unoccr *next;
-  edge pred;
-  rtx insn;
-};
-
-static bool reg_used_on_edge (rtx, edge);
-static rtx reg_set_between_after_reload_p (rtx, rtx, rtx);
-static rtx reg_used_between_after_reload_p (rtx, rtx, rtx);
-static rtx get_avail_load_store_reg (rtx);
-static bool is_jump_table_basic_block (basic_block);
-static bool bb_has_well_behaved_predecessors (basic_block);
-static struct occr* get_bb_avail_insn (basic_block, struct occr *);
-static void hash_scan_set_after_reload (rtx, rtx, struct hash_table *);
-static void compute_hash_table_after_reload (struct hash_table *);
-static void eliminate_partially_redundant_loads (basic_block,
-                                               rtx,
-                                               struct expr *);
-static void gcse_after_reload (void);
-static struct occr* get_bb_avail_insn (basic_block, struct occr *);
-void gcse_after_reload_main (rtx, FILE *);
-
-
-/* Check if register REG is used in any insn waiting to be inserted on E.
-   Assumes no such insn can be a CALL_INSN; if so call reg_used_between_p
-   with PREV(insn),NEXT(insn) instead of calling
-   reg_overlap_mentioned_p.  */
-
-static bool
-reg_used_on_edge (rtx reg, edge e)
-{
-  rtx insn;
-
-  for (insn = e->insns.r; insn; insn = NEXT_INSN (insn))
-    if (INSN_P (insn) && reg_overlap_mentioned_p (reg, PATTERN (insn)))
-      return true;
-
-  return false;
-}
-
-/* Return the insn that sets register REG or clobbers it in between
-   FROM_INSN and TO_INSN (exclusive of those two).
-   Just like reg_set_between but for hard registers and not pseudos.  */
-
-static rtx
-reg_set_between_after_reload_p (rtx reg, rtx from_insn, rtx to_insn)
-{
-  rtx insn;
-  int regno;
-
-  if (! REG_P (reg))
-    abort ();
-  regno = REGNO (reg);
-
-  /* We are called after register allocation.  */
-  if (regno >= FIRST_PSEUDO_REGISTER)
-    abort ();
-
-  if (from_insn == to_insn)
-    return NULL_RTX;
-
-  for (insn = NEXT_INSN (from_insn);
-       insn != to_insn;
-       insn = NEXT_INSN (insn))
-    {
-      if (INSN_P (insn))
-       {
-         if (FIND_REG_INC_NOTE (insn, reg)
-             || (CALL_P (insn)
-                 && call_used_regs[regno])
-             || find_reg_fusage (insn, CLOBBER, reg))
-           return insn;
-       }
-      if (set_of (reg, insn) != NULL_RTX)
-       return insn;
-    }
-  return NULL_RTX;
-}
-
-/* Return the insn that uses register REG in between FROM_INSN and TO_INSN
-   (exclusive of those two). Similar to reg_used_between but for hard
-   registers and not pseudos.  */
-
-static rtx
-reg_used_between_after_reload_p (rtx reg, rtx from_insn, rtx to_insn)
-{
-  rtx insn;
-  int regno;
-
-  if (! REG_P (reg))
-    return to_insn;
-  regno = REGNO (reg);
-
-  /* We are called after register allocation.  */
-  if (regno >= FIRST_PSEUDO_REGISTER)
-    abort ();
-  if (from_insn == to_insn)
-    return NULL_RTX;
-
-  for (insn = NEXT_INSN (from_insn);
-       insn != to_insn;
-       insn = NEXT_INSN (insn))
-    if (INSN_P (insn)
-       && (reg_overlap_mentioned_p (reg, PATTERN (insn))
-           || (CALL_P (insn)
-               && call_used_regs[regno])
-           || find_reg_fusage (insn, USE, reg)
-           || find_reg_fusage (insn, CLOBBER, reg)))
-      return insn;
-  return NULL_RTX;
-}
-
-/* Return the loaded/stored register of a load/store instruction.  */
-
-static rtx
-get_avail_load_store_reg (rtx insn)
-{
-  if (REG_P (SET_DEST (PATTERN (insn))))  /* A load.  */
-    return SET_DEST(PATTERN(insn));
-  if (REG_P (SET_SRC (PATTERN (insn))))  /* A store.  */
-    return SET_SRC (PATTERN (insn));
-  abort ();
-}
-
-/* Don't handle ABNORMAL edges or jump tables.  */
-
-static bool
-is_jump_table_basic_block (basic_block bb)
-{
-  rtx insn = BB_END (bb);
-
-  if (JUMP_TABLE_DATA_P (insn))
-    return true;
-  return false;
-}
-
-/* Return nonzero if the predecessors of BB are "well behaved".  */
-
-static bool
-bb_has_well_behaved_predecessors (basic_block bb)
-{
-  edge pred;
-
-  if (! bb->pred)
-    return false;
-  for (pred = bb->pred; pred != NULL; pred = pred->pred_next)
-    if (((pred->flags & EDGE_ABNORMAL) && EDGE_CRITICAL_P (pred))
-       || is_jump_table_basic_block (pred->src))
-      return false;
-  return true;
-}
-
-
-/* Search for the occurrences of expression in BB.  */
-
-static struct occr*
-get_bb_avail_insn (basic_block bb, struct occr *occr)
-{
-  for (; occr != NULL; occr = occr->next)
-    if (BLOCK_FOR_INSN (occr->insn)->index == bb->index)
-      return occr;
-  return NULL;
-}
-
-/* Perform partial GCSE pass after reload, try to eliminate redundant loads
-   created by the reload pass. We try to look for a full or partial
-   redundant loads fed by one or more loads/stores in predecessor BBs,
-   and try adding loads to make them fully redundant. We also check if
-   it's worth adding loads to be able to delete the redundant load.
-
-   Algorithm:
-   1. Build available expressions hash table:
-       For each load/store instruction, if the loaded/stored memory didn't
-       change until the end of the basic block add this memory expression to
-       the hash table.
-   2. Perform Redundancy elimination:
-      For each load instruction do the following:
-        perform partial redundancy elimination, check if it's worth adding
-        loads to make the load fully redundant. If so add loads and
-        register copies and delete the load.
-
-   Future enhancement:
-     if loaded register is used/defined between load and some store,
-     look for some other free register between load and all its stores,
-     and replace load with a copy from this register to the loaded
-     register.  */
-
-
-/* This handles the case where several stores feed a partially redundant
-   load. It checks if the redundancy elimination is possible and if it's
-   worth it.  */
-
-static void
-eliminate_partially_redundant_loads (basic_block bb, rtx insn,
-                                    struct expr *expr)
-{
-  edge pred;
-  rtx avail_insn = NULL_RTX;
-  rtx avail_reg;
-  rtx dest, pat;
-  struct occr *a_occr;
-  struct unoccr *occr, *avail_occrs = NULL;
-  struct unoccr *unoccr, *unavail_occrs = NULL;
-  int npred_ok = 0;
-  gcov_type ok_count = 0; /* Redundant load execution count.  */
-  gcov_type critical_count = 0; /* Execution count of critical edges.  */
-
-  /* The execution count of the loads to be added to make the
-     load fully redundant.  */
-  gcov_type not_ok_count = 0;
-  basic_block pred_bb;
-
-  pat = PATTERN (insn);
-  dest = SET_DEST (pat);
-  /* Check that the loaded register is not used, set, or killed from the
-     beginning of the block.  */
-  if (reg_used_between_after_reload_p (dest,
-                                       PREV_INSN (BB_HEAD (bb)), insn)
-      || reg_set_between_after_reload_p (dest,
-                                         PREV_INSN (BB_HEAD (bb)), insn))
-    return;
-
-  /* Check potential for replacing load with copy for predecessors.  */
-  for (pred = bb->pred; pred; pred = pred->pred_next)
-    {
-      rtx next_pred_bb_end;
-
-      avail_insn = NULL_RTX;
-      pred_bb = pred->src;
-      next_pred_bb_end = NEXT_INSN (BB_END (pred_bb));
-      for (a_occr = get_bb_avail_insn (pred_bb, expr->avail_occr); a_occr;
-          a_occr = get_bb_avail_insn (pred_bb, a_occr->next))
-       {
-         /* Check if the loaded register is not used.  */
-         avail_insn = a_occr->insn;
-         if (! (avail_reg = get_avail_load_store_reg (avail_insn)))
-           abort ();
-         /* Make sure we can generate a move from register avail_reg to
-            dest.  */
-         extract_insn (gen_move_insn (copy_rtx (dest),
-                                      copy_rtx (avail_reg)));
-         if (! constrain_operands (1)
-             || reg_killed_on_edge (avail_reg, pred)
-             || reg_used_on_edge (dest, pred))
-           {
-             avail_insn = NULL;
-             continue;
-           }
-         if (! reg_set_between_after_reload_p (avail_reg, avail_insn,
-                                               next_pred_bb_end))
-           /* AVAIL_INSN remains non-null.  */
-           break;
-         else
-           avail_insn = NULL;
-       }
-      if (avail_insn != NULL_RTX)
-       {
-         npred_ok++;
-         ok_count += pred->count;
-          if (EDGE_CRITICAL_P (pred))
-            critical_count += pred->count;
-         occr = gmalloc (sizeof (struct unoccr));
-         occr->insn = avail_insn;
-         occr->pred = pred;
-         occr->next = avail_occrs;
-         avail_occrs = occr;
-       }
-      else
-       {
-         not_ok_count += pred->count;
-          if (EDGE_CRITICAL_P (pred))
-            critical_count += pred->count;
-         unoccr = gmalloc (sizeof (struct unoccr));
-         unoccr->insn = NULL_RTX;
-         unoccr->pred = pred;
-         unoccr->next = unavail_occrs;
-         unavail_occrs = unoccr;
-       }
-    }
-
-  if (npred_ok == 0    /* No load can be replaced by copy.  */
-      || (optimize_size && npred_ok > 1)) /* Prevent exploding the code.  */
-    goto cleanup;
-
-  /* Check if it's worth applying the partial redundancy elimination.  */
-  if (ok_count < GCSE_AFTER_RELOAD_PARTIAL_FRACTION * not_ok_count)
-    goto cleanup;
-
-  if (ok_count < GCSE_AFTER_RELOAD_CRITICAL_FRACTION * critical_count)
-    goto cleanup;
-
-  /* Generate moves to the loaded register from where
-     the memory is available.  */
-  for (occr = avail_occrs; occr; occr = occr->next)
-    {
-      avail_insn = occr->insn;
-      pred = occr->pred;
-      /* Set avail_reg to be the register having the value of the
-        memory.  */
-      avail_reg = get_avail_load_store_reg (avail_insn);
-      if (! avail_reg)
-       abort ();
-
-      insert_insn_on_edge (gen_move_insn (copy_rtx (dest),
-                                         copy_rtx (avail_reg)),
-                          pred);
-
-      if (gcse_file)
-       fprintf (gcse_file,
-                "GCSE AFTER reload generating move from %d to %d on \
-                edge from %d to %d\n",
-                REGNO (avail_reg),
-                REGNO (dest),
-                pred->src->index,
-                pred->dest->index);
-    }
-
-  /* Regenerate loads where the memory is unavailable.  */
-  for (unoccr = unavail_occrs; unoccr; unoccr = unoccr->next)
-    {
-      pred = unoccr->pred;
-      insert_insn_on_edge (copy_insn (PATTERN (insn)), pred);
-
-      if (gcse_file)
-       fprintf (gcse_file,
-                "GCSE AFTER reload: generating on edge from %d to %d\
-                 a copy of load:\n",
-                pred->src->index,
-                pred->dest->index);
-    }
-
-  /* Delete the insn if it is not available in this block and mark it
-     for deletion if it is available. If insn is available it may help
-     discover additional redundancies, so mark it for later deletion.*/
-  for (a_occr = get_bb_avail_insn (bb, expr->avail_occr);
-       a_occr && (a_occr->insn != insn);
-       a_occr = get_bb_avail_insn (bb, a_occr->next));
-
-  if (!a_occr)
-    delete_insn (insn);
-  else
-    a_occr->deleted_p = 1;
-
-cleanup:
-
-  while (unavail_occrs)
-    {
-      struct unoccr *temp = unavail_occrs->next;
-      free (unavail_occrs);
-      unavail_occrs = temp;
-    }
-
-  while (avail_occrs)
-    {
-      struct unoccr *temp = avail_occrs->next;
-      free (avail_occrs);
-      avail_occrs = temp;
-    }
-}
-
-/* Performing the redundancy elimination as described before.  */
-
-static void
-gcse_after_reload (void)
-{
-  unsigned int i;
-  rtx insn;
-  basic_block bb;
-  struct expr *expr;
-  struct occr *occr;
-
-  /* Note we start at block 1.  */
-
-  if (ENTRY_BLOCK_PTR->next_bb == EXIT_BLOCK_PTR)
-    return;
-
-  FOR_BB_BETWEEN (bb,
-                 ENTRY_BLOCK_PTR->next_bb->next_bb,
-                 EXIT_BLOCK_PTR,
-                 next_bb)
-    {
-      if (! bb_has_well_behaved_predecessors (bb))
-       continue;
-
-      /* Do not try this optimization on cold basic blocks.  */
-      if (probably_cold_bb_p (bb))
-       continue;
-
-      reset_opr_set_tables ();
-
-      for (insn = BB_HEAD (bb);
-          insn != NULL
-          && insn != NEXT_INSN (BB_END (bb));
-          insn = NEXT_INSN (insn))
-       {
-         /* Is it a load - of the form (set (reg) (mem))?  */
-         if (NONJUMP_INSN_P (insn)
-              && GET_CODE (PATTERN (insn)) == SET
-             && REG_P (SET_DEST (PATTERN (insn)))
-             && MEM_P (SET_SRC (PATTERN (insn))))
-           {
-             rtx pat = PATTERN (insn);
-             rtx src = SET_SRC (pat);
-             struct expr *expr;
-
-             if (general_operand (src, GET_MODE (src))
-                 /* Is the expression recorded?  */
-                 && (expr = lookup_expr (src, &expr_hash_table)) != NULL
-                 /* Are the operands unchanged since the start of the
-                    block?  */
-                 && oprs_not_set_p (src, insn)
-                 && ! MEM_VOLATILE_P (src)
-                 && GET_MODE (src) != BLKmode
-                 && !(flag_non_call_exceptions && may_trap_p (src))
-                 && !side_effects_p (src))
-               {
-                 /* We now have a load (insn) and an available memory at
-                    its BB start (expr). Try to remove the loads if it is
-                    redundant.  */
-                 eliminate_partially_redundant_loads (bb, insn, expr);
-               }
-           }
-
-           /* Keep track of everything modified by this insn.  */
-           if (INSN_P (insn))
-             mark_oprs_set (insn);
-       }
-    }
-
-  commit_edge_insertions ();
-
-  /* Go over the expression hash table and delete insns that were
-     marked for later deletion.  */
-  for (i = 0; i < expr_hash_table.size; i++)
-    {
-      for (expr = expr_hash_table.table[i];
-          expr != NULL;
-          expr = expr->next_same_hash)
-       for (occr = expr->avail_occr; occr; occr = occr->next)
-         if (occr->deleted_p)
-           delete_insn (occr->insn);
-    }
-}
-
-/* Scan pattern PAT of INSN and add an entry to the hash TABLE.
-   After reload we are interested in loads/stores only.  */
-
-static void
-hash_scan_set_after_reload (rtx pat, rtx insn, struct hash_table *table)
-{
-  rtx src = SET_SRC (pat);
-  rtx dest = SET_DEST (pat);
-
-  if (! MEM_P (src) && ! MEM_P (dest))
-    return;
-
-  if (REG_P (dest))
-    {
-      if (/* Don't GCSE something if we can't do a reg/reg copy.  */
-         can_copy_p (GET_MODE (dest))
-         /* 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_SRC something we want to gcse?  */
-         && general_operand (src, GET_MODE (src))
-         /* Don't CSE a nop.  */
-         && ! set_noop_p (pat)
-         && ! JUMP_P (insn))
-       {
-         /* An expression is not available if its operands are
-            subsequently modified, including this insn.  */
-         if (oprs_available_p (src, insn))
-           insert_expr_in_table (src, GET_MODE (dest), insn, 0, 1, table);
-       }
-    }
-  else if (REG_P (src))
-    {
-      /* Only record sets of pseudo-regs in the hash table.  */
-      if (/* 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?  */
-         && general_operand (dest, GET_MODE (dest))
-         /* Don't CSE a nop.  */
-         && ! set_noop_p (pat)
-         &&! JUMP_P (insn)
-         && ! (flag_float_store && FLOAT_MODE_P (GET_MODE (dest)))
-         /* Check if the memory expression is killed after insn.  */
-         && ! load_killed_in_block_p (BLOCK_FOR_INSN (insn),
-                                      INSN_CUID (insn) + 1,
-                                      dest,
-                                      1)
-         && oprs_unchanged_p (XEXP (dest, 0), insn, 1))
-       {
-         insert_expr_in_table (dest, GET_MODE (dest), insn, 0, 1, table);
-       }
-    }
-}
-
-
-/* Create hash table of memory expressions available at end of basic
-   blocks.  */
-
-static void
-compute_hash_table_after_reload (struct hash_table *table)
-{
-  unsigned int i;
-
-  table->set_p = 0;
-
-  /* Initialize count of number of entries in hash table.  */
-  table->n_elems = 0;
-  memset ((char *) table->table, 0,
-         table->size * sizeof (struct expr *));
-
-  /* While we compute the hash table we also compute a bit array of which
-     registers are set in which blocks.  */
-  sbitmap_vector_zero (reg_set_in_block, last_basic_block);
-
-  /* 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 = gmalloc (max_gcse_regno * sizeof (struct reg_avail_info));
-
-  for (i = 0; i < max_gcse_regno; ++i)
-    reg_avail_info[i].last_bb = NULL;
-
-  FOR_EACH_BB (current_bb)
-    {
-      rtx insn;
-      unsigned int regno;
-
-      /* First pass over the instructions records information used to
-        determine when registers and memory are first and last set.  */
-      for (insn = BB_HEAD (current_bb);
-          insn && insn != NEXT_INSN (BB_END (current_bb));
-          insn = NEXT_INSN (insn))
-       {
-         if (! INSN_P (insn))
-           continue;
-
-         if (CALL_P (insn))
-           {
-             bool clobbers_all = false;
-
-#ifdef NON_SAVING_SETJMP
-             if (NON_SAVING_SETJMP
-                 && find_reg_note (insn, REG_SETJMP, NULL_RTX))
-               clobbers_all = true;
-#endif
-
-             for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-               if (clobbers_all
-                   || TEST_HARD_REG_BIT (regs_invalidated_by_call,
-                                         regno))
-                 record_last_reg_set_info (insn, regno);
-
-             mark_call (insn);
-           }
-
-           note_stores (PATTERN (insn), record_last_set_info, insn);
-
-           if (GET_CODE (PATTERN (insn)) == SET)
-             {
-               rtx src, dest;
-
-               src = SET_SRC (PATTERN (insn));
-               dest = SET_DEST (PATTERN (insn));
-               if (MEM_P (src) && auto_inc_p (XEXP (src, 0)))
-                 {
-                   regno = REGNO (XEXP (XEXP (src, 0), 0));
-                   record_last_reg_set_info (insn, regno);
-                 }
-               if (MEM_P (dest) && auto_inc_p (XEXP (dest, 0)))
-                 {
-                   regno = REGNO (XEXP (XEXP (dest, 0), 0));
-                   record_last_reg_set_info (insn, regno);
-                 }
-               }
-         }
-
-       /* The next pass builds the hash table.  */
-       for (insn = BB_HEAD (current_bb);
-            insn && insn != NEXT_INSN (BB_END (current_bb));
-            insn = NEXT_INSN (insn))
-         if (INSN_P (insn) && GET_CODE (PATTERN (insn)) == SET)
-           if (! find_reg_note (insn, REG_LIBCALL, NULL_RTX))
-             hash_scan_set_after_reload (PATTERN (insn), insn, table);
-    }
-
-  free (reg_avail_info);
-  reg_avail_info = NULL;
-}
-
-
-/* Main entry point of the GCSE after reload - clean some redundant loads
-   due to spilling.  */
-
-void
-gcse_after_reload_main (rtx f, FILE* file)
-{
-  gcse_subst_count = 0;
-  gcse_create_count = 0;
-
-  gcse_file = file;
-
-  gcc_obstack_init (&gcse_obstack);
-  bytes_used = 0;
-
-  /* We need alias.  */
-  init_alias_analysis ();
-
-  max_gcse_regno = max_reg_num ();
-
-  alloc_reg_set_mem (max_gcse_regno);
-  alloc_gcse_mem (f);
-  alloc_hash_table (max_cuid, &expr_hash_table, 0);
-  compute_hash_table_after_reload (&expr_hash_table);
-
-  if (gcse_file)
-    dump_hash_table (gcse_file, "Expression", &expr_hash_table);
-
-  if (expr_hash_table.n_elems > 0)
-    gcse_after_reload ();
-
-  free_hash_table (&expr_hash_table);
-
-  free_gcse_mem ();
-  free_reg_set_mem ();
-
-  /* We are finished with alias.  */
-  end_alias_analysis ();
-
-  obstack_free (&gcse_obstack, NULL);
-}
-
 #include "gt-gcse.h"