OSDN Git Service

Use C fixincludes for UnixWare 7.
[pf3gnuchains/gcc-fork.git] / gcc / flow.c
index 2dc2b17..a3cc477 100644 (file)
@@ -1,6 +1,6 @@
 /* Data flow analysis for GNU compiler.
-   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 
-   1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -19,7 +19,6 @@ along with GNU CC; see the file COPYING.  If not, write to
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
-
 /* This file contains the data flow analysis pass of the compiler.  It
    computes data flow information which tells combine_instructions
    which insns to consider combining and controls register allocation.
@@ -57,7 +56,7 @@ Boston, MA 02111-1307, USA.  */
    pseudo register.  The bit is 1 if the register is live at the
    beginning of the basic block.
 
-   Two types of elements can be added to an insn's REG_NOTES.  
+   Two types of elements can be added to an insn's REG_NOTES.
    A REG_DEAD note is added to an insn's REG_NOTES for any register
    that meets both of two conditions:  The value in the register is not
    needed in subsequent insns and the insn does not replace the value in
@@ -110,7 +109,7 @@ Boston, MA 02111-1307, USA.  */
    life_analysis sets current_function_sp_is_unchanging if the function
    doesn't modify the stack pointer.  */
 
-/* TODO: 
+/* TODO:
 
    Split out from life_analysis:
        - local property discovery (bb->local_live, bb->local_set)
@@ -136,6 +135,7 @@ Boston, MA 02111-1307, USA.  */
 #include "recog.h"
 #include "insn-flags.h"
 #include "expr.h"
+#include "ssa.h"
 
 #include "obstack.h"
 #include "splay-tree.h"
@@ -143,7 +143,6 @@ Boston, MA 02111-1307, USA.  */
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 
-
 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
    the stack pointer does not matter.  The value is tested only in
    functions that have frame pointers.
@@ -162,12 +161,17 @@ Boston, MA 02111-1307, USA.  */
 #define HAVE_sibcall_epilogue 0
 #endif
 
-/* The contents of the current function definition are allocated
-   in this obstack, and all are freed at the end of the function.
-   For top-level functions, this is temporary_obstack.
-   Separate obstacks are made for nested functions.  */
+#ifndef LOCAL_REGNO
+#define LOCAL_REGNO(REGNO)  0
+#endif
+#ifndef EPILOGUE_USES
+#define EPILOGUE_USES(REGNO)  0
+#endif
+
+/* The obstack on which the flow graph components are allocated.  */
 
-extern struct obstack *function_obstack;
+struct obstack flow_obstack;
+static char *flow_firstobj;
 
 /* Number of basic blocks in the current function.  */
 
@@ -189,6 +193,7 @@ struct basic_block_def entry_exit_blocks[2]
     NULL,                      /* pred */
     NULL,                      /* succ */
     NULL,                      /* local_set */
+    NULL,                      /* cond_local_set */
     NULL,                      /* global_live_at_start */
     NULL,                      /* global_live_at_end */
     NULL,                      /* aux */
@@ -203,6 +208,7 @@ struct basic_block_def entry_exit_blocks[2]
     NULL,                      /* pred */
     NULL,                      /* succ */
     NULL,                      /* local_set */
+    NULL,                      /* cond_local_set */
     NULL,                      /* global_live_at_start */
     NULL,                      /* global_live_at_end */
     NULL,                      /* aux */
@@ -241,6 +247,10 @@ regset regs_live_at_setjmp;
    are another pair, etc.  */
 rtx regs_may_share;
 
+/* Callback that determines if it's ok for a function to have no
+   noreturn attribute.  */
+int (*lang_missing_noreturn_ok_p) PARAMS ((tree));
+
 /* Set of registers that may be eliminable.  These are handled specially
    in updating regs_ever_live.  */
 
@@ -251,7 +261,7 @@ static HARD_REG_SET elim_reg_set;
 varray_type basic_block_for_insn;
 
 /* The labels mentioned in non-jump rtl.  Valid during find_basic_blocks.  */
-/* ??? Should probably be using LABEL_NUSES instead.  It would take a 
+/* ??? Should probably be using LABEL_NUSES instead.  It would take a
    bit of surgery to be able to use or co-opt the routines in jump.  */
 
 static rtx label_value_list;
@@ -289,9 +299,14 @@ struct propagate_block_info
      elimination.  */
   rtx mem_set_list;
 
-  /* If non-null, record the set of registers set in the basic block.  */
+  /* If non-null, record the set of registers set unconditionally in the
+     basic block.  */
   regset local_set;
 
+  /* If non-null, record the set of registers set conditionally in the
+     basic block.  */
+  regset cond_local_set;
+
 #ifdef HAVE_conditional_execution
   /* Indexed by register number, holds a reg_cond_life_info for each
      register that is not unconditionally live or dead.  */
@@ -301,6 +316,9 @@ struct propagate_block_info
   regset reg_cond_reg;
 #endif
 
+  /* The length of mem_set_list.  */
+  int mem_set_list_len;
+
   /* Non-zero if the value of CC0 is live.  */
   int cc0_live;
 
@@ -308,6 +326,24 @@ struct propagate_block_info
   int flags;
 };
 
+/* Maximum length of pbi->mem_set_list before we start dropping
+   new elements on the floor.  */
+#define MAX_MEM_SET_LIST_LEN   100
+
+/* Store the data structures necessary for depth-first search.  */
+struct depth_first_search_dsS {
+  /* stack for backtracking during the algorithm */
+  basic_block *stack;
+
+  /* number of edges in the stack.  That is, positions 0, ..., sp-1
+     have edges.  */
+  unsigned int sp;
+
+  /* record of basic blocks already seen by depth-first search */
+  sbitmap visited_blocks;
+};
+typedef struct depth_first_search_dsS *depth_first_search_ds;
+
 /* Forward declarations */
 static int count_basic_blocks          PARAMS ((rtx));
 static void find_basic_blocks_1                PARAMS ((rtx));
@@ -367,11 +403,14 @@ static void free_reg_cond_life_info       PARAMS ((splay_tree_value));
 static int flush_reg_cond_reg_1                PARAMS ((splay_tree_node, void *));
 static void flush_reg_cond_reg         PARAMS ((struct propagate_block_info *,
                                                 int));
-static rtx ior_reg_cond                        PARAMS ((rtx, rtx));
+static rtx elim_reg_cond               PARAMS ((rtx, unsigned int));
+static rtx ior_reg_cond                        PARAMS ((rtx, rtx, int));
 static rtx not_reg_cond                        PARAMS ((rtx));
-static rtx nand_reg_cond               PARAMS ((rtx, rtx));
+static rtx and_reg_cond                        PARAMS ((rtx, rtx, int));
 #endif
 #ifdef AUTO_INC_DEC
+static void attempt_auto_inc           PARAMS ((struct propagate_block_info *,
+                                                rtx, rtx, rtx, rtx, rtx));
 static void find_auto_inc              PARAMS ((struct propagate_block_info *,
                                                 rtx, rtx));
 static int try_pre_increment_1         PARAMS ((struct propagate_block_info *,
@@ -385,22 +424,42 @@ static void mark_used_regs                PARAMS ((struct propagate_block_info *,
 void dump_flow_info                    PARAMS ((FILE *));
 void debug_flow_info                   PARAMS ((void));
 static void dump_edge_info             PARAMS ((FILE *, edge, int));
+static void print_rtl_and_abort                PARAMS ((void));
 
 static void invalidate_mems_from_autoinc PARAMS ((struct propagate_block_info *,
                                                  rtx));
+static void invalidate_mems_from_set   PARAMS ((struct propagate_block_info *,
+                                                rtx));
 static void remove_fake_successors     PARAMS ((basic_block));
-static void flow_nodes_print   PARAMS ((const char *, const sbitmap, FILE *));
-static void flow_exits_print PARAMS ((const char *, const edge *, int, FILE *));
-static void flow_loops_cfg_dump                PARAMS ((const struct loops *, FILE *));
-static int flow_loop_nested_p          PARAMS ((struct loop *, struct loop *));
-static int flow_loop_exits_find                PARAMS ((const sbitmap, edge **));
+static void flow_nodes_print           PARAMS ((const char *, const sbitmap,
+                                                FILE *));
+static void flow_edge_list_print       PARAMS ((const char *, const edge *,
+                                                int, FILE *));
+static void flow_loops_cfg_dump                PARAMS ((const struct loops *,
+                                                FILE *));
+static int flow_loop_nested_p          PARAMS ((struct loop *,
+                                                struct loop *));
+static int flow_loop_entry_edges_find  PARAMS ((basic_block, const sbitmap,
+                                                edge **));
+static int flow_loop_exit_edges_find   PARAMS ((const sbitmap, edge **));
 static int flow_loop_nodes_find        PARAMS ((basic_block, basic_block, sbitmap));
-static int flow_depth_first_order_compute PARAMS ((int *));
-static basic_block flow_loop_pre_header_find PARAMS ((basic_block, const sbitmap *));
+static int flow_depth_first_order_compute PARAMS ((int *, int *));
+static void flow_dfs_compute_reverse_init
+  PARAMS ((depth_first_search_ds));
+static void flow_dfs_compute_reverse_add_bb
+  PARAMS ((depth_first_search_ds, basic_block));
+static basic_block flow_dfs_compute_reverse_execute
+  PARAMS ((depth_first_search_ds));
+static void flow_dfs_compute_reverse_finish
+  PARAMS ((depth_first_search_ds));
+static void flow_loop_pre_header_scan PARAMS ((struct loop *));
+static basic_block flow_loop_pre_header_find PARAMS ((basic_block,
+                                                     const sbitmap *));
 static void flow_loop_tree_node_add    PARAMS ((struct loop *, struct loop *));
 static void flow_loops_tree_build      PARAMS ((struct loops *));
 static int flow_loop_level_compute     PARAMS ((struct loop *, int));
 static int flow_loops_level_compute    PARAMS ((struct loops *));
+static void allocate_bb_life_data      PARAMS ((void));
 \f
 /* Find basic blocks of the current function.
    F is the first insn of the function and NREGS the number of register
@@ -421,7 +480,7 @@ find_basic_blocks (f, nregs, file)
 
       clear_edges ();
 
-      /* Clear bb->aux on all extant basic blocks.  We'll use this as a 
+      /* Clear bb->aux on all extant basic blocks.  We'll use this as a
         tag for reuse during create_basic_block, just in case some pass
         copies around basic block notes improperly.  */
       for (i = 0; i < n_basic_blocks; ++i)
@@ -436,14 +495,14 @@ find_basic_blocks (f, nregs, file)
      by find_basic_blocks_1, since we want to keep the structure pointers
      stable across calls to find_basic_blocks.  */
   /* ??? This whole issue would be much simpler if we called find_basic_blocks
-     exactly once, and thereafter we don't have a single long chain of 
+     exactly once, and thereafter we don't have a single long chain of
      instructions at all until close to the end of compilation when we
      actually lay them out.  */
 
   VARRAY_BB_INIT (basic_block_info, n_basic_blocks, "basic_block_info");
 
   find_basic_blocks_1 (f);
-  
+
   /* Record the block to which an insn belongs.  */
   /* ??? This should be done another way, by which (perhaps) a label is
      tagged directly with the basic block that it starts.  It is used for
@@ -473,9 +532,48 @@ find_basic_blocks (f, nregs, file)
 #endif
 }
 
+void
+check_function_return_warnings ()
+{
+  if (warn_missing_noreturn
+      && !TREE_THIS_VOLATILE (cfun->decl)
+      && EXIT_BLOCK_PTR->pred == NULL
+      && (lang_missing_noreturn_ok_p
+         && !lang_missing_noreturn_ok_p (cfun->decl)))
+    warning ("function might be possible candidate for attribute `noreturn'");
+
+  /* If we have a path to EXIT, then we do return.  */
+  if (TREE_THIS_VOLATILE (cfun->decl)
+      && EXIT_BLOCK_PTR->pred != NULL)
+    warning ("`noreturn' function does return");
+
+  /* If the clobber_return_insn appears in some basic block, then we
+     do reach the end without returning a value.  */
+  else if (warn_return_type
+          && cfun->x_clobber_return_insn != NULL
+          && EXIT_BLOCK_PTR->pred != NULL)
+    {
+      int max_uid = get_max_uid ();
+
+      /* If clobber_return_insn was excised by jump1, then renumber_insns
+        can make max_uid smaller than the number still recorded in our rtx.
+        That's fine, since this is a quick way of verifying that the insn
+        is no longer in the chain.  */
+      if (INSN_UID (cfun->x_clobber_return_insn) < max_uid)
+       {
+         /* Recompute insn->block mapping, since the initial mapping is
+            set before we delete unreachable blocks.  */
+         compute_bb_for_insn (max_uid);
+
+         if (BLOCK_FOR_INSN (cfun->x_clobber_return_insn) != NULL)
+           warning ("control reaches end of non-void function");
+       }
+    }
+}
+
 /* Count the basic blocks of the function.  */
 
-static int 
+static int
 count_basic_blocks (f)
      rtx f;
 {
@@ -535,28 +633,32 @@ count_basic_blocks (f)
   return count;
 }
 
-/* Scan a list of insns for labels referrred to other than by jumps.
+/* Scan a list of insns for labels referred to other than by jumps.
    This is used to scan the alternatives of a call placeholder.  */
-static rtx find_label_refs (f, lvl)
+static rtx
+find_label_refs (f, lvl)
      rtx f;
      rtx lvl;
 {
   rtx insn;
 
   for (insn = f; insn; insn = NEXT_INSN (insn))
-    if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
+    if (INSN_P (insn) && GET_CODE (insn) != JUMP_INSN)
       {
        rtx note;
 
        /* Make a list of all labels referred to other than by jumps
-          (which just don't have the REG_LABEL notes). 
+          (which just don't have the REG_LABEL notes).
 
           Make a special exception for labels followed by an ADDR*VEC,
-          as this would be a part of the tablejump setup code. 
+          as this would be a part of the tablejump setup code.
 
           Make a special exception for the eh_return_stub_label, which
-          we know isn't part of any otherwise visible control flow.  */
-            
+          we know isn't part of any otherwise visible control flow.
+
+          Make a special exception to registers loaded with label
+          values just before jump insns that use them.  */
+
        for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
          if (REG_NOTE_KIND (note) == REG_LABEL)
            {
@@ -571,6 +673,9 @@ static rtx find_label_refs (f, lvl)
                ;
              else if (GET_CODE (lab) == NOTE)
                ;
+             else if (GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
+                      && find_reg_note (NEXT_INSN (insn), REG_LABEL, lab))
+               ;
              else
                lvl = alloc_EXPR_LIST (0, XEXP (note, 0), lvl);
            }
@@ -596,7 +701,7 @@ find_basic_blocks_1 (f)
   rtx trll = NULL_RTX;
   rtx head = NULL_RTX;
   rtx end = NULL_RTX;
-  
+
   /* We process the instructions in a slightly different way than we did
      previously.  This is so that we see a NOTE_BASIC_BLOCK after we have
      closed out the previous block, so that it gets attached at the proper
@@ -626,7 +731,7 @@ find_basic_blocks_1 (f)
                free_INSN_LIST_node (t);
              }
 
-           /* Look for basic block notes with which to keep the 
+           /* Look for basic block notes with which to keep the
               basic_block_info pointers stable.  Unthread the note now;
               we'll put it back at the right place in create_basic_block.
               Or not at all if we've already found a note in this block.  */
@@ -641,7 +746,7 @@ find_basic_blocks_1 (f)
          }
 
        case CODE_LABEL:
-         /* A basic block starts at a label.  If we've closed one off due 
+         /* A basic block starts at a label.  If we've closed one off due
             to a barrier or some such, no need to do it again.  */
          if (head != NULL_RTX)
            {
@@ -669,14 +774,14 @@ find_basic_blocks_1 (f)
            head = insn;
          else
            {
-             /* ??? Make a special check for table jumps.  The way this 
+             /* ??? Make a special check for table jumps.  The way this
                 happens is truly and amazingly gross.  We are about to
                 create a basic block that contains just a code label and
                 an addr*vec jump insn.  Worse, an addr_diff_vec creates
                 its own natural loop.
 
                 Prevent this bit of brain damage, pasting things together
-                correctly in make_edges.  
+                correctly in make_edges.
 
                 The correct solution involves emitting the table directly
                 on the tablejump instruction as a note, or JUMP_LABEL.  */
@@ -753,8 +858,8 @@ find_basic_blocks_1 (f)
                bb_note = NULL_RTX;
                break;
              }
-           }
-         /* FALLTHRU */
+         }
+         /* Fall through.  */
 
        default:
          if (GET_RTX_CLASS (code) == 'i')
@@ -766,19 +871,22 @@ find_basic_blocks_1 (f)
          break;
        }
 
-      if (GET_RTX_CLASS (code) == 'i')
+      if (GET_RTX_CLASS (code) == 'i'
+         && GET_CODE (insn) != JUMP_INSN)
        {
          rtx note;
 
-         /* Make a list of all labels referred to other than by jumps
-            (which just don't have the REG_LABEL notes). 
+         /* Make a list of all labels referred to other than by jumps.
 
             Make a special exception for labels followed by an ADDR*VEC,
-            as this would be a part of the tablejump setup code. 
+            as this would be a part of the tablejump setup code.
 
             Make a special exception for the eh_return_stub_label, which
-            we know isn't part of any otherwise visible control flow.  */
-            
+            we know isn't part of any otherwise visible control flow.
+
+            Make a special exception to registers loaded with label
+            values just before jump insns that use them.  */
+
          for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
            if (REG_NOTE_KIND (note) == REG_LABEL)
              {
@@ -793,6 +901,9 @@ find_basic_blocks_1 (f)
                  ;
                else if (GET_CODE (lab) == NOTE)
                  ;
+               else if (GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
+                        && find_reg_note (NEXT_INSN (insn), REG_LABEL, lab))
+                 ;
                else
                  lvl = alloc_EXPR_LIST (0, XEXP (note, 0), lvl);
              }
@@ -866,7 +977,7 @@ create_basic_block (index, head, end, bb_note)
         the same lifetime by allocating it off the function obstack
         rather than using malloc.  */
 
-      bb = (basic_block) obstack_alloc (function_obstack, sizeof (*bb));
+      bb = (basic_block) obstack_alloc (&flow_obstack, sizeof (*bb));
       memset (bb, 0, sizeof (*bb));
 
       if (GET_CODE (head) == CODE_LABEL)
@@ -937,7 +1048,7 @@ clear_edges ()
     {
       basic_block bb = BASIC_BLOCK (i);
 
-      for (e = bb->succ; e ; e = n)
+      for (e = bb->succ; e; e = n)
        {
          n = e->succ_next;
          free (e);
@@ -947,7 +1058,7 @@ clear_edges ()
       bb->pred = 0;
     }
 
-  for (e = ENTRY_BLOCK_PTR->succ; e ; e = n)
+  for (e = ENTRY_BLOCK_PTR->succ; e; e = n)
     {
       n = e->succ_next;
       free (e);
@@ -964,7 +1075,7 @@ clear_edges ()
    NONLOCAL_LABEL_LIST is a list of non-local labels in the function.  Blocks
    that are otherwise unreachable may be reachable with a non-local goto.
 
-   BB_EH_END is an array indexed by basic block number in which we record 
+   BB_EH_END is an array indexed by basic block number in which we record
    the list of exception regions active at the end of the basic block.  */
 
 static void
@@ -1008,12 +1119,17 @@ make_edges (label_value_list)
        {
          rtx tmp;
 
+         /* Recognize a non-local goto as a branch outside the
+            current function.  */
+         if (find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX))
+           ;
+
          /* ??? Recognize a tablejump and do the right thing.  */
-         if ((tmp = JUMP_LABEL (insn)) != NULL_RTX
-             && (tmp = NEXT_INSN (tmp)) != NULL_RTX
-             && GET_CODE (tmp) == JUMP_INSN
-             && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
-                 || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
+         else if ((tmp = JUMP_LABEL (insn)) != NULL_RTX
+                  && (tmp = NEXT_INSN (tmp)) != NULL_RTX
+                  && GET_CODE (tmp) == JUMP_INSN
+                  && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
+                      || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
            {
              rtvec vec;
              int j;
@@ -1052,7 +1168,7 @@ make_edges (label_value_list)
 
              for (x = label_value_list; x; x = XEXP (x, 1))
                make_label_edge (edge_cache, bb, XEXP (x, 0), EDGE_ABNORMAL);
-             
+
              for (x = forced_labels; x; x = XEXP (x, 1))
                make_label_edge (edge_cache, bb, XEXP (x, 0), EDGE_ABNORMAL);
            }
@@ -1070,7 +1186,7 @@ make_edges (label_value_list)
            }
        }
 
-      /* If this is a sibling call insn, then this is in effect a 
+      /* If this is a sibling call insn, then this is in effect a
         combined call and return, and so we need an edge to the
         exit block.  No need to worry about EH edges, since we
         wouldn't have created the sibling call in the first place.  */
@@ -1078,7 +1194,6 @@ make_edges (label_value_list)
       if (code == CALL_INSN && SIBLING_CALL_P (insn))
        make_edge (edge_cache, bb, EXIT_BLOCK_PTR,
                   EDGE_ABNORMAL | EDGE_ABNORMAL_CALL);
-      else
 
       /* If this is a CALL_INSN, then mark it as reaching the active EH
         handler for this CALL_INSN.  If we're handling asynchronous
@@ -1086,7 +1201,7 @@ make_edges (label_value_list)
 
         Also mark the CALL_INSN as reaching any nonlocal goto handler.  */
 
-      if (code == CALL_INSN || asynchronous_exceptions)
+      else if (code == CALL_INSN || asynchronous_exceptions)
        {
          /* Add any appropriate EH edges.  We do this unconditionally
             since there may be a REG_EH_REGION or REG_EH_RETHROW note
@@ -1126,7 +1241,7 @@ make_edges (label_value_list)
                 than 0 is guaranteed not to perform a non-local goto.  */
              rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
              if (!note || INTVAL (XEXP (note, 0)) >=  0)
-               for (x = nonlocal_goto_handler_labels; x ; x = XEXP (x, 1))
+               for (x = nonlocal_goto_handler_labels; x; x = XEXP (x, 1))
                  make_label_edge (edge_cache, bb, XEXP (x, 0),
                                   EDGE_ABNORMAL | EDGE_ABNORMAL_CALL);
            }
@@ -1178,13 +1293,27 @@ make_edge (edge_cache, src, dst, flags)
                    && dst != EXIT_BLOCK_PTR);
 
   /* Make sure we don't add duplicate edges.  */
-  if (! use_edge_cache || TEST_BIT (edge_cache[src->index], dst->index))
-    for (e = src->succ; e ; e = e->succ_next)
-      if (e->dest == dst)
-       {
-         e->flags |= flags;
-         return;
-       }
+  switch (use_edge_cache)
+    {
+    default:
+      /* Quick test for non-existance of the edge.  */
+      if (! TEST_BIT (edge_cache[src->index], dst->index))
+       break;
+
+      /* The edge exists; early exit if no work to do.  */
+      if (flags == 0)
+       return;
+
+      /* FALLTHRU */
+    case 0:
+      for (e = src->succ; e; e = e->succ_next)
+       if (e->dest == dst)
+         {
+           e->flags |= flags;
+           return;
+         }
+      break;
+    }
 
   e = (edge) xcalloc (1, sizeof (*e));
   n_edges++;
@@ -1310,7 +1439,7 @@ record_active_eh_regions (f)
   int i = 0;
   basic_block bb = BASIC_BLOCK (0);
 
-  for (insn = f; insn ; insn = NEXT_INSN (insn))
+  for (insn = f; insn; insn = NEXT_INSN (insn))
     {
       if (bb->head == insn)
        bb->eh_beg = (eh_list ? NOTE_EH_HANDLER (XEXP (eh_list, 0)) : -1);
@@ -1360,7 +1489,7 @@ mark_critical_edges ()
       /* (1) Critical edges must have a source with multiple successors.  */
       if (bb->succ && bb->succ->succ_next)
        {
-         for (e = bb->succ; e ; e = e->succ_next)
+         for (e = bb->succ; e; e = e->succ_next)
            {
              /* (2) Critical edges must have a destination with multiple
                 predecessors.  Note that we know there is at least one
@@ -1373,7 +1502,7 @@ mark_critical_edges ()
        }
       else
        {
-         for (e = bb->succ; e ; e = e->succ_next)
+         for (e = bb->succ; e; e = e->succ_next)
            e->flags &= ~EDGE_CRITICAL;
        }
 
@@ -1383,11 +1512,104 @@ mark_critical_edges ()
     }
 }
 \f
+/* Split a block BB after insn INSN creating a new fallthru edge.
+   Return the new edge.  Note that to keep other parts of the compiler happy,
+   this function renumbers all the basic blocks so that the new
+   one has a number one greater than the block split.  */
+
+edge
+split_block (bb, insn)
+     basic_block bb;
+     rtx insn;
+{
+  basic_block new_bb;
+  edge new_edge;
+  edge e;
+  rtx bb_note;
+  int i, j;
+
+  /* There is no point splitting the block after its end.  */
+  if (bb->end == insn)
+    return 0;
+
+  /* Create the new structures.  */
+  new_bb = (basic_block) obstack_alloc (&flow_obstack, sizeof (*new_bb));
+  new_edge = (edge) xcalloc (1, sizeof (*new_edge));
+  n_edges++;
+
+  memset (new_bb, 0, sizeof (*new_bb));
+
+  new_bb->head = NEXT_INSN (insn);
+  new_bb->end = bb->end;
+  bb->end = insn;
+
+  new_bb->succ = bb->succ;
+  bb->succ = new_edge;
+  new_bb->pred = new_edge;
+  new_bb->count = bb->count;
+  new_bb->loop_depth = bb->loop_depth;
+
+  new_edge->src = bb;
+  new_edge->dest = new_bb;
+  new_edge->flags = EDGE_FALLTHRU;
+  new_edge->probability = REG_BR_PROB_BASE;
+  new_edge->count = bb->count;
+
+  /* Redirect the src of the successor edges of bb to point to new_bb.  */
+  for (e = new_bb->succ; e; e = e->succ_next)
+    e->src = new_bb;
+
+  /* Place the new block just after the block being split.  */
+  VARRAY_GROW (basic_block_info, ++n_basic_blocks);
+
+  /* Some parts of the compiler expect blocks to be number in
+     sequential order so insert the new block immediately after the
+     block being split..  */
+  j = bb->index;
+  for (i = n_basic_blocks - 1; i > j + 1; --i)
+    {
+      basic_block tmp = BASIC_BLOCK (i - 1);
+      BASIC_BLOCK (i) = tmp;
+      tmp->index = i;
+    }
+
+  BASIC_BLOCK (i) = new_bb;
+  new_bb->index = i;
+
+  /* Create the basic block note.  */
+  bb_note = emit_note_before (NOTE_INSN_BASIC_BLOCK,
+                             new_bb->head);
+  NOTE_BASIC_BLOCK (bb_note) = new_bb;
+  new_bb->head = bb_note;
+
+  update_bb_for_insn (new_bb);
+
+  if (bb->global_live_at_start)
+    {
+      new_bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+      new_bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+      COPY_REG_SET (new_bb->global_live_at_end, bb->global_live_at_end);
+
+      /* We now have to calculate which registers are live at the end
+        of the split basic block and at the start of the new basic
+        block.  Start with those registers that are known to be live
+        at the end of the original basic block and get
+        propagate_block to determine which registers are live.  */
+      COPY_REG_SET (new_bb->global_live_at_start, bb->global_live_at_end);
+      propagate_block (new_bb, new_bb->global_live_at_start, NULL, NULL, 0);
+      COPY_REG_SET (bb->global_live_at_end,
+                   new_bb->global_live_at_start);
+    }
+
+  return new_edge;
+}
+
+
 /* Split a (typically critical) edge.  Return the new block.
-   Abort on abnormal edges. 
+   Abort on abnormal edges.
 
    ??? The code generally expects to be called on critical edges.
-   The case of a block ending in an unconditional jump to a 
+   The case of a block ending in an unconditional jump to a
    block with multiple predecessors is not handled optimally.  */
 
 basic_block
@@ -1398,7 +1620,7 @@ split_edge (edge_in)
   edge edge_out;
   rtx bb_note;
   int i, j;
+
   /* Abnormal edges cannot be split.  */
   if ((edge_in->flags & EDGE_ABNORMAL) != 0)
     abort ();
@@ -1416,7 +1638,7 @@ split_edge (edge_in)
   }
 
   /* Create the new structures.  */
-  bb = (basic_block) obstack_alloc (function_obstack, sizeof (*bb));
+  bb = (basic_block) obstack_alloc (&flow_obstack, sizeof (*bb));
   edge_out = (edge) xcalloc (1, sizeof (*edge_out));
   n_edges++;
 
@@ -1425,8 +1647,8 @@ split_edge (edge_in)
   /* ??? This info is likely going to be out of date very soon.  */
   if (old_succ->global_live_at_start)
     {
-      bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (function_obstack);
-      bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (function_obstack);
+      bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+      bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (&flow_obstack);
       COPY_REG_SET (bb->global_live_at_start, old_succ->global_live_at_start);
       COPY_REG_SET (bb->global_live_at_end, old_succ->global_live_at_start);
     }
@@ -1451,7 +1673,7 @@ split_edge (edge_in)
 
   /* Tricky case -- if there existed a fallthru into the successor
      (and we're not it) we must add a new unconditional jump around
-     the new block we're actually interested in. 
+     the new block we're actually interested in.
 
      Further, if that edge is critical, this means a second new basic
      block must be created to hold it.  In order to simplify correct
@@ -1460,7 +1682,7 @@ split_edge (edge_in)
   if ((edge_in->flags & EDGE_FALLTHRU) == 0)
     {
       edge e;
-      for (e = edge_out->pred_next; e ; e = e->pred_next)
+      for (e = edge_out->pred_next; e; e = e->pred_next)
        if (e->flags & EDGE_FALLTHRU)
          break;
 
@@ -1496,7 +1718,7 @@ split_edge (edge_in)
          /* ... let jump know that label is in use, ...  */
          JUMP_LABEL (pos) = old_succ->head;
          ++LABEL_NUSES (old_succ->head);
-         
+
          /* ... and clear fallthru on the outgoing edge.  */
          e->flags &= ~EDGE_FALLTHRU;
 
@@ -1519,11 +1741,10 @@ split_edge (edge_in)
   BASIC_BLOCK (i) = bb;
   bb->index = i;
 
-  /* Create the basic block note. 
+  /* Create the basic block note.
 
      Where we place the note can have a noticable impact on the generated
-     code.  Consider this cfg: 
-       
+     code.  Consider this cfg:
 
                        E
                        |
@@ -1579,7 +1800,7 @@ split_edge (edge_in)
          for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
            if (XEXP (RTVEC_ELT (vec, j), 0) == old_label)
              {
-               RTVEC_ELT (vec, j) = gen_rtx_LABEL_REF (VOIDmode, new_label);
+               RTVEC_ELT (vec, j) = gen_rtx_LABEL_REF (VOIDmode, new_label);
                --LABEL_NUSES (old_label);
                ++LABEL_NUSES (new_label);
              }
@@ -1591,7 +1812,7 @@ split_edge (edge_in)
              && GET_CODE (XEXP (SET_SRC (tmp), 2)) == LABEL_REF
              && XEXP (XEXP (SET_SRC (tmp), 2), 0) == old_label)
            {
-             XEXP (SET_SRC (tmp), 2) = gen_rtx_LABEL_REF (VOIDmode, 
+             XEXP (SET_SRC (tmp), 2) = gen_rtx_LABEL_REF (VOIDmode,
                                                           new_label);
              --LABEL_NUSES (old_label);
              ++LABEL_NUSES (new_label);
@@ -1644,7 +1865,7 @@ insert_insn_on_edge (pattern, e)
   emit_insn (pattern);
 
   e->insns = get_insns ();
-  end_sequence();
+  end_sequence ();
 }
 
 /* Update the CFG for the instructions queued on edge E.  */
@@ -1672,15 +1893,14 @@ commit_one_edge_insertion (e)
       tmp = bb->head;
       if (GET_CODE (tmp) == CODE_LABEL)
        tmp = NEXT_INSN (tmp);
-      if (GET_CODE (tmp) == NOTE
-         && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BASIC_BLOCK)
+      if (NOTE_INSN_BASIC_BLOCK_P (tmp))
        tmp = NEXT_INSN (tmp);
       if (tmp == bb->head)
        before = tmp;
       else
        after = PREV_INSN (tmp);
     }
-  
+
   /* If the source has one successor and the edge is not abnormal,
      insert there.  Except for the entry block.  */
   else if ((e->flags & EDGE_ABNORMAL) == 0
@@ -1690,7 +1910,7 @@ commit_one_edge_insertion (e)
       bb = e->src;
       /* It is possible to have a non-simple jump here.  Consider a target
         where some forms of unconditional jumps clobber a register.  This
-        happens on the fr30 for example. 
+        happens on the fr30 for example.
 
         We know this block has a single successor, so we can just emit
         the queued insns before the jump.  */
@@ -1742,7 +1962,7 @@ commit_one_edge_insertion (e)
 
   if (returnjump_p (last))
     {
-      /* ??? Remove all outgoing edges from BB and add one for EXIT. 
+      /* ??? Remove all outgoing edges from BB and add one for EXIT.
          This is not currently a problem because this only happens
         for the (single) epilogue, which already has a fallthru edge
         to EXIT.  */
@@ -1775,14 +1995,14 @@ commit_edge_insertions ()
 #ifdef ENABLE_CHECKING
   verify_flow_info ();
 #endif
+
   i = -1;
   bb = ENTRY_BLOCK_PTR;
   while (1)
     {
       edge e, next;
 
-      for (e = bb->succ; e ; e = next)
+      for (e = bb->succ; e; e = next)
        {
          next = e->succ_next;
          if (e->insns)
@@ -1794,6 +2014,75 @@ commit_edge_insertions ()
       bb = BASIC_BLOCK (i);
     }
 }
+
+/* Add fake edges to the function exit for any non constant calls in
+   the bitmap of blocks specified by BLOCKS or to the whole CFG if
+   BLOCKS is zero.  Return the nuber of blocks that were split.  */
+
+int
+flow_call_edges_add (blocks)
+     sbitmap blocks;
+{
+  int i;
+  int blocks_split = 0;
+  int bb_num = 0;
+  basic_block *bbs;
+
+  /* Map bb indicies into basic block pointers since split_block
+     will renumber the basic blocks.  */
+
+  bbs = xmalloc (n_basic_blocks * sizeof (*bbs));
+
+  if (! blocks)
+    {
+      for (i = 0; i < n_basic_blocks; i++)
+       bbs[bb_num++] = BASIC_BLOCK (i);
+    }
+  else
+    {
+      EXECUTE_IF_SET_IN_SBITMAP (blocks, 0, i, 
+      {
+       bbs[bb_num++] = BASIC_BLOCK (i);
+      });
+    }
+
+
+  /* Now add fake edges to the function exit for any non constant
+     calls since there is no way that we can determine if they will
+     return or not...  */
+
+  for (i = 0; i < bb_num; i++)
+    {
+      basic_block bb = bbs[i];
+      rtx insn;
+      rtx prev_insn;
+
+      for (insn = bb->end; ; insn = prev_insn)
+       {
+         prev_insn = PREV_INSN (insn);
+         if (GET_CODE (insn) == CALL_INSN && ! CONST_CALL_P (insn))
+           {
+             edge e;
+
+             /* Note that the following may create a new basic block
+                and renumber the existing basic blocks.  */
+             e = split_block (bb, insn);
+             if (e)
+               blocks_split++;
+
+             make_edge (NULL, bb, EXIT_BLOCK_PTR, EDGE_FAKE);
+           }
+         if (insn == bb->head)
+           break;
+       }
+    }
+
+  if (blocks_split)
+    verify_flow_info ();
+
+  free (bbs);
+  return blocks_split;
+}
 \f
 /* Delete all unreachable basic blocks.   */
 
@@ -1817,21 +2106,21 @@ delete_unreachable_blocks ()
      be only one.  It isn't inconcievable that we might one day directly
      support Fortran alternate entry points.  */
 
-  for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
+  for (e = ENTRY_BLOCK_PTR->succ; e; e = e->succ_next)
     {
       *tos++ = e->dest;
 
       /* Mark the block with a handy non-null value.  */
       e->dest->aux = e;
     }
-      
+
   /* Iterate: find everything reachable from what we've already seen.  */
 
   while (tos != worklist)
     {
       basic_block b = *--tos;
 
-      for (e = b->succ; e ; e = e->succ_next)
+      for (e = b->succ; e; e = e->succ_next)
        if (!e->dest->aux)
          {
            *tos++ = e->dest;
@@ -1840,7 +2129,7 @@ delete_unreachable_blocks ()
     }
 
   /* Delete all unreachable basic blocks.  Count down so that we don't
-     interfere with the block renumbering that happens in flow_delete_block. */
+     interfere with the block renumbering that happens in flow_delete_block.  */
 
   deleted_handler = 0;
 
@@ -1858,7 +2147,7 @@ delete_unreachable_blocks ()
   tidy_fallthru_edges ();
 
   /* If we deleted an exception handler, we may have EH region begin/end
-     blocks to remove as well. */
+     blocks to remove as well.  */
   if (deleted_handler)
     delete_eh_regions ();
 
@@ -1877,8 +2166,8 @@ delete_eh_regions ()
   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
     if (GET_CODE (insn) == NOTE)
       {
-       if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG) ||
-           (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)) 
+       if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
+           || (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END))
          {
            int num = NOTE_EH_HANDLER (insn);
            /* A NULL handler indicates a region is no longer needed,
@@ -1961,7 +2250,7 @@ flow_delete_block (b)
      NOTE_INSN_EH_REGION_END notes.  */
 
   insn = b->head;
-  
+
   never_reached_warning (insn);
 
   if (GET_CODE (insn) == CODE_LABEL)
@@ -2004,12 +2293,12 @@ flow_delete_block (b)
   /* Selectively delete the entire chain.  */
   flow_delete_insn_chain (insn, end);
 
-  /* Remove the edges into and out of this block.  Note that there may 
+  /* Remove the edges into and out of this block.  Note that there may
      indeed be edges in, if we are removing an unreachable loop.  */
   {
     edge e, next, *q;
 
-    for (e = b->pred; e ; e = next)
+    for (e = b->pred; e; e = next)
       {
        for (q = &e->src->succ; *q != e; q = &(*q)->succ_next)
          continue;
@@ -2018,7 +2307,7 @@ flow_delete_block (b)
        n_edges--;
        free (e);
       }
-    for (e = b->succ; e ; e = next)
+    for (e = b->succ; e; e = next)
       {
        for (q = &e->dest->pred; *q != e; q = &(*q)->pred_next)
          continue;
@@ -2070,7 +2359,7 @@ flow_delete_insn (insn)
   PREV_INSN (insn) = NULL_RTX;
   NEXT_INSN (insn) = NULL_RTX;
   INSN_DELETED_P (insn) = 1;
-  
+
   if (prev)
     NEXT_INSN (prev) = next;
   if (next)
@@ -2098,7 +2387,7 @@ flow_delete_insn (insn)
 
 /* True if a given label can be deleted.  */
 
-static int 
+static int
 can_delete_label_p (label)
      rtx label;
 {
@@ -2107,20 +2396,20 @@ can_delete_label_p (label)
   if (LABEL_PRESERVE_P (label))
     return 0;
 
-  for (x = forced_labels; x ; x = XEXP (x, 1))
+  for (x = forced_labels; x; x = XEXP (x, 1))
     if (label == XEXP (x, 0))
       return 0;
-  for (x = label_value_list; x ; x = XEXP (x, 1))
+  for (x = label_value_list; x; x = XEXP (x, 1))
     if (label == XEXP (x, 0))
       return 0;
-  for (x = exception_handler_labels; x ; x = XEXP (x, 1))
+  for (x = exception_handler_labels; x; x = XEXP (x, 1))
     if (label == XEXP (x, 0))
       return 0;
 
   /* User declared labels must be preserved.  */
   if (LABEL_NAME (label) != 0)
     return 0;
-  
+
   return 1;
 }
 
@@ -2130,7 +2419,7 @@ tail_recursion_label_p (label)
 {
   rtx x;
 
-  for (x = tail_recursion_label_list; x ; x = XEXP (x, 1))
+  for (x = tail_recursion_label_list; x; x = XEXP (x, 1))
     if (label == XEXP (x, 0))
       return 1;
 
@@ -2163,8 +2452,7 @@ merge_blocks_nomove (a, b)
     }
 
   /* Delete the basic block note.  */
-  if (GET_CODE (b_head) == NOTE 
-      && NOTE_LINE_NUMBER (b_head) == NOTE_INSN_BASIC_BLOCK)
+  if (NOTE_INSN_BASIC_BLOCK_P (b_head))
     {
       if (b_head == b_end)
        b_empty = 1;
@@ -2180,9 +2468,11 @@ merge_blocks_nomove (a, b)
     {
       rtx prev;
 
-      prev = prev_nonnote_insn (a_end);
-      if (!prev) 
-       prev = a->head;
+      for (prev = PREV_INSN (a_end); ; prev = PREV_INSN (prev))
+       if (GET_CODE (prev) != NOTE
+           || NOTE_LINE_NUMBER (prev) == NOTE_INSN_BASIC_BLOCK
+           || prev == a->head)
+         break;
 
       del_first = a_end;
 
@@ -2191,7 +2481,7 @@ merge_blocks_nomove (a, b)
         the insn that set cc0.  */
       if (prev && sets_cc0_p (prev))
        {
-          rtx tmp = prev;
+         rtx tmp = prev;
          prev = prev_nonnote_insn (prev);
          if (!prev)
            prev = a->head;
@@ -2216,7 +2506,7 @@ merge_blocks_nomove (a, b)
     remove_edge (a->succ);
 
   /* Adjust the edges out of B for the new owner.  */
-  for (e = b->succ; e ; e = e->succ_next)
+  for (e = b->succ; e; e = e->succ_next)
     e->src = a;
   a->succ = b->succ;
 
@@ -2283,12 +2573,12 @@ merge_blocks_move_predecessor_nojumps (a, b)
   /* Swap the records for the two blocks around.  Although we are deleting B,
      A is now where B was and we want to compact the BB array from where
      A used to be.  */
-  BASIC_BLOCK(a->index) = b;
-  BASIC_BLOCK(b->index) = a;
+  BASIC_BLOCK (a->index) = b;
+  BASIC_BLOCK (b->index) = a;
   index = a->index;
   a->index = b->index;
   b->index = index;
-  
+
   /* Now blocks A and B are contiguous.  Merge them.  */
   merge_blocks_nomove (a, b);
 
@@ -2349,7 +2639,7 @@ merge_blocks_move_successor_nojumps (a, b)
   return 1;
 }
 
-/* Attempt to merge basic blocks that are potentially non-adjacent.  
+/* Attempt to merge basic blocks that are potentially non-adjacent.
    Return true iff the attempt succeeded.  */
 
 static int
@@ -2387,24 +2677,24 @@ merge_blocks (e, b, c)
 
       /* We must make sure to not munge nesting of exception regions,
         lexical blocks, and loop notes.
-  
+
         The first is taken care of by requiring that the active eh
         region at the end of one block always matches the active eh
         region at the beginning of the next block.
-  
+
         The later two are taken care of by squeezing out all the notes.  */
-  
+
       /* ???  A throw/catch edge (or any abnormal edge) should be rarely
         executed and we may want to treat blocks which have two out
         edges, one normal, one abnormal as only having one edge for
         block merging purposes.  */
 
-      for (tmp_edge = c->succ; tmp_edge ; tmp_edge = tmp_edge->succ_next)
+      for (tmp_edge = c->succ; tmp_edge; tmp_edge = tmp_edge->succ_next)
        if (tmp_edge->flags & EDGE_FALLTHRU)
          break;
       c_has_outgoing_fallthru = (tmp_edge != NULL);
 
-      for (tmp_edge = b->pred; tmp_edge ; tmp_edge = tmp_edge->pred_next)
+      for (tmp_edge = b->pred; tmp_edge; tmp_edge = tmp_edge->pred_next)
        if (tmp_edge->flags & EDGE_FALLTHRU)
          break;
       b_has_incoming_fallthru = (tmp_edge != NULL);
@@ -2453,10 +2743,10 @@ try_merge_blocks ()
   int i;
 
   /* Attempt to merge blocks as made possible by edge removal.  If a block
-     has only one successor, and the successor has only one predecessor, 
+     has only one successor, and the successor has only one predecessor,
      they may be combined.  */
 
-  for (i = 0; i < n_basic_blocks; )
+  for (i = 0; i < n_basic_blocks;)
     {
       basic_block c, b = BASIC_BLOCK (i);
       edge s;
@@ -2524,7 +2814,16 @@ tidy_fallthru_edge (e, b, c)
          NOTE_SOURCE_FILE (q) = 0;
        }
       else
-       b->end = q = PREV_INSN (q);
+       {
+         q = PREV_INSN (q);
+
+         /* We don't want a block to end on a line-number note since that has
+            the potential of changing the code between -g and not -g.  */
+         while (GET_CODE (q) == NOTE && NOTE_LINE_NUMBER (q) >= 0)
+           q = PREV_INSN (q);
+       }
+
+      b->end = q;
     }
 
   /* Selectively unlink the sequence.  */
@@ -2592,21 +2891,21 @@ life_analysis (f, file, flags)
   CLEAR_HARD_REG_SET (elim_reg_set);
 
 #ifdef ELIMINABLE_REGS
-  for (i = 0; i < (int) (sizeof eliminables / sizeof eliminables[0]); i++)
+  for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
     SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
 #else
   SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
 #endif
 
   if (! optimize)
-    flags &= PROP_DEATH_NOTES | PROP_REG_INFO;
+    flags &= ~(PROP_LOG_LINKS | PROP_AUTOINC);
 
   /* The post-reload life analysis have (on a global basis) the same
      registers live as was computed by reload itself.  elimination
      Otherwise offsets and such may be incorrect.
 
      Reload will make some registers as live even though they do not
-     appear in the rtl.  
+     appear in the rtl.
 
      We don't want to create new auto-incs after reload, since they
      are unlikely to be useful and can cause problems with shared
@@ -2615,7 +2914,7 @@ life_analysis (f, file, flags)
     flags &= ~(PROP_REG_INFO | PROP_AUTOINC);
 
   /* We want alias analysis information for local dead store elimination.  */
-  if (flags & PROP_SCAN_DEAD_CODE)
+  if (optimize && (flags & PROP_SCAN_DEAD_CODE))
     init_alias_analysis ();
 
   /* Always remove no-op moves.  Do this before other processing so
@@ -2627,7 +2926,7 @@ life_analysis (f, file, flags)
      we've already emitted the epilogue so there's no sense searching.  */
   if (! reload_completed)
     notice_stack_pointer_modification (f);
-    
+
   /* Allocate and zero out data structures that will record the
      data from lifetime analysis.  */
   allocate_reg_life_data ();
@@ -2641,11 +2940,11 @@ life_analysis (f, file, flags)
      is not immediately handy.  */
 
   if (flags & PROP_REG_INFO)
-    memset (regs_ever_live, 0, sizeof(regs_ever_live));
+    memset (regs_ever_live, 0, sizeof (regs_ever_live));
   update_life_info (NULL, UPDATE_LIFE_GLOBAL, flags);
 
   /* Clean up.  */
-  if (flags & PROP_SCAN_DEAD_CODE)
+  if (optimize && (flags & PROP_SCAN_DEAD_CODE))
     end_alias_analysis ();
 
   if (file)
@@ -2684,7 +2983,7 @@ verify_wide_reg (regno, head, end)
 {
   while (1)
     {
-      if (GET_RTX_CLASS (GET_CODE (head)) == 'i'
+      if (INSN_P (head)
          && for_each_rtx (&PATTERN (head), verify_wide_reg_1, &regno))
        return;
       if (head == end)
@@ -2693,7 +2992,9 @@ verify_wide_reg (regno, head, end)
     }
 
   /* We didn't find the register at all.  Something's way screwy.  */
-  abort ();
+  if (rtl_dump_file)
+    fprintf (rtl_dump_file, "Aborting in verify_wide_reg; reg %d\n", regno);
+  print_rtl_and_abort ();
 }
 
 /* A subroutine of update_life_info.  Verify that there are no untoward
@@ -2709,7 +3010,17 @@ verify_local_live_at_start (new_live_at_start, bb)
       /* After reload, there are no pseudos, nor subregs of multi-word
         registers.  The regsets should exactly match.  */
       if (! REG_SET_EQUAL_P (new_live_at_start, bb->global_live_at_start))
-        abort ();
+       {
+         if (rtl_dump_file)
+           {
+             fprintf (rtl_dump_file,
+                      "live_at_start mismatch in bb %d, aborting\n",
+                      bb->index);
+             debug_bitmap_file (rtl_dump_file, bb->global_live_at_start);
+             debug_bitmap_file (rtl_dump_file, new_live_at_start);
+           }
+         print_rtl_and_abort ();
+       }
     }
   else
     {
@@ -2722,7 +3033,14 @@ verify_local_live_at_start (new_live_at_start, bb)
        {
           /* No registers should die.  */
          if (REGNO_REG_SET_P (bb->global_live_at_start, i))
-           abort ();
+           {
+             if (rtl_dump_file)
+               fprintf (rtl_dump_file,
+                        "Register %d died unexpectedly in block %d\n", i,
+                        bb->index);
+             print_rtl_and_abort ();
+           }
+
           /* Verify that the now-live register is wider than word_mode.  */
          verify_wide_reg (i, bb->head, bb->end);
        });
@@ -2731,7 +3049,7 @@ verify_local_live_at_start (new_live_at_start, bb)
 
 /* Updates life information starting with the basic blocks set in BLOCKS.
    If BLOCKS is null, consider it to be the universal set.
-   
+
    If EXTENT is UPDATE_LIFE_LOCAL, such as after splitting or peepholeing,
    we are only expecting local modifications to basic blocks.  If we find
    extra registers live at the beginning of a block, then we either killed
@@ -2776,7 +3094,7 @@ update_life_info (blocks, extent, prop_flags)
          basic_block bb = BASIC_BLOCK (i);
 
          COPY_REG_SET (tmp, bb->global_live_at_end);
-         propagate_block (bb, tmp, (regset) NULL, prop_flags);
+         propagate_block (bb, tmp, NULL, NULL, prop_flags);
 
          if (extent == UPDATE_LIFE_LOCAL)
            verify_local_live_at_start (tmp, bb);
@@ -2789,7 +3107,7 @@ update_life_info (blocks, extent, prop_flags)
          basic_block bb = BASIC_BLOCK (i);
 
          COPY_REG_SET (tmp, bb->global_live_at_end);
-         propagate_block (bb, tmp, (regset) NULL, prop_flags);
+         propagate_block (bb, tmp, NULL, NULL, prop_flags);
 
          if (extent == UPDATE_LIFE_LOCAL)
            verify_local_live_at_start (tmp, bb);
@@ -2808,7 +3126,7 @@ update_life_info (blocks, extent, prop_flags)
                                 FIRST_PSEUDO_REGISTER, i,
                                 { REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL; });
 
-      /* We have a problem with any pseudoreg that lives across the setjmp. 
+      /* We have a problem with any pseudoreg that lives across the setjmp.
         ANSI says that if a user variable does not change in value between
         the setjmp and the longjmp, then the longjmp preserves it.  This
         includes longjmp from a place where the pseudo appears dead.
@@ -2856,6 +3174,7 @@ free_basic_block_vars (keep_head_end_p)
 }
 
 /* Return nonzero if the destination of SET equals the source.  */
+
 static int
 set_noop_p (set)
      rtx set;
@@ -2877,6 +3196,7 @@ set_noop_p (set)
 
 /* Return nonzero if an insn consists only of SETs, each of which only sets a
    value to itself.  */
+
 static int
 noop_move_p (insn)
      rtx insn;
@@ -2944,10 +3264,7 @@ notice_stack_pointer_modification_1 (x, pat, data)
         of a push until later in flow.  See the comments in rtl.texi
         regarding Embedded Side-Effects on Addresses.  */
       || (GET_CODE (x) == MEM
-         && (GET_CODE (XEXP (x, 0)) == PRE_DEC
-             || GET_CODE (XEXP (x, 0)) == PRE_INC
-             || GET_CODE (XEXP (x, 0)) == POST_DEC
-             || GET_CODE (XEXP (x, 0)) == POST_INC)
+         && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == 'a'
          && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
     current_function_sp_is_unchanging = 0;
 }
@@ -2966,7 +3283,7 @@ notice_stack_pointer_modification (f)
 
   for (insn = f; insn; insn = NEXT_INSN (insn))
     {
-      if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
+      if (INSN_P (insn))
        {
          /* Check if insn modifies the stack pointer.  */
          note_stores (PATTERN (insn), notice_stack_pointer_modification_1,
@@ -2979,6 +3296,7 @@ notice_stack_pointer_modification (f)
 
 /* Mark a register in SET.  Hard registers in large modes get all
    of their component registers set as well.  */
+
 static void
 mark_reg (reg, xset)
      rtx reg;
@@ -3001,6 +3319,7 @@ mark_reg (reg, xset)
 
 /* Mark those regs which are needed at the end of the function as live
    at the end of the last basic block.  */
+
 static void
 mark_regs_live_at_end (set)
      regset set;
@@ -3027,37 +3346,33 @@ mark_regs_live_at_end (set)
     {
       SET_REGNO_REG_SET (set, FRAME_POINTER_REGNUM);
 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
-      /* If they are different, also mark the hard frame pointer as live */
-      SET_REGNO_REG_SET (set, HARD_FRAME_POINTER_REGNUM);
-#endif      
+      /* If they are different, also mark the hard frame pointer as live.  */
+      if (! LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
+        SET_REGNO_REG_SET (set, HARD_FRAME_POINTER_REGNUM);
+#endif
     }
 
-#ifdef PIC_OFFSET_TABLE_REGNUM
 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
   /* Many architectures have a GP register even without flag_pic.
      Assume the pic register is not in use, or will be handled by
      other means, if it is not fixed.  */
-  if (fixed_regs[PIC_OFFSET_TABLE_REGNUM])
+  if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
+      && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
     SET_REGNO_REG_SET (set, PIC_OFFSET_TABLE_REGNUM);
 #endif
-#endif
 
   /* Mark all global registers, and all registers used by the epilogue
      as being live at the end of the function since they may be
      referenced by our caller.  */
   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-    if (global_regs[i]
-#ifdef EPILOGUE_USES
-       || EPILOGUE_USES (i)
-#endif
-       )
+    if (global_regs[i] || EPILOGUE_USES (i))
       SET_REGNO_REG_SET (set, i);
 
   /* Mark all call-saved registers that we actaully used.  */
   if (HAVE_epilogue && reload_completed)
     {
       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-       if (! call_used_regs[i] && regs_ever_live[i])
+       if (regs_ever_live[i] && ! call_used_regs[i] && ! LOCAL_REGNO (i))
          SET_REGNO_REG_SET (set, i);
     }
 
@@ -3082,7 +3397,7 @@ set_phi_alternative_reg (insn, dest_regno, src_regno, data)
 }
 
 /* Propagate global life info around the graph of basic blocks.  Begin
-   considering blocks with their corresponding bit set in BLOCKS_IN. 
+   considering blocks with their corresponding bit set in BLOCKS_IN.
    If BLOCKS_IN is null, consider it the universal set.
 
    BLOCKS_OUT is set for every block that was changed.  */
@@ -3102,21 +3417,21 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
   new_live_at_end = INITIALIZE_REG_SET (new_live_at_end_head);
 
   /* Create a worklist.  Allocate an extra slot for ENTRY_BLOCK, and one
-     because the `head == tail' style test for an empty queue doesn't 
+     because the `head == tail' style test for an empty queue doesn't
      work with a full queue.  */
   queue = (basic_block *) xmalloc ((n_basic_blocks + 2) * sizeof (*queue));
   qtail = queue;
   qhead = qend = queue + n_basic_blocks + 2;
 
-  /* Clear out the garbage that might be hanging out in bb->aux.  */
-  for (i = n_basic_blocks - 1; i >= 0; --i)
-    BASIC_BLOCK (i)->aux = NULL;
-
   /* Queue the blocks set in the initial mask.  Do this in reverse block
-     number order so that we are more likely for the first round to do 
+     number order so that we are more likely for the first round to do
      useful work.  We use AUX non-null to flag that the block is queued.  */
   if (blocks_in)
     {
+      /* Clear out the garbage that might be hanging out in bb->aux.  */
+      for (i = n_basic_blocks - 1; i >= 0; --i)
+       BASIC_BLOCK (i)->aux = NULL;
+
       EXECUTE_IF_SET_IN_SBITMAP (blocks_in, 0, i,
        {
          basic_block bb = BASIC_BLOCK (i);
@@ -3150,22 +3465,44 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
 
       /* Begin by propogating live_at_start from the successor blocks.  */
       CLEAR_REG_SET (new_live_at_end);
-      for (e = bb->succ; e ; e = e->succ_next)
+      for (e = bb->succ; e; e = e->succ_next)
        {
          basic_block sb = e->dest;
          IOR_REG_SET (new_live_at_end, sb->global_live_at_start);
        }
 
-      /* Force the stack pointer to be live -- which might not already be 
-        the case for blocks within infinite loops.  */
+      /* The all-important stack pointer must always be live.  */
       SET_REGNO_REG_SET (new_live_at_end, STACK_POINTER_REGNUM);
 
+      /* Before reload, there are a few registers that must be forced
+        live everywhere -- which might not already be the case for
+        blocks within infinite loops.  */
+      if (! reload_completed)
+       {
+         /* Any reference to any pseudo before reload is a potential
+            reference of the frame pointer.  */
+         SET_REGNO_REG_SET (new_live_at_end, FRAME_POINTER_REGNUM);
+
+#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
+         /* Pseudos with argument area equivalences may require
+            reloading via the argument pointer.  */
+         if (fixed_regs[ARG_POINTER_REGNUM])
+           SET_REGNO_REG_SET (new_live_at_end, ARG_POINTER_REGNUM);
+#endif
+
+         /* Any constant, or pseudo with constant equivalences, may
+            require reloading from memory using the pic register.  */
+         if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
+             && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
+           SET_REGNO_REG_SET (new_live_at_end, PIC_OFFSET_TABLE_REGNUM);
+       }
+
       /* Regs used in phi nodes are not included in
         global_live_at_start, since they are live only along a
         particular edge.  Set those regs that are live because of a
         phi node alternative corresponding to this particular block.  */
       if (in_ssa_form)
-       for_each_successor_phi (bb, &set_phi_alternative_reg, 
+       for_each_successor_phi (bb, &set_phi_alternative_reg,
                                new_live_at_end);
 
       if (bb == ENTRY_BLOCK_PTR)
@@ -3174,13 +3511,14 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
          continue;
        }
 
-      /* On our first pass through this block, we'll go ahead and continue. 
+      /* On our first pass through this block, we'll go ahead and continue.
         Recognize first pass by local_set NULL.  On subsequent passes, we
         get to skip out early if live_at_end wouldn't have changed.  */
 
       if (bb->local_set == NULL)
        {
-         bb->local_set = OBSTACK_ALLOC_REG_SET (function_obstack);
+         bb->local_set = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+         bb->cond_local_set = OBSTACK_ALLOC_REG_SET (&flow_obstack);
          rescan = 1;
        }
       else
@@ -3188,13 +3526,27 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
          /* If any bits were removed from live_at_end, we'll have to
             rescan the block.  This wouldn't be necessary if we had
             precalculated local_live, however with PROP_SCAN_DEAD_CODE
-            local_live is really dependant on live_at_end.  */
+            local_live is really dependent on live_at_end.  */
          CLEAR_REG_SET (tmp);
          rescan = bitmap_operation (tmp, bb->global_live_at_end,
                                     new_live_at_end, BITMAP_AND_COMPL);
 
          if (! rescan)
            {
+             /* If any of the registers in the new live_at_end set are
+                conditionally set in this basic block, we must rescan.
+                This is because conditional lifetimes at the end of the
+                block do not just take the live_at_end set into account,
+                but also the liveness at the start of each successor
+                block.  We can miss changes in those sets if we only
+                compare the new live_at_end against the previous one.  */
+             CLEAR_REG_SET (tmp);
+             rescan = bitmap_operation (tmp, new_live_at_end,
+                                        bb->cond_local_set, BITMAP_AND);
+           }
+
+         if (! rescan)
+           {
              /* Find the set of changed bits.  Take this opportunity
                 to notice that this set is empty and early out.  */
              CLEAR_REG_SET (tmp);
@@ -3237,7 +3589,8 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
 
          /* Rescan the block insn by insn to turn (a copy of) live_at_end
             into live_at_start.  */
-         propagate_block (bb, new_live_at_end, bb->local_set, flags);
+         propagate_block (bb, new_live_at_end, bb->local_set,
+                          bb->cond_local_set, flags);
 
          /* If live_at start didn't change, no need to go farther.  */
          if (REG_SET_EQUAL_P (bb->global_live_at_start, new_live_at_end))
@@ -3248,7 +3601,7 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
 
       /* Queue all predecessors of BB so that we may re-examine
         their live_at_end.  */
-      for (e = bb->pred; e ; e = e->pred_next)
+      for (e = bb->pred; e; e = e->pred_next)
        {
          basic_block pb = e->src;
          if (pb->aux == NULL)
@@ -3270,6 +3623,7 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
        {
          basic_block bb = BASIC_BLOCK (i);
          FREE_REG_SET (bb->local_set);
+         FREE_REG_SET (bb->cond_local_set);
        });
     }
   else
@@ -3278,6 +3632,7 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
        {
          basic_block bb = BASIC_BLOCK (i);
          FREE_REG_SET (bb->local_set);
+         FREE_REG_SET (bb->cond_local_set);
        }
     }
 
@@ -3289,7 +3644,7 @@ calculate_global_regs_live (blocks_in, blocks_out, flags)
 /* Allocate the permanent data structures that represent the results
    of life analysis.  Not static since used also for stupid life analysis.  */
 
-void
+static void
 allocate_bb_life_data ()
 {
   register int i;
@@ -3298,16 +3653,16 @@ allocate_bb_life_data ()
     {
       basic_block bb = BASIC_BLOCK (i);
 
-      bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (function_obstack);
-      bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (function_obstack);
+      bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+      bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (&flow_obstack);
     }
 
   ENTRY_BLOCK_PTR->global_live_at_end
-    = OBSTACK_ALLOC_REG_SET (function_obstack);
+    = OBSTACK_ALLOC_REG_SET (&flow_obstack);
   EXIT_BLOCK_PTR->global_live_at_start
-    = OBSTACK_ALLOC_REG_SET (function_obstack);
+    = OBSTACK_ALLOC_REG_SET (&flow_obstack);
 
-  regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (function_obstack);
+  regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (&flow_obstack);
 }
 
 void
@@ -3321,7 +3676,7 @@ allocate_reg_life_data ()
      vector oriented regsets would set regset_{size,bytes} here also.  */
   allocate_reg_info (max_regno, FALSE, FALSE);
 
-  /* Reset all the data we'll collect in propagate_block and its 
+  /* Reset all the data we'll collect in propagate_block and its
      subroutines.  */
   for (i = 0; i < max_regno; i++)
     {
@@ -3389,7 +3744,7 @@ propagate_block_delete_libcall (bb, insn, note)
 
   if (insn == bb->end)
     bb->end = before;
-  
+
   flow_delete_insn_chain (first, insn);
   return before;
 }
@@ -3414,34 +3769,31 @@ propagate_one_insn (pbi, insn)
   note = find_reg_note (insn, REG_RETVAL, NULL_RTX);
   if (flags & PROP_SCAN_DEAD_CODE)
     {
-      insn_is_dead = insn_dead_p (pbi, PATTERN (insn), 0,
-                                 REG_NOTES (insn));
+      insn_is_dead = insn_dead_p (pbi, PATTERN (insn), 0, REG_NOTES (insn));
       libcall_is_dead = (insn_is_dead && note != 0
                         && libcall_dead_p (pbi, note, insn));
     }
 
-  /* We almost certainly don't want to delete prologue or epilogue
-     instructions.  Warn about probable compiler losage.  */
-  if (insn_is_dead
-      && reload_completed
-      && (((HAVE_epilogue || HAVE_prologue)
-          && prologue_epilogue_contains (insn))
-         || (HAVE_sibcall_epilogue
-             && sibcall_epilogue_contains (insn))))
-    {
-      if (flags & PROP_KILL_DEAD_CODE)
-       { 
-         warning ("ICE: would have deleted prologue/epilogue insn");
-         if (!inhibit_warnings)
-           debug_rtx (insn);
-       }
-      libcall_is_dead = insn_is_dead = 0;
-    }
-
   /* If an instruction consists of just dead store(s) on final pass,
      delete it.  */
   if ((flags & PROP_KILL_DEAD_CODE) && insn_is_dead)
     {
+      /* If we're trying to delete a prologue or epilogue instruction
+        that isn't flagged as possibly being dead, something is wrong.
+        But if we are keeping the stack pointer depressed, we might well
+        be deleting insns that are used to compute the amount to update
+        it by, so they are fine.  */
+      if (reload_completed
+         && !(TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
+               && (TYPE_RETURNS_STACK_DEPRESSED
+                   (TREE_TYPE (current_function_decl))))
+         && (((HAVE_epilogue || HAVE_prologue)
+              && prologue_epilogue_contains (insn))
+             || (HAVE_sibcall_epilogue
+                 && sibcall_epilogue_contains (insn)))
+         && find_reg_note (insn, REG_MAYBE_DEAD, NULL_RTX) == 0)
+       abort ();
+
       /* Record sets.  Do this even for dead instructions, since they
         would have killed the values if they hadn't been deleted.  */
       mark_set_regs (pbi, PATTERN (insn), insn);
@@ -3533,7 +3885,10 @@ propagate_one_insn (pbi, insn)
 
          /* Non-constant calls clobber memory.  */
          if (! CONST_CALL_P (insn))
-           free_EXPR_LIST_list (&pbi->mem_set_list);
+           {
+             free_EXPR_LIST_list (&pbi->mem_set_list);
+             pbi->mem_set_list_len = 0;
+           }
 
          /* There may be extra registers to be clobbered.  */
          for (note = CALL_INSN_FUNCTION_USAGE (insn);
@@ -3613,18 +3968,19 @@ propagate_one_insn (pbi, insn)
    the user can use the regsets provided here.  */
 
 struct propagate_block_info *
-init_propagate_block_info (bb, live, local_set, flags)
+init_propagate_block_info (bb, live, local_set, cond_local_set, flags)
      basic_block bb;
-     regset live;
-     regset local_set;
+     regset live, local_set, cond_local_set;
      int flags;
 {
-  struct propagate_block_info *pbi = xmalloc (sizeof(*pbi));
+  struct propagate_block_info *pbi = xmalloc (sizeof (*pbi));
 
   pbi->bb = bb;
   pbi->reg_live = live;
   pbi->mem_set_list = NULL_RTX;
+  pbi->mem_set_list_len = 0;
   pbi->local_set = local_set;
+  pbi->cond_local_set = cond_local_set;
   pbi->cc0_live = 0;
   pbi->flags = flags;
 
@@ -3643,21 +3999,20 @@ init_propagate_block_info (bb, live, local_set, flags)
   /* If this block ends in a conditional branch, for each register live
      from one side of the branch and not the other, record the register
      as conditionally dead.  */
-  if ((flags & (PROP_DEATH_NOTES | PROP_SCAN_DEAD_CODE))
-      && GET_CODE (bb->end) == JUMP_INSN
+  if (GET_CODE (bb->end) == JUMP_INSN
       && any_condjump_p (bb->end))
     {
       regset_head diff_head;
       regset diff = INITIALIZE_REG_SET (diff_head);
       basic_block bb_true, bb_false;
-      rtx cond_true, cond_false;
+      rtx cond_true, cond_false, set_src;
       int i;
 
       /* Identify the successor blocks.  */
       bb_true = bb->succ->dest;
       if (bb->succ->succ_next != NULL)
        {
-          bb_false = bb->succ->succ_next->dest;
+         bb_false = bb->succ->succ_next->dest;
 
          if (bb->succ->flags & EDGE_FALLTHRU)
            {
@@ -3677,13 +4032,14 @@ init_propagate_block_info (bb, live, local_set, flags)
          /* Simplest way to do nothing.  */
          bb_false = bb_true;
        }
-     
+
       /* Extract the condition from the branch.  */
-      cond_true = XEXP (SET_SRC (PATTERN (bb->end)), 0);
+      set_src = SET_SRC (pc_set (bb->end));
+      cond_true = XEXP (set_src, 0);
       cond_false = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond_true)),
                                   GET_MODE (cond_true), XEXP (cond_true, 0),
                                   XEXP (cond_true, 1));
-      if (GET_CODE (XEXP (SET_SRC (PATTERN (bb->end)), 1)) == PC)
+      if (GET_CODE (XEXP (set_src, 1)) == PC)
        {
          rtx t = cond_false;
          cond_false = cond_true;
@@ -3694,9 +4050,15 @@ init_propagate_block_info (bb, live, local_set, flags)
       if (bitmap_operation (diff, bb_true->global_live_at_start,
                            bb_false->global_live_at_start, BITMAP_XOR))
        {
-         if (GET_CODE (XEXP (cond_true, 0)) != REG)
+         rtx reg = XEXP (cond_true, 0);
+
+         if (GET_CODE (reg) == SUBREG)
+           reg = SUBREG_REG (reg);
+
+         if (GET_CODE (reg) != REG)
            abort ();
-         SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond_true, 0)));
+
+         SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (reg));
 
          /* For each such register, mark it conditionally dead.  */
          EXECUTE_IF_SET_IN_REG_SET
@@ -3711,7 +4073,7 @@ init_propagate_block_info (bb, live, local_set, flags)
                 cond = cond_false;
               else
                 cond = cond_true;
-              rcli->condition = alloc_EXPR_LIST (0, cond, NULL_RTX);
+              rcli->condition = cond;
 
               splay_tree_insert (pbi->reg_cond_dead, i,
                                  (splay_tree_value) rcli);
@@ -3726,9 +4088,13 @@ init_propagate_block_info (bb, live, local_set, flags)
      used later in the block are dead.  So make a pass over the block
      recording any such that are made and show them dead at the end.  We do
      a very conservative and simple job here.  */
-  if ((flags & PROP_SCAN_DEAD_CODE)
+  if (optimize
+      && ! (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
+           && (TYPE_RETURNS_STACK_DEPRESSED
+               (TREE_TYPE (current_function_decl))))
+      && (flags & PROP_SCAN_DEAD_CODE)
       && (bb->succ == NULL
-          || (bb->succ->succ_next == NULL
+         || (bb->succ->succ_next == NULL
              && bb->succ->dest == EXIT_BLOCK_PTR)))
     {
       rtx insn;
@@ -3739,11 +4105,34 @@ init_propagate_block_info (bb, live, local_set, flags)
          {
            rtx mem = SET_DEST (PATTERN (insn));
 
+           /* This optimization is performed by faking a store to the
+              memory at the end of the block.  This doesn't work for
+              unchanging memories because multiple stores to unchanging
+              memory is illegal and alias analysis doesn't consider it.  */
+           if (RTX_UNCHANGING_P (mem))
+             continue;
+
            if (XEXP (mem, 0) == frame_pointer_rtx
                || (GET_CODE (XEXP (mem, 0)) == PLUS
                    && XEXP (XEXP (mem, 0), 0) == frame_pointer_rtx
                    && GET_CODE (XEXP (XEXP (mem, 0), 1)) == CONST_INT))
-             pbi->mem_set_list = alloc_EXPR_LIST (0, mem, pbi->mem_set_list);
+             {
+#ifdef AUTO_INC_DEC
+               /* Store a copy of mem, otherwise the address may be scrogged
+                  by find_auto_inc.  This matters because insn_dead_p uses
+                  an rtx_equal_p check to determine if two addresses are
+                  the same.  This works before find_auto_inc, but fails
+                  after find_auto_inc, causing discrepencies between the
+                  set of live registers calculated during the
+                  calculate_global_regs_live phase and what actually exists
+                  after flow completes, leading to aborts.  */
+               if (flags & PROP_AUTOINC)
+                 mem = shallow_copy_rtx (mem);
+#endif
+               pbi->mem_set_list = alloc_EXPR_LIST (0, mem, pbi->mem_set_list);
+               if (++pbi->mem_set_list_len >= MAX_MEM_SET_LIST_LEN)
+                 break;
+             }
          }
     }
 
@@ -3777,34 +4166,42 @@ free_propagate_block_info (pbi)
    When called, REG_LIVE contains those live at the end.  On return, it
    contains those live at the beginning.
 
-   LOCAL_SET, if non-null, will be set with all registers killed by 
-   this basic block.  */
+   LOCAL_SET, if non-null, will be set with all registers killed
+   unconditionally by this basic block.
+   Likewise, COND_LOCAL_SET, if non-null, will be set with all registers
+   killed conditionally by this basic block.  If there is any unconditional
+   set of a register, then the corresponding bit will be set in LOCAL_SET
+   and cleared in COND_LOCAL_SET.
+   It is valid for LOCAL_SET and COND_LOCAL_SET to be the same set.  In this
+   case, the resulting set will be equal to the union of the two sets that
+   would otherwise be computed.  */
 
 void
-propagate_block (bb, live, local_set, flags)
+propagate_block (bb, live, local_set, cond_local_set, flags)
      basic_block bb;
      regset live;
      regset local_set;
+     regset cond_local_set;
      int flags;
 {
   struct propagate_block_info *pbi;
   rtx insn, prev;
-  
-  pbi = init_propagate_block_info (bb, live, local_set, flags);
+
+  pbi = init_propagate_block_info (bb, live, local_set, cond_local_set, flags);
 
   if (flags & PROP_REG_INFO)
     {
       register int i;
 
       /* Process the regs live at the end of the block.
-        Mark them as not local to any one basic block. */
+        Mark them as not local to any one basic block.  */
       EXECUTE_IF_SET_IN_REG_SET (live, 0, i,
                                 { REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL; });
     }
 
   /* Scan the block an insn at a time from end to beginning.  */
 
-  for (insn = bb->end; ; insn = prev)
+  for (insn = bb->end;; insn = prev)
     {
       /* If this is a call to `setjmp' et al, warn if any
         non-volatile datum is live.  */
@@ -3845,7 +4242,7 @@ insn_dead_p (pbi, x, call_ok, notes)
      expresions into account.  */
   if (reload_completed)
     {
-      for ( ; notes; notes = XEXP (notes, 1))
+      for (; notes; notes = XEXP (notes, 1))
        {
          if (REG_NOTE_KIND (notes) == REG_INC)
            {
@@ -3871,7 +4268,7 @@ insn_dead_p (pbi, x, call_ok, notes)
       if (GET_CODE (r) == CC0)
        return ! pbi->cc0_live;
 #endif
-      
+
       /* A SET that is a subroutine call cannot be dead.  */
       if (GET_CODE (SET_SRC (x)) == CALL)
        {
@@ -3897,8 +4294,21 @@ insn_dead_p (pbi, x, call_ok, notes)
          temp = pbi->mem_set_list;
          while (temp)
            {
-             if (rtx_equal_p (XEXP (temp, 0), r))
+             rtx mem = XEXP (temp, 0);
+
+             if (rtx_equal_p (mem, r))
+               return 1;
+#ifdef AUTO_INC_DEC
+             /* Check if memory reference matches an auto increment. Only
+                post increment/decrement or modify are valid.  */
+             if (GET_MODE (mem) == GET_MODE (r)
+                 && (GET_CODE (XEXP (mem, 0)) == POST_DEC
+                     || GET_CODE (XEXP (mem, 0)) == POST_INC
+                     || GET_CODE (XEXP (mem, 0)) == POST_MODIFY)
+                 && GET_MODE (XEXP (mem, 0)) == GET_MODE (r)
+                 && rtx_equal_p (XEXP (XEXP (mem, 0), 0), XEXP (r, 0)))
                return 1;
+#endif
              temp = XEXP (temp, 1);
            }
        }
@@ -3936,6 +4346,10 @@ insn_dead_p (pbi, x, call_ok, notes)
              if (regno == STACK_POINTER_REGNUM)
                return 0;
 
+             /* ??? These bits might be redundant with the force live bits
+                in calculate_global_regs_live.  We would delete from
+                sequential sets; whether this actually affects real code
+                for anything but the stack pointer I don't know.  */
              /* Make sure insns to set the frame pointer aren't deleted.  */
              if (regno == FRAME_POINTER_REGNUM
                  && (! reload_completed || frame_pointer_needed))
@@ -3954,16 +4368,6 @@ insn_dead_p (pbi, x, call_ok, notes)
                return 0;
 #endif
 
-#ifdef PIC_OFFSET_TABLE_REGNUM
-             /* Before reload, do not allow sets of the pic register
-                to be deleted.  Reload can insert references to
-                constant pool memory anywhere in the function, making
-                the PIC register live where it wasn't before.  */
-             if (regno == PIC_OFFSET_TABLE_REGNUM && fixed_regs[regno]
-                 && ! reload_completed)
-               return 0;
-#endif
-
              /* Otherwise, the set is dead.  */
              return 1;
            }
@@ -4113,44 +4517,79 @@ invalidate_mems_from_autoinc (pbi, insn)
   for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
     {
       if (REG_NOTE_KIND (note) == REG_INC)
-        {
-          rtx temp = pbi->mem_set_list;
-          rtx prev = NULL_RTX;
+       {
+         rtx temp = pbi->mem_set_list;
+         rtx prev = NULL_RTX;
          rtx next;
 
-          while (temp)
+         while (temp)
            {
              next = XEXP (temp, 1);
              if (reg_overlap_mentioned_p (XEXP (note, 0), XEXP (temp, 0)))
-               {
-                 /* Splice temp out of list.  */
-                 if (prev)
-                   XEXP (prev, 1) = next;
-                 else
-                   pbi->mem_set_list = next;
+               {
+                 /* Splice temp out of list.  */
+                 if (prev)
+                   XEXP (prev, 1) = next;
+                 else
+                   pbi->mem_set_list = next;
                  free_EXPR_LIST_node (temp);
-               }
+                 pbi->mem_set_list_len--;
+               }
              else
-               prev = temp;
-              temp = next;
+               prev = temp;
+             temp = next;
            }
        }
     }
 }
 
-/* Process the registers that are set within X.  Their bits are set to
-   1 in the regset DEAD, because they are dead prior to this insn.
-
-   If INSN is nonzero, it is the insn being processed.
-
-   FLAGS is the set of operations to perform.  */
+/* EXP is either a MEM or a REG.  Remove any dependant entries
+   from pbi->mem_set_list.  */
 
 static void
-mark_set_regs (pbi, x, insn)
+invalidate_mems_from_set (pbi, exp)
      struct propagate_block_info *pbi;
-     rtx x, insn;
+     rtx exp;
 {
-  rtx cond = NULL_RTX;
+  rtx temp = pbi->mem_set_list;
+  rtx prev = NULL_RTX;
+  rtx next;
+
+  while (temp)
+    {
+      next = XEXP (temp, 1);
+      if ((GET_CODE (exp) == MEM
+          && output_dependence (XEXP (temp, 0), exp))
+         || (GET_CODE (exp) == REG
+             && reg_overlap_mentioned_p (exp, XEXP (temp, 0))))
+       {
+         /* Splice this entry out of the list.  */
+         if (prev)
+           XEXP (prev, 1) = next;
+         else
+           pbi->mem_set_list = next;
+         free_EXPR_LIST_node (temp);
+         pbi->mem_set_list_len--;
+       }
+      else
+       prev = temp;
+      temp = next;
+    }
+}
+
+/* Process the registers that are set within X.  Their bits are set to
+   1 in the regset DEAD, because they are dead prior to this insn.
+
+   If INSN is nonzero, it is the insn being processed.
+
+   FLAGS is the set of operations to perform.  */
+
+static void
+mark_set_regs (pbi, x, insn)
+     struct propagate_block_info *pbi;
+     rtx x, insn;
+{
+  rtx cond = NULL_RTX;
   rtx link;
   enum rtx_code code;
 
@@ -4192,7 +4631,7 @@ mark_set_regs (pbi, x, insn)
                sub = COND_EXEC_CODE (sub);
                if (GET_CODE (sub) != SET && GET_CODE (sub) != CLOBBER)
                  break;
-               /* FALLTHRU */
+               /* Fall through.  */
 
              case SET:
              case CLOBBER:
@@ -4224,23 +4663,22 @@ mark_set_1 (pbi, code, reg, cond, insn, flags)
   int not_dead = 0;
   int i;
 
-  /* Some targets place small structures in registers for
-     return values of functions.  We have to detect this
-     case specially here to get correct flow information.  */
-  if (GET_CODE (reg) == PARALLEL
-      && GET_MODE (reg) == BLKmode)
-    {
-      for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
-       mark_set_1 (pbi, code, XVECEXP (reg, 0, i), cond, insn, flags);
-      return;
-    }
-
   /* Modifying just one hardware register of a multi-reg value or just a
      byte field of a register does not mean the value from before this insn
      is now dead.  Of course, if it was dead after it's unused now.  */
 
   switch (GET_CODE (reg))
     {
+    case PARALLEL:
+      /* Some targets place small structures in registers for return values of
+        functions.  We have to detect this case specially here to get correct
+        flow information.  */
+      for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
+       if (XEXP (XVECEXP (reg, 0, i), 0) != 0)
+         mark_set_1 (pbi, code, XEXP (XVECEXP (reg, 0, i), 0), cond, insn,
+                     flags);
+      return;
+
     case ZERO_EXTRACT:
     case SIGN_EXTRACT:
     case STRICT_LOW_PART:
@@ -4254,7 +4692,7 @@ mark_set_1 (pbi, code, reg, cond, insn, flags)
       if (GET_CODE (reg) == MEM)
        break;
       not_dead = REGNO_REG_SET_P (pbi->reg_live, REGNO (reg));
-      /* FALLTHRU */
+      /* Fall through.  */
 
     case REG:
       regno_last = regno_first = REGNO (reg);
@@ -4314,36 +4752,12 @@ mark_set_1 (pbi, code, reg, cond, insn, flags)
       break;
     }
 
-  /* If this set is a MEM, then it kills any aliased writes. 
+  /* If this set is a MEM, then it kills any aliased writes.
      If this set is a REG, then it kills any MEMs which use the reg.  */
-  if (flags & PROP_SCAN_DEAD_CODE)
+  if (optimize && (flags & PROP_SCAN_DEAD_CODE))
     {
       if (GET_CODE (reg) == MEM || GET_CODE (reg) == REG)
-       {
-         rtx temp = pbi->mem_set_list;
-         rtx prev = NULL_RTX;
-         rtx next;
-
-         while (temp)
-           {
-             next = XEXP (temp, 1);
-             if ((GET_CODE (reg) == MEM
-                  && output_dependence (XEXP (temp, 0), reg))
-                 || (GET_CODE (reg) == REG
-                     && reg_overlap_mentioned_p (reg, XEXP (temp, 0))))
-               {
-                 /* Splice this entry out of the list.  */
-                 if (prev)
-                   XEXP (prev, 1) = next;
-                 else
-                   pbi->mem_set_list = next;
-                 free_EXPR_LIST_node (temp);
-               }
-             else
-               prev = temp;
-             temp = next;
-           }
-       }
+       invalidate_mems_from_set (pbi, reg);
 
       /* If the memory reference had embedded side effects (autoincrement
         address modes.  Then we may need to kill some entries on the
@@ -4351,17 +4765,27 @@ mark_set_1 (pbi, code, reg, cond, insn, flags)
       if (insn && GET_CODE (reg) == MEM)
        invalidate_mems_from_autoinc (pbi, insn);
 
-      if (GET_CODE (reg) == MEM && ! side_effects_p (reg)
+      if (pbi->mem_set_list_len < MAX_MEM_SET_LIST_LEN
+         && GET_CODE (reg) == MEM && ! side_effects_p (reg)
          /* ??? With more effort we could track conditional memory life.  */
          && ! cond
          /* We do not know the size of a BLKmode store, so we do not track
             them for redundant store elimination.  */
          && GET_MODE (reg) != BLKmode
-         /* There are no REG_INC notes for SP, so we can't assume we'll see 
+         /* There are no REG_INC notes for SP, so we can't assume we'll see
             everything that invalidates it.  To be safe, don't eliminate any
             stores though SP; none of them should be redundant anyway.  */
          && ! reg_mentioned_p (stack_pointer_rtx, reg))
-       pbi->mem_set_list = alloc_EXPR_LIST (0, reg, pbi->mem_set_list);
+       {
+#ifdef AUTO_INC_DEC
+         /* Store a copy of mem, otherwise the address may be
+            scrogged by find_auto_inc.  */
+         if (flags & PROP_AUTOINC)
+           reg = shallow_copy_rtx (reg);
+#endif
+         pbi->mem_set_list = alloc_EXPR_LIST (0, reg, pbi->mem_set_list);
+         pbi->mem_set_list_len++;
+       }
     }
 
   if (GET_CODE (reg) == REG
@@ -4382,7 +4806,16 @@ mark_set_1 (pbi, code, reg, cond, insn, flags)
        {
          int needed_regno = REGNO_REG_SET_P (pbi->reg_live, i);
          if (pbi->local_set)
-           SET_REGNO_REG_SET (pbi->local_set, i);
+           {
+             /* Order of the set operation matters here since both
+                sets may be the same.  */
+             CLEAR_REGNO_REG_SET (pbi->cond_local_set, i);
+             if (cond != NULL_RTX
+                 && ! REGNO_REG_SET_P (pbi->local_set, i))
+               SET_REGNO_REG_SET (pbi->cond_local_set, i);
+             else
+               SET_REGNO_REG_SET (pbi->local_set, i);
+           }
          if (code != CLOBBER)
            SET_REGNO_REG_SET (pbi->new_set, i);
 
@@ -4437,7 +4870,7 @@ mark_set_1 (pbi, code, reg, cond, insn, flags)
                     elsewhere, but we want the count to include the insn
                     where the reg is set, and the normal counting mechanism
                     would not count it.  */
-                 REG_LIVE_LENGTH (i) += 1;
+                 REG_LIVE_LENGTH (i) += 1;
                }
 
              /* If this is a hard reg, record this function uses the reg.  */
@@ -4543,8 +4976,8 @@ mark_set_1 (pbi, code, reg, cond, insn, flags)
 }
 \f
 #ifdef HAVE_conditional_execution
-/* Mark REGNO conditionally dead.  Return true if the register is
-   now unconditionally dead.  */
+/* Mark REGNO conditionally dead.
+   Return true if the register is now unconditionally dead.  */
 
 static int
 mark_regno_cond_dead (pbi, regno, cond)
@@ -4554,7 +4987,7 @@ mark_regno_cond_dead (pbi, regno, cond)
 {
   /* If this is a store to a predicate register, the value of the
      predicate is changing, we don't know that the predicate as seen
-     before is the same as that seen after.  Flush all dependant
+     before is the same as that seen after.  Flush all dependent
      conditions from reg_cond_dead.  This will make all such
      conditionally live registers unconditionally live.  */
   if (REGNO_REG_SET_P (pbi->reg_cond_reg, regno))
@@ -4580,25 +5013,23 @@ mark_regno_cond_dead (pbi, regno, cond)
          /* The register was unconditionally live previously.
             Record the current condition as the condition under
             which it is dead.  */
-         rcli = (struct reg_cond_life_info *)
-           xmalloc (sizeof (*rcli));
-         rcli->condition = alloc_EXPR_LIST (0, cond, NULL_RTX);
+         rcli = (struct reg_cond_life_info *) xmalloc (sizeof (*rcli));
+         rcli->condition = cond;
          splay_tree_insert (pbi->reg_cond_dead, regno,
                             (splay_tree_value) rcli);
 
-         SET_REGNO_REG_SET (pbi->reg_cond_reg,
-                            REGNO (XEXP (cond, 0)));
+         SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond, 0)));
 
          /* Not unconditionaly dead.  */
          return 0;
        }
       else
        {
-         /* The register was conditionally live previously. 
+         /* The register was conditionally live previously.
             Add the new condition to the old.  */
          rcli = (struct reg_cond_life_info *) node->value;
          ncond = rcli->condition;
-         ncond = ior_reg_cond (ncond, cond);
+         ncond = ior_reg_cond (ncond, cond, 1);
 
          /* If the register is now unconditionally dead,
             remove the entry in the splay_tree.  */
@@ -4608,8 +5039,7 @@ mark_regno_cond_dead (pbi, regno, cond)
            {
              rcli->condition = ncond;
 
-             SET_REGNO_REG_SET (pbi->reg_cond_reg,
-                                REGNO (XEXP (cond, 0)));
+             SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond, 0)));
 
              /* Not unconditionaly dead.  */
              return 0;
@@ -4627,7 +5057,6 @@ free_reg_cond_life_info (value)
      splay_tree_value value;
 {
   struct reg_cond_life_info *rcli = (struct reg_cond_life_info *) value;
-  free_EXPR_LIST_list (&rcli->condition);
   free (rcli);
 }
 
@@ -4641,7 +5070,6 @@ flush_reg_cond_reg_1 (node, data)
   struct reg_cond_life_info *rcli;
   int *xdata = (int *) data;
   unsigned int regno = xdata[0];
-  rtx c, *prev;
 
   /* Don't need to search if last flushed value was farther on in
      the in-order traversal.  */
@@ -4650,27 +5078,18 @@ flush_reg_cond_reg_1 (node, data)
 
   /* Splice out portions of the expression that refer to regno.  */
   rcli = (struct reg_cond_life_info *) node->value;
-  c = *(prev = &rcli->condition);
-  while (c)
-    {
-      if (regno == REGNO (XEXP (XEXP (c, 0), 0)))
-       {
-         rtx next = XEXP (c, 1);
-         free_EXPR_LIST_node (c);
-         c = *prev = next;
-       }
-      else
-       c = *(prev = &XEXP (c, 1));
-    }
+  rcli->condition = elim_reg_cond (rcli->condition, regno);
 
-  /* If the entire condition is now NULL, signal the node to be removed.  */
-  if (! rcli->condition)
+  /* If the entire condition is now false, signal the node to be removed.  */
+  if (rcli->condition == const0_rtx)
     {
       xdata[1] = node->key;
       return -1;
     }
-  else
-    return 0;
+  else if (rcli->condition == const1_rtx)
+    abort ();
+
+  return 0;
 }
 
 /* Flush all (sub) expressions referring to REGNO from REG_COND_LIVE.  */
@@ -4691,47 +5110,91 @@ flush_reg_cond_reg (pbi, regno)
   CLEAR_REGNO_REG_SET (pbi->reg_cond_reg, regno);
 }
 
-/* Logical arithmetic on predicate conditions.  IOR, NOT and NAND.
-   We actually use EXPR_LIST to chain the sub-expressions together
-   instead of IOR because it's easier to manipulate and we have 
-   the lists.c functions to reuse nodes.
-   
-   Return a new rtl expression as appropriate.  */
+/* Logical arithmetic on predicate conditions.  IOR, NOT and AND.
+   For ior/and, the ADD flag determines whether we want to add the new
+   condition X to the old one unconditionally.  If it is zero, we will
+   only return a new expression if X allows us to simplify part of
+   OLD, otherwise we return OLD unchanged to the caller.
+   If ADD is nonzero, we will return a new condition in all cases.  The
+   toplevel caller of one of these functions should always pass 1 for
+   ADD.  */
 
 static rtx
-ior_reg_cond (old, x)
+ior_reg_cond (old, x, add)
      rtx old, x;
+     int add;
 {
-  enum rtx_code x_code;
-  rtx x_reg;
-  rtx c;
+  rtx op0, op1;
 
-  /* We expect these conditions to be of the form (eq reg 0).  */
-  x_code = GET_CODE (x);
-  if (GET_RTX_CLASS (x_code) != '<'
-      || GET_CODE (x_reg = XEXP (x, 0)) != REG
-      || XEXP (x, 1) != const0_rtx)
-    abort ();
+  if (GET_RTX_CLASS (GET_CODE (old)) == '<')
+    {
+      if (GET_RTX_CLASS (GET_CODE (x)) == '<'
+         && GET_CODE (x) == reverse_condition (GET_CODE (old))
+         && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+       return const1_rtx;
+      if (GET_CODE (x) == GET_CODE (old)
+         && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+       return old;
+      if (! add)
+       return old;
+      return gen_rtx_IOR (0, old, x);
+    }
 
-  /* Search the expression for an existing sub-expression of X_REG.  */
-  for (c = old; c ; c = XEXP (c, 1))
+  switch (GET_CODE (old))
     {
-      rtx y = XEXP (c, 0);
-      if (REGNO (XEXP (y, 0)) == REGNO (x_reg))
+    case IOR:
+      op0 = ior_reg_cond (XEXP (old, 0), x, 0);
+      op1 = ior_reg_cond (XEXP (old, 1), x, 0);
+      if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
        {
-         /* If we find X already present in OLD, we need do nothing.  */
-         if (GET_CODE (y) == x_code)
-           return old;
-
-         /* If we find X being a compliment of a condition in OLD, 
-            then the entire condition is true.  */
-         if (GET_CODE (y) == reverse_condition (x_code))
+         if (op0 == const0_rtx)
+           return op1;
+         if (op1 == const0_rtx)
+           return op0;
+         if (op0 == const1_rtx || op1 == const1_rtx)
            return const1_rtx;
+         if (op0 == XEXP (old, 0))
+           op0 = gen_rtx_IOR (0, op0, x);
+         else
+           op1 = gen_rtx_IOR (0, op1, x);
+         return gen_rtx_IOR (0, op0, op1);
        }
-    }
+      if (! add)
+       return old;
+      return gen_rtx_IOR (0, old, x);
+
+    case AND:
+      op0 = ior_reg_cond (XEXP (old, 0), x, 0);
+      op1 = ior_reg_cond (XEXP (old, 1), x, 0);
+      if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
+       {
+         if (op0 == const1_rtx)
+           return op1;
+         if (op1 == const1_rtx)
+           return op0;
+         if (op0 == const0_rtx || op1 == const0_rtx)
+           return const0_rtx;
+         if (op0 == XEXP (old, 0))
+           op0 = gen_rtx_IOR (0, op0, x);
+         else
+           op1 = gen_rtx_IOR (0, op1, x);
+         return gen_rtx_AND (0, op0, op1);
+       }
+      if (! add)
+       return old;
+      return gen_rtx_IOR (0, old, x);
+
+    case NOT:
+      op0 = and_reg_cond (XEXP (old, 0), not_reg_cond (x), 0);
+      if (op0 != XEXP (old, 0))
+       return not_reg_cond (op0);
+      if (! add)
+       return old;
+      return gen_rtx_IOR (0, old, x);
 
-  /* Otherwise just add to the chain.  */
-  return alloc_EXPR_LIST (0, x, old);
+    default:
+      abort ();
+    }
 }
 
 static rtx
@@ -4739,68 +5202,317 @@ not_reg_cond (x)
      rtx x;
 {
   enum rtx_code x_code;
-  rtx x_reg;
 
-  /* We expect these conditions to be of the form (eq reg 0).  */
+  if (x == const0_rtx)
+    return const1_rtx;
+  else if (x == const1_rtx)
+    return const0_rtx;
   x_code = GET_CODE (x);
-  if (GET_RTX_CLASS (x_code) != '<'
-      || GET_CODE (x_reg = XEXP (x, 0)) != REG
-      || XEXP (x, 1) != const0_rtx)
-    abort ();
+  if (x_code == NOT)
+    return XEXP (x, 0);
+  if (GET_RTX_CLASS (x_code) == '<'
+      && GET_CODE (XEXP (x, 0)) == REG)
+    {
+      if (XEXP (x, 1) != const0_rtx)
+       abort ();
 
-  return alloc_EXPR_LIST (0, gen_rtx_fmt_ee (reverse_condition (x_code),
-                                            VOIDmode, x_reg, const0_rtx),
-                         NULL_RTX);
+      return gen_rtx_fmt_ee (reverse_condition (x_code),
+                            VOIDmode, XEXP (x, 0), const0_rtx);
+    }
+  return gen_rtx_NOT (0, x);
 }
 
 static rtx
-nand_reg_cond (old, x)
+and_reg_cond (old, x, add)
      rtx old, x;
+     int add;
 {
-  enum rtx_code x_code;
-  rtx x_reg;
-  rtx c, *prev;
-
-  /* We expect these conditions to be of the form (eq reg 0).  */
-  x_code = GET_CODE (x);
-  if (GET_RTX_CLASS (x_code) != '<'
-      || GET_CODE (x_reg = XEXP (x, 0)) != REG
-      || XEXP (x, 1) != const0_rtx)
-    abort ();
+  rtx op0, op1;
 
-  /* Search the expression for an existing sub-expression of X_REG.  */
+  if (GET_RTX_CLASS (GET_CODE (old)) == '<')
+    {
+      if (GET_RTX_CLASS (GET_CODE (x)) == '<'
+         && GET_CODE (x) == reverse_condition (GET_CODE (old))
+         && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+       return const0_rtx;
+      if (GET_CODE (x) == GET_CODE (old)
+         && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+       return old;
+      if (! add)
+       return old;
+      return gen_rtx_AND (0, old, x);
+    }
 
-  for (c = *(prev = &old); c ; c = *(prev = &XEXP (c, 1)))
+  switch (GET_CODE (old))
     {
-      rtx y = XEXP (c, 0);
-      if (REGNO (XEXP (y, 0)) == REGNO (x_reg))
+    case IOR:
+      op0 = and_reg_cond (XEXP (old, 0), x, 0);
+      op1 = and_reg_cond (XEXP (old, 1), x, 0);
+      if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
        {
-         /* If we find X already present in OLD, then we need to 
-            splice it out.  */
-         if (GET_CODE (y) == x_code)
-           {
-             *prev = XEXP (c, 1);
-             free_EXPR_LIST_node (c);
-             return old ? old : const0_rtx;
-           }
-
-         /* If we find X being a compliment of a condition in OLD, 
-            then we need do nothing.  */
-         if (GET_CODE (y) == reverse_condition (x_code))
-           return old;
+         if (op0 == const0_rtx)
+           return op1;
+         if (op1 == const0_rtx)
+           return op0;
+         if (op0 == const1_rtx || op1 == const1_rtx)
+           return const1_rtx;
+         if (op0 == XEXP (old, 0))
+           op0 = gen_rtx_AND (0, op0, x);
+         else
+           op1 = gen_rtx_AND (0, op1, x);
+         return gen_rtx_IOR (0, op0, op1);
        }
+      if (! add)
+       return old;
+      return gen_rtx_AND (0, old, x);
+
+    case AND:
+      op0 = and_reg_cond (XEXP (old, 0), x, 0);
+      op1 = and_reg_cond (XEXP (old, 1), x, 0);
+      if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
+       {
+         if (op0 == const1_rtx)
+           return op1;
+         if (op1 == const1_rtx)
+           return op0;
+         if (op0 == const0_rtx || op1 == const0_rtx)
+           return const0_rtx;
+         if (op0 == XEXP (old, 0))
+           op0 = gen_rtx_AND (0, op0, x);
+         else
+           op1 = gen_rtx_AND (0, op1, x);
+         return gen_rtx_AND (0, op0, op1);
+       }
+      if (! add)
+       return old;
+      return gen_rtx_AND (0, old, x);
+
+    case NOT:
+      op0 = ior_reg_cond (XEXP (old, 0), not_reg_cond (x), 0);
+      if (op0 != XEXP (old, 0))
+       return not_reg_cond (op0);
+      if (! add)
+       return old;
+      return gen_rtx_AND (0, old, x);
+
+    default:
+      abort ();
+    }
+}
+
+/* Given a condition X, remove references to reg REGNO and return the
+   new condition.  The removal will be done so that all conditions
+   involving REGNO are considered to evaluate to false.  This function
+   is used when the value of REGNO changes.  */
+
+static rtx
+elim_reg_cond (x, regno)
+     rtx x;
+     unsigned int regno;
+{
+  rtx op0, op1;
+
+  if (GET_RTX_CLASS (GET_CODE (x)) == '<')
+    {
+      if (REGNO (XEXP (x, 0)) == regno)
+       return const0_rtx;
+      return x;
     }
 
-  /* Otherwise, by implication, the register in question is now live for
-     the inverse of the condition X.  */
-  return alloc_EXPR_LIST (0, gen_rtx_fmt_ee (reverse_condition (x_code),
-                                            VOIDmode, x_reg, const0_rtx),
-                         old);
+  switch (GET_CODE (x))
+    {
+    case AND:
+      op0 = elim_reg_cond (XEXP (x, 0), regno);
+      op1 = elim_reg_cond (XEXP (x, 1), regno);
+      if (op0 == const0_rtx || op1 == const0_rtx)
+       return const0_rtx;
+      if (op0 == const1_rtx)
+       return op1;
+      if (op1 == const1_rtx)
+       return op0;
+      if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1))
+       return x;
+      return gen_rtx_AND (0, op0, op1);
+
+    case IOR:
+      op0 = elim_reg_cond (XEXP (x, 0), regno);
+      op1 = elim_reg_cond (XEXP (x, 1), regno);
+      if (op0 == const1_rtx || op1 == const1_rtx)
+       return const1_rtx;
+      if (op0 == const0_rtx)
+       return op1;
+      if (op1 == const0_rtx)
+       return op0;
+      if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1))
+       return x;
+      return gen_rtx_IOR (0, op0, op1);
+
+    case NOT:
+      op0 = elim_reg_cond (XEXP (x, 0), regno);
+      if (op0 == const0_rtx)
+       return const1_rtx;
+      if (op0 == const1_rtx)
+       return const0_rtx;
+      if (op0 != XEXP (x, 0))
+       return not_reg_cond (op0);
+      return x;
+
+    default:
+      abort ();
+    }
 }
 #endif /* HAVE_conditional_execution */
 \f
 #ifdef AUTO_INC_DEC
 
+/* Try to substitute the auto-inc expression INC as the address inside
+   MEM which occurs in INSN.  Currently, the address of MEM is an expression
+   involving INCR_REG, and INCR is the next use of INCR_REG; it is an insn
+   that has a single set whose source is a PLUS of INCR_REG and something
+   else.  */
+
+static void
+attempt_auto_inc (pbi, inc, insn, mem, incr, incr_reg)
+     struct propagate_block_info *pbi;
+     rtx inc, insn, mem, incr, incr_reg;
+{
+  int regno = REGNO (incr_reg);
+  rtx set = single_set (incr);
+  rtx q = SET_DEST (set);
+  rtx y = SET_SRC (set);
+  int opnum = XEXP (y, 0) == incr_reg ? 0 : 1;
+
+  /* Make sure this reg appears only once in this insn.  */
+  if (count_occurrences (PATTERN (insn), incr_reg, 1) != 1)
+    return;
+
+  if (dead_or_set_p (incr, incr_reg)
+      /* Mustn't autoinc an eliminable register.  */
+      && (regno >= FIRST_PSEUDO_REGISTER
+         || ! TEST_HARD_REG_BIT (elim_reg_set, regno)))
+    {
+      /* This is the simple case.  Try to make the auto-inc.  If
+        we can't, we are done.  Otherwise, we will do any
+        needed updates below.  */
+      if (! validate_change (insn, &XEXP (mem, 0), inc, 0))
+       return;
+    }
+  else if (GET_CODE (q) == REG
+          /* PREV_INSN used here to check the semi-open interval
+             [insn,incr).  */
+          && ! reg_used_between_p (q,  PREV_INSN (insn), incr)
+          /* We must also check for sets of q as q may be
+             a call clobbered hard register and there may
+             be a call between PREV_INSN (insn) and incr.  */
+          && ! reg_set_between_p (q,  PREV_INSN (insn), incr))
+    {
+      /* We have *p followed sometime later by q = p+size.
+        Both p and q must be live afterward,
+        and q is not used between INSN and its assignment.
+        Change it to q = p, ...*q..., q = q+size.
+        Then fall into the usual case.  */
+      rtx insns, temp;
+
+      start_sequence ();
+      emit_move_insn (q, incr_reg);
+      insns = get_insns ();
+      end_sequence ();
+
+      if (basic_block_for_insn)
+       for (temp = insns; temp; temp = NEXT_INSN (temp))
+         set_block_for_insn (temp, pbi->bb);
+
+      /* If we can't make the auto-inc, or can't make the
+        replacement into Y, exit.  There's no point in making
+        the change below if we can't do the auto-inc and doing
+        so is not correct in the pre-inc case.  */
+
+      XEXP (inc, 0) = q;
+      validate_change (insn, &XEXP (mem, 0), inc, 1);
+      validate_change (incr, &XEXP (y, opnum), q, 1);
+      if (! apply_change_group ())
+       return;
+
+      /* We now know we'll be doing this change, so emit the
+        new insn(s) and do the updates.  */
+      emit_insns_before (insns, insn);
+
+      if (pbi->bb->head == insn)
+       pbi->bb->head = insns;
+
+      /* INCR will become a NOTE and INSN won't contain a
+        use of INCR_REG.  If a use of INCR_REG was just placed in
+        the insn before INSN, make that the next use.
+        Otherwise, invalidate it.  */
+      if (GET_CODE (PREV_INSN (insn)) == INSN
+         && GET_CODE (PATTERN (PREV_INSN (insn))) == SET
+         && SET_SRC (PATTERN (PREV_INSN (insn))) == incr_reg)
+       pbi->reg_next_use[regno] = PREV_INSN (insn);
+      else
+       pbi->reg_next_use[regno] = 0;
+
+      incr_reg = q;
+      regno = REGNO (q);
+
+      /* REGNO is now used in INCR which is below INSN, but
+        it previously wasn't live here.  If we don't mark
+        it as live, we'll put a REG_DEAD note for it
+        on this insn, which is incorrect.  */
+      SET_REGNO_REG_SET (pbi->reg_live, regno);
+
+      /* If there are any calls between INSN and INCR, show
+        that REGNO now crosses them.  */
+      for (temp = insn; temp != incr; temp = NEXT_INSN (temp))
+       if (GET_CODE (temp) == CALL_INSN)
+         REG_N_CALLS_CROSSED (regno)++;
+    }
+  else
+    return;
+
+  /* If we haven't returned, it means we were able to make the
+     auto-inc, so update the status.  First, record that this insn
+     has an implicit side effect.  */
+
+  REG_NOTES (insn) = alloc_EXPR_LIST (REG_INC, incr_reg, REG_NOTES (insn));
+
+  /* Modify the old increment-insn to simply copy
+     the already-incremented value of our register.  */
+  if (! validate_change (incr, &SET_SRC (set), incr_reg, 0))
+    abort ();
+
+  /* If that makes it a no-op (copying the register into itself) delete
+     it so it won't appear to be a "use" and a "set" of this
+     register.  */
+  if (REGNO (SET_DEST (set)) == REGNO (incr_reg))
+    {
+      /* If the original source was dead, it's dead now.  */
+      rtx note;
+
+      while ((note = find_reg_note (incr, REG_DEAD, NULL_RTX)) != NULL_RTX)
+       {
+         remove_note (incr, note);
+         if (XEXP (note, 0) != incr_reg)
+           CLEAR_REGNO_REG_SET (pbi->reg_live, REGNO (XEXP (note, 0)));
+       }
+
+      PUT_CODE (incr, NOTE);
+      NOTE_LINE_NUMBER (incr) = NOTE_INSN_DELETED;
+      NOTE_SOURCE_FILE (incr) = 0;
+    }
+
+  if (regno >= FIRST_PSEUDO_REGISTER)
+    {
+      /* Count an extra reference to the reg.  When a reg is
+        incremented, spilling it is worse, so we want to make
+        that less likely.  */
+      REG_N_REFS (regno) += (optimize_size ? 1 : pbi->bb->loop_depth + 1);
+
+      /* Count the increment as a setting of the register,
+        even though it isn't a SET in rtl.  */
+      REG_N_SETS (regno)++;
+    }
+}
+
 /* X is a MEM found in INSN.  See if we can convert it into an auto-increment
    reference.  */
 
@@ -4812,7 +5524,12 @@ find_auto_inc (pbi, x, insn)
 {
   rtx addr = XEXP (x, 0);
   HOST_WIDE_INT offset = 0;
-  rtx set;
+  rtx set, y, incr, inc_val;
+  int regno;
+  int size = GET_MODE_SIZE (GET_MODE (x));
+
+  if (GET_CODE (insn) == JUMP_INSN)
+    return;
 
   /* Here we detect use of an index register which might be good for
      postincrement, postdecrement, preincrement, or predecrement.  */
@@ -4820,170 +5537,69 @@ find_auto_inc (pbi, x, insn)
   if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
     offset = INTVAL (XEXP (addr, 1)), addr = XEXP (addr, 0);
 
-  if (GET_CODE (addr) == REG)
-    {
-      register rtx y;
-      register int size = GET_MODE_SIZE (GET_MODE (x));
-      rtx use;
-      rtx incr;
-      int regno = REGNO (addr);
-
-      /* Is the next use an increment that might make auto-increment? */
-      if ((incr = pbi->reg_next_use[regno]) != 0
-         && (set = single_set (incr)) != 0
-         && GET_CODE (set) == SET
-         && BLOCK_NUM (incr) == BLOCK_NUM (insn)
-         /* Can't add side effects to jumps; if reg is spilled and
-            reloaded, there's no way to store back the altered value.  */
-         && GET_CODE (insn) != JUMP_INSN
-         && (y = SET_SRC (set), GET_CODE (y) == PLUS)
-         && XEXP (y, 0) == addr
-         && GET_CODE (XEXP (y, 1)) == CONST_INT
-         && ((HAVE_POST_INCREMENT
-              && (INTVAL (XEXP (y, 1)) == size && offset == 0))
-             || (HAVE_POST_DECREMENT
-                 && (INTVAL (XEXP (y, 1)) == - size && offset == 0))
-             || (HAVE_PRE_INCREMENT
-                 && (INTVAL (XEXP (y, 1)) == size && offset == size))
-             || (HAVE_PRE_DECREMENT
-                 && (INTVAL (XEXP (y, 1)) == - size && offset == - size)))
-         /* Make sure this reg appears only once in this insn.  */
-         && (use = find_use_as_address (PATTERN (insn), addr, offset),
-             use != 0 && use != (rtx) 1))
-       {
-         rtx q = SET_DEST (set);
-         enum rtx_code inc_code = (INTVAL (XEXP (y, 1)) == size
-                                   ? (offset ? PRE_INC : POST_INC)
-                                   : (offset ? PRE_DEC : POST_DEC));
-
-         if (dead_or_set_p (incr, addr)
-             /* Mustn't autoinc an eliminable register.  */
-             && (regno >= FIRST_PSEUDO_REGISTER
-                 || ! TEST_HARD_REG_BIT (elim_reg_set, regno)))
-           {
-             /* This is the simple case.  Try to make the auto-inc.  If
-                we can't, we are done.  Otherwise, we will do any
-                needed updates below.  */
-             if (! validate_change (insn, &XEXP (x, 0),
-                                    gen_rtx_fmt_e (inc_code, Pmode, addr),
-                                    0))
-               return;
-           }
-         else if (GET_CODE (q) == REG
-                  /* PREV_INSN used here to check the semi-open interval
-                     [insn,incr).  */
-                  && ! reg_used_between_p (q,  PREV_INSN (insn), incr)
-                  /* We must also check for sets of q as q may be
-                     a call clobbered hard register and there may
-                     be a call between PREV_INSN (insn) and incr.  */
-                  && ! reg_set_between_p (q,  PREV_INSN (insn), incr))
-           {
-             /* We have *p followed sometime later by q = p+size.
-                Both p and q must be live afterward,
-                and q is not used between INSN and its assignment.
-                Change it to q = p, ...*q..., q = q+size.
-                Then fall into the usual case.  */
-             rtx insns, temp;
-
-             start_sequence ();
-             emit_move_insn (q, addr);
-             insns = get_insns ();
-             end_sequence ();
-
-             if (basic_block_for_insn)
-               for (temp = insns; temp; temp = NEXT_INSN (temp))
-                 set_block_for_insn (temp, pbi->bb);
-
-             /* If we can't make the auto-inc, or can't make the
-                replacement into Y, exit.  There's no point in making
-                the change below if we can't do the auto-inc and doing
-                so is not correct in the pre-inc case.  */
-
-             validate_change (insn, &XEXP (x, 0),
-                              gen_rtx_fmt_e (inc_code, Pmode, q),
-                              1);
-             validate_change (incr, &XEXP (y, 0), q, 1);
-             if (! apply_change_group ())
-               return;
-
-             /* We now know we'll be doing this change, so emit the
-                new insn(s) and do the updates.  */
-             emit_insns_before (insns, insn);
-
-             if (pbi->bb->head == insn)
-               pbi->bb->head = insns;
-
-             /* INCR will become a NOTE and INSN won't contain a
-                use of ADDR.  If a use of ADDR was just placed in
-                the insn before INSN, make that the next use. 
-                Otherwise, invalidate it.  */
-             if (GET_CODE (PREV_INSN (insn)) == INSN
-                 && GET_CODE (PATTERN (PREV_INSN (insn))) == SET
-                 && SET_SRC (PATTERN (PREV_INSN (insn))) == addr)
-               pbi->reg_next_use[regno] = PREV_INSN (insn);
-             else
-               pbi->reg_next_use[regno] = 0;
-
-             addr = q;
-             regno = REGNO (q);
-
-             /* REGNO is now used in INCR which is below INSN, but it
-                previously wasn't live here.  If we don't mark it as
-                live, we'll put a REG_DEAD note for it on this insn,
-                which is incorrect.  */
-             SET_REGNO_REG_SET (pbi->reg_live, regno);
-
-             /* If there are any calls between INSN and INCR, show
-                that REGNO now crosses them.  */
-             for (temp = insn; temp != incr; temp = NEXT_INSN (temp))
-               if (GET_CODE (temp) == CALL_INSN)
-                 REG_N_CALLS_CROSSED (regno)++;
-           }
-         else
-           return;
-
-         /* If we haven't returned, it means we were able to make the
-            auto-inc, so update the status.  First, record that this insn
-            has an implicit side effect.  */
+  if (GET_CODE (addr) != REG)
+    return;
 
-         REG_NOTES (insn)
-           = alloc_EXPR_LIST (REG_INC, addr, REG_NOTES (insn));
+  regno = REGNO (addr);
 
-         /* Modify the old increment-insn to simply copy
-            the already-incremented value of our register.  */
-         if (! validate_change (incr, &SET_SRC (set), addr, 0))
-           abort ();
+  /* Is the next use an increment that might make auto-increment? */
+  incr = pbi->reg_next_use[regno];
+  if (incr == 0 || BLOCK_NUM (incr) != BLOCK_NUM (insn))
+    return;
+  set = single_set (incr);
+  if (set == 0 || GET_CODE (set) != SET)
+    return;
+  y = SET_SRC (set);
 
-         /* If that makes it a no-op (copying the register into itself) delete
-            it so it won't appear to be a "use" and a "set" of this
-            register.  */
-         if (SET_DEST (set) == addr)
-           {
-             /* If the original source was dead, it's dead now.  */
-             rtx note = find_reg_note (incr, REG_DEAD, NULL_RTX);
-             if (note && XEXP (note, 0) != addr)
-               CLEAR_REGNO_REG_SET (pbi->reg_live, REGNO (XEXP (note, 0)));
-             
-             PUT_CODE (incr, NOTE);
-             NOTE_LINE_NUMBER (incr) = NOTE_INSN_DELETED;
-             NOTE_SOURCE_FILE (incr) = 0;
-           }
+  if (GET_CODE (y) != PLUS)
+    return;
 
-         if (regno >= FIRST_PSEUDO_REGISTER)
-           {
-             /* Count an extra reference to the reg.  When a reg is
-                incremented, spilling it is worse, so we want to make
-                that less likely.  */
-             REG_N_REFS (regno) += (optimize_size ? 1
-                                    : pbi->bb->loop_depth + 1);
+  if (REG_P (XEXP (y, 0)) && REGNO (XEXP (y, 0)) == REGNO (addr))
+    inc_val = XEXP (y, 1);
+  else if (REG_P (XEXP (y, 1)) && REGNO (XEXP (y, 1)) == REGNO (addr))
+    inc_val = XEXP (y, 0);
+  else
+    return;
 
-             /* Count the increment as a setting of the register,
-                even though it isn't a SET in rtl.  */
-             REG_N_SETS (regno)++;
-           }
-       }
+  if (GET_CODE (inc_val) == CONST_INT)
+    {
+      if (HAVE_POST_INCREMENT
+         && (INTVAL (inc_val) == size && offset == 0))
+       attempt_auto_inc (pbi, gen_rtx_POST_INC (Pmode, addr), insn, x,
+                         incr, addr);
+      else if (HAVE_POST_DECREMENT
+              && (INTVAL (inc_val) == -size && offset == 0))
+       attempt_auto_inc (pbi, gen_rtx_POST_DEC (Pmode, addr), insn, x,
+                         incr, addr);
+      else if (HAVE_PRE_INCREMENT
+              && (INTVAL (inc_val) == size && offset == size))
+       attempt_auto_inc (pbi, gen_rtx_PRE_INC (Pmode, addr), insn, x,
+                         incr, addr);
+      else if (HAVE_PRE_DECREMENT
+              && (INTVAL (inc_val) == -size && offset == -size))
+       attempt_auto_inc (pbi, gen_rtx_PRE_DEC (Pmode, addr), insn, x,
+                         incr, addr);
+      else if (HAVE_POST_MODIFY_DISP && offset == 0)
+       attempt_auto_inc (pbi, gen_rtx_POST_MODIFY (Pmode, addr,
+                                                   gen_rtx_PLUS (Pmode,
+                                                                 addr,
+                                                                 inc_val)),
+                         insn, x, incr, addr);
+    }
+  else if (GET_CODE (inc_val) == REG
+          && ! reg_set_between_p (inc_val, PREV_INSN (insn),
+                                  NEXT_INSN (incr)))
+
+    {
+      if (HAVE_POST_MODIFY_REG && offset == 0)
+       attempt_auto_inc (pbi, gen_rtx_POST_MODIFY (Pmode, addr,
+                                                   gen_rtx_PLUS (Pmode,
+                                                                 addr,
+                                                                 inc_val)),
+                         insn, x, incr, addr);
     }
 }
+
 #endif /* AUTO_INC_DEC */
 \f
 static void
@@ -5143,11 +5759,11 @@ mark_used_reg (pbi, reg, cond, insn)
            }
          else
            {
-             /* The register was conditionally live previously. 
+             /* The register was conditionally live previously.
                 Subtract the new life cond from the old death cond.  */
              rcli = (struct reg_cond_life_info *) node->value;
              ncond = rcli->condition;
-             ncond = nand_reg_cond (ncond, cond);
+             ncond = and_reg_cond (ncond, not_reg_cond (cond), 1);
 
              /* If the register is now unconditionally live, remove the
                 entry in the splay_tree.  */
@@ -5157,7 +5773,10 @@ mark_used_reg (pbi, reg, cond, insn)
                  splay_tree_remove (pbi->reg_cond_dead, regno);
                }
              else
-               rcli->condition = ncond;
+               {
+                 rcli->condition = ncond;
+                 SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond, 0)));
+               }
            }
        }
       else
@@ -5168,6 +5787,8 @@ mark_used_reg (pbi, reg, cond, insn)
          rcli->condition = not_reg_cond (cond);
          splay_tree_insert (pbi->reg_cond_dead, regno,
                             (splay_tree_value) rcli);
+
+         SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond, 0)));
        }
     }
   else if (some_was_live)
@@ -5235,16 +5856,17 @@ mark_used_regs (pbi, x, cond, insn)
       return;
 
     case MEM:
-      /* Don't bother watching stores to mems if this is not the 
+      /* Don't bother watching stores to mems if this is not the
         final pass.  We'll not be deleting dead stores this round.  */
-      if (flags & PROP_SCAN_DEAD_CODE)
+      if (optimize && (flags & PROP_SCAN_DEAD_CODE))
        {
-          /* Invalidate the data for the last MEM stored, but only if MEM is
+         /* Invalidate the data for the last MEM stored, but only if MEM is
             something that can be stored into.  */
-          if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
+         if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
              && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
-           ; /* needn't clear the memory set list */
-          else
+           /* Needn't clear the memory set list.  */
+           ;
+         else
            {
              rtx temp = pbi->mem_set_list;
              rtx prev = NULL_RTX;
@@ -5261,6 +5883,7 @@ mark_used_regs (pbi, x, cond, insn)
                      else
                        pbi->mem_set_list = next;
                      free_EXPR_LIST_node (temp);
+                     pbi->mem_set_list_len--;
                    }
                  else
                    prev = temp;
@@ -5294,7 +5917,7 @@ mark_used_regs (pbi, x, cond, insn)
       x = SUBREG_REG (x);
       if (GET_CODE (x) != REG)
        goto retry;
-      /* FALLTHRU */
+      /* Fall through.  */
 
     case REG:
       /* See a register other than being set => mark it as needed.  */
@@ -5318,7 +5941,7 @@ mark_used_regs (pbi, x, cond, insn)
            mark_used_regs (pbi, SET_SRC (x), cond, insn);
            return;
          }
-           
+
        /* Storing in STRICT_LOW_PART is like storing in a reg
           in that this SET might be dead, so ignore it in TESTREG.
           but in some other ways it is like using the reg.
@@ -5352,8 +5975,8 @@ mark_used_regs (pbi, x, cond, insn)
            testreg = XEXP (testreg, 0);
          }
 
-       /* If this is a store into a register, recursively scan the
-          value being stored.  */
+       /* If this is a store into a register or group of registers,
+          recursively scan the value being stored.  */
 
        if ((GET_CODE (testreg) == PARALLEL
             && GET_MODE (testreg) == BLKmode)
@@ -5389,7 +6012,7 @@ mark_used_regs (pbi, x, cond, insn)
 
           Consider for instance a volatile asm that changes the fpu rounding
           mode.  An insn should not be moved across this even if it only uses
-          pseudo-regs because it might give an incorrectly rounded result. 
+          pseudo-regs because it might give an incorrectly rounded result.
 
           ?!? Unfortunately, marking all hard registers as live causes massive
           problems for the register allocator and marking all pseudos as live
@@ -5398,9 +6021,12 @@ mark_used_regs (pbi, x, cond, insn)
           So for now, just clear the memory set list and mark any regs
           we can find in ASM_OPERANDS as used.  */
        if (code != ASM_OPERANDS || MEM_VOLATILE_P (x))
-         free_EXPR_LIST_list (&pbi->mem_set_list);
+         {
+           free_EXPR_LIST_list (&pbi->mem_set_list);
+           pbi->mem_set_list_len = 0;
+         }
 
-        /* For all ASM_OPERANDS, we must traverse the vector of input operands.
+       /* For all ASM_OPERANDS, we must traverse the vector of input operands.
           We can not just fall through here since then we would be confused
           by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
           traditional asms unlike their normal usage.  */
@@ -5441,7 +6067,7 @@ mark_used_regs (pbi, x, cond, insn)
   {
     register const char *fmt = GET_RTX_FORMAT (code);
     register int i;
-    
+
     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
       {
        if (fmt[i] == 'e')
@@ -5475,32 +6101,35 @@ try_pre_increment_1 (pbi, insn)
      make it do pre-increment or pre-decrement if appropriate.  */
   rtx x = single_set (insn);
   HOST_WIDE_INT amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
-               * INTVAL (XEXP (SET_SRC (x), 1)));
+                         * INTVAL (XEXP (SET_SRC (x), 1)));
   int regno = REGNO (SET_DEST (x));
   rtx y = pbi->reg_next_use[regno];
   if (y != 0
+      && SET_DEST (x) != stack_pointer_rtx
       && BLOCK_NUM (y) == BLOCK_NUM (insn)
       /* Don't do this if the reg dies, or gets set in y; a standard addressing
         mode would be better.  */
       && ! dead_or_set_p (y, SET_DEST (x))
       && try_pre_increment (y, SET_DEST (x), amount))
     {
-      /* We have found a suitable auto-increment
-        and already changed insn Y to do it.
-        So flush this increment-instruction.  */
-      PUT_CODE (insn, NOTE);
-      NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
-      NOTE_SOURCE_FILE (insn) = 0;
-      /* Count a reference to this reg for the increment
-        insn we are deleting.  When a reg is incremented.
-        spilling it is worse, so we want to make that
-        less likely.  */
+      /* We have found a suitable auto-increment and already changed
+        insn Y to do it.  So flush this increment instruction.  */
+      propagate_block_delete_insn (pbi->bb, insn);
+
+      /* Count a reference to this reg for the increment insn we are
+        deleting.  When a reg is incremented, spilling it is worse,
+        so we want to make that less likely.  */
       if (regno >= FIRST_PSEUDO_REGISTER)
        {
          REG_N_REFS (regno) += (optimize_size ? 1
                                 : pbi->bb->loop_depth + 1);
          REG_N_SETS (regno)++;
        }
+
+      /* Flush any remembered memories depending on the value of
+        the incremented register.  */
+      invalidate_mems_from_set (pbi, SET_DEST (x));
+
       return 1;
     }
   return 0;
@@ -5700,10 +6329,10 @@ dump_flow_info (file)
        if (REG_BASIC_BLOCK (i) >= 0)
          fprintf (file, " in block %d", REG_BASIC_BLOCK (i));
        if (REG_N_SETS (i))
-         fprintf (file, "; set %d time%s", REG_N_SETS (i),
-                  (REG_N_SETS (i) == 1) ? "" : "s");
+         fprintf (file, "; set %d time%s", REG_N_SETS (i),
+                  (REG_N_SETS (i) == 1) ? "" : "s");
        if (REG_USERVAR_P (regno_reg_rtx[i]))
-         fprintf (file, "; user var");
+         fprintf (file, "; user var");
        if (REG_N_DEATHS (i) != 1)
          fprintf (file, "; dies in %d places", REG_N_DEATHS (i));
        if (REG_N_CALLS_CROSSED (i) == 1)
@@ -5725,7 +6354,7 @@ dump_flow_info (file)
                       reg_class_names[(int) class],
                       reg_class_names[(int) altclass]);
          }
-       if (REGNO_POINTER_FLAG (i))
+       if (REG_POINTER (regno_reg_rtx[i]))
          fprintf (file, "; pointer");
        fprintf (file, ".\n");
       }
@@ -5740,11 +6369,11 @@ dump_flow_info (file)
               i, INSN_UID (bb->head), INSN_UID (bb->end), bb->loop_depth, bb->count);
 
       fprintf (file, "Predecessors: ");
-      for (e = bb->pred; e ; e = e->pred_next)
+      for (e = bb->pred; e; e = e->pred_next)
        dump_edge_info (file, e, 0);
 
       fprintf (file, "\nSuccessors: ");
-      for (e = bb->succ; e ; e = e->succ_next)
+      for (e = bb->succ; e; e = e->succ_next)
        dump_edge_info (file, e, 1);
 
       fprintf (file, "\nRegisters live at start:");
@@ -5753,10 +6382,10 @@ dump_flow_info (file)
       fprintf (file, "\nRegisters live at end:");
       dump_regset (bb->global_live_at_end, file);
 
-      putc('\n', file);
+      putc ('\n', file);
     }
 
-  putc('\n', file);
+  putc ('\n', file);
 }
 
 void
@@ -5800,7 +6429,7 @@ dump_edge_info (file, e, do_succ)
 
            if (comma)
              fputc (',', file);
-           if (i < (int)(sizeof (bitnames) / sizeof (*bitnames)))
+           if (i < (int) ARRAY_SIZE (bitnames))
              fputs (bitnames[i], file);
            else
              fprintf (file, "%d", i);
@@ -5809,9 +6438,9 @@ dump_edge_info (file, e, do_succ)
       fputc (')', file);
     }
 }
-
 \f
 /* Print out one basic block with live information at start and end.  */
+
 void
 dump_bb (bb, outf)
      basic_block bb;
@@ -5828,7 +6457,7 @@ dump_bb (bb, outf)
   putc ('\n', outf);
 
   fputs (";; Predecessors: ", outf);
-  for (e = bb->pred; e ; e = e->pred_next)
+  for (e = bb->pred; e; e = e->pred_next)
     dump_edge_info (outf, e, 0);
   putc ('\n', outf);
 
@@ -5862,7 +6491,7 @@ void
 debug_bb_n (n)
      int n;
 {
-  dump_bb (BASIC_BLOCK(n), stderr);
+  dump_bb (BASIC_BLOCK (n), stderr);
 }
 
 /* Like print_rtl, but also print out live information for the start of each
@@ -5899,9 +6528,9 @@ print_rtl_with_bb (outf, rtx_first)
          for (x = bb->head; x != NULL_RTX; x = NEXT_INSN (x))
            {
              enum bb_state state = IN_MULTIPLE_BB;
-             if (in_bb_p[INSN_UID(x)] == NOT_IN_BB)
+             if (in_bb_p[INSN_UID (x)] == NOT_IN_BB)
                state = IN_ONE_BB;
-             in_bb_p[INSN_UID(x)] = state;
+             in_bb_p[INSN_UID (x)] = state;
 
              if (x == bb->end)
                break;
@@ -5921,11 +6550,11 @@ print_rtl_with_bb (outf, rtx_first)
              putc ('\n', outf);
            }
 
-         if (in_bb_p[INSN_UID(tmp_rtx)] == NOT_IN_BB
+         if (in_bb_p[INSN_UID (tmp_rtx)] == NOT_IN_BB
              && GET_CODE (tmp_rtx) != NOTE
              && GET_CODE (tmp_rtx) != BARRIER)
            fprintf (outf, ";; Insn is not within a basic block\n");
-         else if (in_bb_p[INSN_UID(tmp_rtx)] == IN_MULTIPLE_BB)
+         else if (in_bb_p[INSN_UID (tmp_rtx)] == IN_MULTIPLE_BB)
            fprintf (outf, ";; Insn is in multiple basic blocks\n");
 
          did_output = print_rtl_single (outf, tmp_rtx);
@@ -5956,276 +6585,58 @@ print_rtl_with_bb (outf, rtx_first)
     }
 }
 
-/* Compute dominator relationships using new flow graph structures.  */
-void
-compute_flow_dominators (dominators, post_dominators)
-     sbitmap *dominators;
-     sbitmap *post_dominators;
+/* Dump the rtl into the current debugging dump file, then abort.  */
+static void
+print_rtl_and_abort ()
 {
-  int bb;
-  sbitmap *temp_bitmap;
-  edge e;
-  basic_block *worklist, *workend, *qin, *qout;
-  int qlen;
-
-  /* Allocate a worklist array/queue.  Entries are only added to the
-     list if they were not already on the list.  So the size is
-     bounded by the number of basic blocks.  */
-  worklist = (basic_block *) xmalloc (sizeof (basic_block) * n_basic_blocks);
-  workend = &worklist[n_basic_blocks];
+  if (rtl_dump_file)
+    {
+      print_rtl_with_bb (rtl_dump_file, get_insns ());
+      fclose (rtl_dump_file);
+    }
+  abort ();
+}
 
-  temp_bitmap = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
-  sbitmap_vector_zero (temp_bitmap, n_basic_blocks);
+/* Recompute register set/reference counts immediately prior to register
+   allocation.
 
-  if (dominators)
-    {
-      /* The optimistic setting of dominators requires us to put every
-        block on the work list initially.  */
-      qin = qout = worklist;
-      for (bb = 0; bb < n_basic_blocks; bb++)
-       {
-         *qin++ = BASIC_BLOCK (bb);
-         BASIC_BLOCK (bb)->aux = BASIC_BLOCK (bb);
-       }
-      qlen = n_basic_blocks;
-      qin = worklist;
+   This avoids problems with set/reference counts changing to/from values
+   which have special meanings to the register allocators.
 
-      /* We want a maximal solution, so initially assume everything dominates
-        everything else.  */
-      sbitmap_vector_ones (dominators, n_basic_blocks);
+   Additionally, the reference counts are the primary component used by the
+   register allocators to prioritize pseudos for allocation to hard regs.
+   More accurate reference counts generally lead to better register allocation.
 
-      /* Mark successors of the entry block so we can identify them below.  */
-      for (e = ENTRY_BLOCK_PTR->succ; e; e = e->succ_next)
-       e->dest->aux = ENTRY_BLOCK_PTR;
+   F is the first insn to be scanned.
 
-      /* Iterate until the worklist is empty.  */
-      while (qlen)
-       {
-         /* Take the first entry off the worklist.  */
-         basic_block b = *qout++;
-         if (qout >= workend)
-           qout = worklist;
-         qlen--;
-
-         bb = b->index;
-
-         /* Compute the intersection of the dominators of all the
-            predecessor blocks.
-
-            If one of the predecessor blocks is the ENTRY block, then the
-            intersection of the dominators of the predecessor blocks is
-            defined as the null set.  We can identify such blocks by the
-            special value in the AUX field in the block structure.  */
-         if (b->aux == ENTRY_BLOCK_PTR)
-           {
-             /* Do not clear the aux field for blocks which are
-                successors of the ENTRY block.  That way we we never
-                add them to the worklist again.
+   LOOP_STEP denotes how much loop_depth should be incremented per
+   loop nesting level in order to increase the ref count more for
+   references in a loop.
 
-                The intersect of dominators of the preds of this block is
-                defined as the null set.  */
-             sbitmap_zero (temp_bitmap[bb]);
-           }
-         else
-           {
-             /* Clear the aux field of this block so it can be added to
-                the worklist again if necessary.  */
-             b->aux = NULL;
-             sbitmap_intersection_of_preds (temp_bitmap[bb], dominators, bb);
-           }
+   It might be worthwhile to update REG_LIVE_LENGTH, REG_BASIC_BLOCK and
+   possibly other information which is used by the register allocators.  */
 
-         /* Make sure each block always dominates itself.  */
-         SET_BIT (temp_bitmap[bb], bb);
+void
+recompute_reg_usage (f, loop_step)
+     rtx f ATTRIBUTE_UNUSED;
+     int loop_step ATTRIBUTE_UNUSED;
+{
+  allocate_reg_life_data ();
+  update_life_info (NULL, UPDATE_LIFE_LOCAL, PROP_REG_INFO);
+}
 
-         /* If the out state of this block changed, then we need to
-            add the successors of this block to the worklist if they
-            are not already on the worklist.  */
-         if (sbitmap_a_and_b (dominators[bb], dominators[bb], temp_bitmap[bb]))
-           {
-             for (e = b->succ; e; e = e->succ_next)
-               {
-                 if (!e->dest->aux && e->dest != EXIT_BLOCK_PTR)
-                   {
-                     *qin++ = e->dest;
-                     if (qin >= workend)
-                       qin = worklist;
-                     qlen++;
+/* Optionally removes all the REG_DEAD and REG_UNUSED notes from a set of
+   blocks.  If BLOCKS is NULL, assume the universal set.  Returns a count
+   of the number of registers that died.  */
 
-                     e->dest->aux = e;
-                   }
-               }
-           }
-       }
-    }
+int
+count_or_remove_death_notes (blocks, kill)
+     sbitmap blocks;
+     int kill;
+{
+  int i, count = 0;
 
-  if (post_dominators)
-    {
-      /* The optimistic setting of dominators requires us to put every
-        block on the work list initially.  */
-      qin = qout = worklist;
-      for (bb = 0; bb < n_basic_blocks; bb++)
-       {
-         *qin++ = BASIC_BLOCK (bb);
-         BASIC_BLOCK (bb)->aux = BASIC_BLOCK (bb);
-       }
-      qlen = n_basic_blocks;
-      qin = worklist;
-
-      /* We want a maximal solution, so initially assume everything post
-        dominates everything else.  */
-      sbitmap_vector_ones (post_dominators, n_basic_blocks);
-
-      /* Mark predecessors of the exit block so we can identify them below.  */
-      for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
-       e->src->aux = EXIT_BLOCK_PTR;
-
-      /* Iterate until the worklist is empty.  */
-      while (qlen)
-       {
-         /* Take the first entry off the worklist.  */
-         basic_block b = *qout++;
-         if (qout >= workend)
-           qout = worklist;
-         qlen--;
-
-         bb = b->index;
-
-         /* Compute the intersection of the post dominators of all the
-            successor blocks.
-
-            If one of the successor blocks is the EXIT block, then the
-            intersection of the dominators of the successor blocks is
-            defined as the null set.  We can identify such blocks by the
-            special value in the AUX field in the block structure.  */
-         if (b->aux == EXIT_BLOCK_PTR)
-           {
-             /* Do not clear the aux field for blocks which are
-                predecessors of the EXIT block.  That way we we never
-                add them to the worklist again.
-
-                The intersect of dominators of the succs of this block is
-                defined as the null set.  */
-             sbitmap_zero (temp_bitmap[bb]);
-           }
-         else
-           {
-             /* Clear the aux field of this block so it can be added to
-                the worklist again if necessary.  */
-             b->aux = NULL;
-             sbitmap_intersection_of_succs (temp_bitmap[bb],
-                                            post_dominators, bb);
-           }
-
-         /* Make sure each block always post dominates itself.  */
-         SET_BIT (temp_bitmap[bb], bb);
-
-         /* If the out state of this block changed, then we need to
-            add the successors of this block to the worklist if they
-            are not already on the worklist.  */
-         if (sbitmap_a_and_b (post_dominators[bb],
-                              post_dominators[bb],
-                              temp_bitmap[bb]))
-           {
-             for (e = b->pred; e; e = e->pred_next)
-               {
-                 if (!e->src->aux && e->src != ENTRY_BLOCK_PTR)
-                   {
-                     *qin++ = e->src;
-                     if (qin >= workend)
-                       qin = worklist;
-                     qlen++;
-
-                     e->src->aux = e;
-                   }
-               }
-           }
-       }
-    }
-
-  free (worklist);
-  free (temp_bitmap);
-}
-
-/* Given DOMINATORS, compute the immediate dominators into IDOM.  */
-
-void
-compute_immediate_dominators (idom, dominators)
-     int *idom;
-     sbitmap *dominators;
-{
-  sbitmap *tmp;
-  int b;
-
-  tmp = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
-
-  /* Begin with tmp(n) = dom(n) - { n }.  */
-  for (b = n_basic_blocks; --b >= 0; )
-    {
-      sbitmap_copy (tmp[b], dominators[b]);
-      RESET_BIT (tmp[b], b);
-    }
-
-  /* Subtract out all of our dominator's dominators.  */
-  for (b = n_basic_blocks; --b >= 0; )
-    {
-      sbitmap tmp_b = tmp[b];
-      int s;
-
-      for (s = n_basic_blocks; --s >= 0; )
-       if (TEST_BIT (tmp_b, s))
-         sbitmap_difference (tmp_b, tmp_b, tmp[s]);
-    }
-
-  /* Find the one bit set in the bitmap and put it in the output array.  */
-  for (b = n_basic_blocks; --b >= 0; )
-    {
-      int t;
-      EXECUTE_IF_SET_IN_SBITMAP (tmp[b], 0, t, { idom[b] = t; });
-    }
-
-  sbitmap_vector_free (tmp);
-}
-
-/* Recompute register set/reference counts immediately prior to register
-   allocation.
-
-   This avoids problems with set/reference counts changing to/from values
-   which have special meanings to the register allocators.
-
-   Additionally, the reference counts are the primary component used by the
-   register allocators to prioritize pseudos for allocation to hard regs.
-   More accurate reference counts generally lead to better register allocation.
-
-   F is the first insn to be scanned.
-
-   LOOP_STEP denotes how much loop_depth should be incremented per
-   loop nesting level in order to increase the ref count more for
-   references in a loop.
-
-   It might be worthwhile to update REG_LIVE_LENGTH, REG_BASIC_BLOCK and
-   possibly other information which is used by the register allocators.  */
-
-void
-recompute_reg_usage (f, loop_step)
-     rtx f ATTRIBUTE_UNUSED;
-     int loop_step ATTRIBUTE_UNUSED;
-{
-  allocate_reg_life_data ();
-  update_life_info (NULL, UPDATE_LIFE_LOCAL, PROP_REG_INFO);
-}
-
-/* Optionally removes all the REG_DEAD and REG_UNUSED notes from a set of
-   blocks.  If BLOCKS is NULL, assume the universal set.  Returns a count
-   of the number of registers that died.  */
-
-int
-count_or_remove_death_notes (blocks, kill)
-    sbitmap blocks;
-    int kill;
-{
-  int i, count = 0;
-
-  for (i = n_basic_blocks - 1; i >= 0; --i)
+  for (i = n_basic_blocks - 1; i >= 0; --i)
     {
       basic_block bb;
       rtx insn;
@@ -6235,9 +6646,9 @@ count_or_remove_death_notes (blocks, kill)
 
       bb = BASIC_BLOCK (i);
 
-      for (insn = bb->head; ; insn = NEXT_INSN (insn))
+      for (insn = bb->head;; insn = NEXT_INSN (insn))
        {
-         if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
+         if (INSN_P (insn))
            {
              rtx *pprev = &REG_NOTES (insn);
              rtx link = *pprev;
@@ -6258,17 +6669,17 @@ count_or_remove_death_notes (blocks, kill)
                            n = HARD_REGNO_NREGS (REGNO (reg), GET_MODE (reg));
                          count += n;
                        }
-                     /* FALLTHRU */
+                     /* Fall through.  */
 
                    case REG_UNUSED:
                      if (kill)
                        {
                          rtx next = XEXP (link, 1);
                          free_EXPR_LIST_node (link);
-                         *pprev = link = next;
-                         break;
+                         *pprev = link = next;
+                         break;
                        }
-                     /* FALLTHRU */
+                     /* Fall through.  */
 
                    default:
                      pprev = &XEXP (link, 1);
@@ -6286,6 +6697,28 @@ count_or_remove_death_notes (blocks, kill)
   return count;
 }
 
+
+/* Update insns block within BB.  */
+
+void
+update_bb_for_insn (bb)
+     basic_block bb;
+{
+  rtx insn;
+
+  if (! basic_block_for_insn)
+    return;
+
+  for (insn = bb->head; ; insn = NEXT_INSN (insn))
+    {
+      set_block_for_insn (insn, bb);
+
+      if (insn == bb->end)
+       break;
+    }
+}
+
+
 /* Record INSN's block as BB.  */
 
 void
@@ -6297,7 +6730,7 @@ set_block_for_insn (insn, bb)
   if (uid >= basic_block_for_insn->num_elements)
     {
       int new_size;
-      
+
       /* Add one-eighth the size so we don't keep calling xrealloc.  */
       new_size = uid + (uid + 7) / 8;
 
@@ -6321,7 +6754,7 @@ set_block_num (insn, bb)
    aborts when something is wrong.  Hope that this function will help to
    convert many optimization passes to preserve CFG consistent.
 
-   Currently it does following checks: 
+   Currently it does following checks:
 
    - test head/end pointers
    - overlapping of basic blocks
@@ -6330,7 +6763,7 @@ set_block_num (insn, bb)
    - tails of basic blocks (ensure that boundary is necesary)
    - scans body of the basic block for JUMP_INSN, CODE_LABEL
      and NOTE_INSN_BASIC_BLOCK
-   - check that all insns are in the basic blocks 
+   - check that all insns are in the basic blocks
    (except the switch handling code, barriers and notes)
    - check that all returns are followed by barriers
 
@@ -6342,34 +6775,37 @@ verify_flow_info ()
 {
   const int max_uid = get_max_uid ();
   const rtx rtx_first = get_insns ();
+  rtx last_head = get_last_insn ();
   basic_block *bb_info;
   rtx x;
   int i, last_bb_num_seen, num_bb_notes, err = 0;
 
   bb_info = (basic_block *) xcalloc (max_uid, sizeof (basic_block));
 
-  /* First pass check head/end pointers and set bb_info array used by
-     later passes.  */
   for (i = n_basic_blocks - 1; i >= 0; i--)
     {
       basic_block bb = BASIC_BLOCK (i);
+      rtx head = bb->head;
+      rtx end = bb->end;
 
-      /* Check the head pointer and make sure that it is pointing into
-         insn list.  */
-      for (x = rtx_first; x != NULL_RTX; x = NEXT_INSN (x))
-       if (x == bb->head)
+      /* Verify the end of the basic block is in the INSN chain.  */
+      for (x = last_head; x != NULL_RTX; x = PREV_INSN (x))
+       if (x == end)
          break;
       if (!x)
        {
-         error ("Head insn %d for block %d not found in the insn stream.",
-                INSN_UID (bb->head), bb->index);
+         error ("End insn %d for block %d not found in the insn stream.",
+                INSN_UID (end), bb->index);
          err = 1;
        }
 
-      /* Check the end pointer and make sure that it is pointing into
-         insn list.  */
-      for (x = bb->head; x != NULL_RTX; x = NEXT_INSN (x))
+      /* Work backwards from the end to the head of the basic block
+        to verify the head is in the RTL chain.  */
+      for (; x != NULL_RTX; x = PREV_INSN (x))
        {
+         /* While walking over the insn chain, verify insns appear
+            in only one basic block and initialize the BB_INFO array
+            used by other passes.  */
          if (bb_info[INSN_UID (x)] != NULL)
            {
              error ("Insn %d is in multiple basic blocks (%d and %d)",
@@ -6378,15 +6814,17 @@ verify_flow_info ()
            }
          bb_info[INSN_UID (x)] = bb;
 
-         if (x == bb->end)
+         if (x == head)
            break;
        }
       if (!x)
        {
-         error ("End insn %d for block %d not found in the insn stream.",
-                INSN_UID (bb->end), bb->index);
+         error ("Head insn %d for block %d not found in the insn stream.",
+                INSN_UID (head), bb->index);
          err = 1;
        }
+
+      last_head = x;
     }
 
   /* Now check the basic blocks (boundaries etc.) */
@@ -6401,7 +6839,8 @@ verify_flow_info ()
        {
          if (e->src != bb)
            {
-             fprintf (stderr, "verify_flow_info: Basic block %d succ edge is corrupted\n",
+             fprintf (stderr,
+                      "verify_flow_info: Basic block %d succ edge is corrupted\n",
                       bb->index);
              fprintf (stderr, "Predecessor: ");
              dump_edge_info (stderr, e, 0);
@@ -6465,9 +6904,7 @@ verify_flow_info ()
            }
          x = NEXT_INSN (x);
        }
-      if (GET_CODE (x) != NOTE
-         || NOTE_LINE_NUMBER (x) != NOTE_INSN_BASIC_BLOCK
-         || NOTE_BASIC_BLOCK (x) != bb)
+      if (!NOTE_INSN_BASIC_BLOCK_P (x) || NOTE_BASIC_BLOCK (x) != bb)
        {
          error ("NOTE_INSN_BASIC_BLOCK is missing for block %d\n",
                 bb->index);
@@ -6483,8 +6920,7 @@ verify_flow_info ()
          x = NEXT_INSN (x);
          while (x)
            {
-             if (GET_CODE (x) == NOTE
-                 && NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
+             if (NOTE_INSN_BASIC_BLOCK_P (x))
                {
                  error ("NOTE_INSN_BASIC_BLOCK %d in the middle of basic block %d",
                         INSN_UID (x), bb->index);
@@ -6512,13 +6948,14 @@ verify_flow_info ()
   x = rtx_first;
   while (x)
     {
-      if (GET_CODE (x) == NOTE
-         && NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
+      if (NOTE_INSN_BASIC_BLOCK_P (x))
        {
          basic_block bb = NOTE_BASIC_BLOCK (x);
          num_bb_notes++;
          if (bb->index != last_bb_num_seen + 1)
-           fatal ("Basic blocks not numbered consecutively");
+           /* Basic blocks not numbered consecutively.  */
+           abort ();
+              
          last_bb_num_seen = bb->index;
        }
 
@@ -6548,7 +6985,7 @@ verify_flow_info ()
            }
        }
 
-      if (GET_RTX_CLASS (GET_CODE (x)) == 'i'
+      if (INSN_P (x)
          && GET_CODE (x) == JUMP_INSN
          && returnjump_p (x) && ! condjump_p (x)
          && ! (NEXT_INSN (x) && GET_CODE (NEXT_INSN (x)) == BARRIER))
@@ -6558,8 +6995,9 @@ verify_flow_info ()
     }
 
   if (num_bb_notes != n_basic_blocks)
-    fatal ("number of bb notes in insn chain (%d) != n_basic_blocks (%d)",
-          num_bb_notes, n_basic_blocks);
+    internal_error
+      ("number of bb notes in insn chain (%d) != n_basic_blocks (%d)",
+       num_bb_notes, n_basic_blocks);
 
   if (err)
     abort ();
@@ -6569,17 +7007,18 @@ verify_flow_info ()
 }
 \f
 /* Functions to access an edge list with a vector representation.
-   Enough data is kept such that given an index number, the 
-   pred and succ that edge reprsents can be determined, or
-   given a pred and a succ, it's index number can be returned.
-   This allows algorithms which comsume a lot of memory to 
+   Enough data is kept such that given an index number, the
+   pred and succ that edge represents can be determined, or
+   given a pred and a succ, its index number can be returned.
+   This allows algorithms which consume a lot of memory to
    represent the normally full matrix of edge (pred,succ) with a
    single indexed vector,  edge (EDGE_INDEX (pred, succ)), with no
    wasted space in the client code due to sparse flow graphs.  */
 
-/* This functions initializes the edge list. Basically the entire 
+/* This functions initializes the edge list. Basically the entire
    flowgraph is processed, and all edges are assigned a number,
-   and the data structure is filed in.  */
+   and the data structure is filled in.  */
+
 struct edge_list *
 create_edge_list ()
 {
@@ -6619,7 +7058,7 @@ create_edge_list ()
       elist->index_to_edge[num_edges] = e;
       num_edges++;
     }
-  
+
   for (x = 0; x < n_basic_blocks; x++)
     {
       basic_block bb = BASIC_BLOCK (x);
@@ -6635,6 +7074,7 @@ create_edge_list ()
 }
 
 /* This function free's memory associated with an edge list.  */
+
 void
 free_edge_list (elist)
      struct edge_list *elist;
@@ -6647,33 +7087,35 @@ free_edge_list (elist)
 }
 
 /* This function provides debug output showing an edge list.  */
-void 
+
+void
 print_edge_list (f, elist)
      FILE *f;
      struct edge_list *elist;
 {
   int x;
-  fprintf(f, "Compressed edge list, %d BBs + entry & exit, and %d edges\n",
-         elist->num_blocks - 2, elist->num_edges);
+  fprintf (f, "Compressed edge list, %d BBs + entry & exit, and %d edges\n",
+          elist->num_blocks - 2, elist->num_edges);
 
   for (x = 0; x < elist->num_edges; x++)
     {
       fprintf (f, " %-4d - edge(", x);
       if (INDEX_EDGE_PRED_BB (elist, x) == ENTRY_BLOCK_PTR)
-        fprintf (f,"entry,");
+       fprintf (f, "entry,");
       else
-        fprintf (f,"%d,", INDEX_EDGE_PRED_BB (elist, x)->index);
+       fprintf (f, "%d,", INDEX_EDGE_PRED_BB (elist, x)->index);
 
       if (INDEX_EDGE_SUCC_BB (elist, x) == EXIT_BLOCK_PTR)
-        fprintf (f,"exit)\n");
+       fprintf (f, "exit)\n");
       else
-        fprintf (f,"%d)\n", INDEX_EDGE_SUCC_BB (elist, x)->index);
+       fprintf (f, "%d)\n", INDEX_EDGE_SUCC_BB (elist, x)->index);
     }
 }
 
-/* This function provides an internal consistancy check of an edge list,
-   verifying that all edges are present, and that there are no 
+/* This function provides an internal consistency check of an edge list,
+   verifying that all edges are present, and that there are no
    extra edges.  */
+
 void
 verify_edge_list (f, elist)
      FILE *f;
@@ -6693,7 +7135,7 @@ verify_edge_list (f, elist)
          index = EDGE_INDEX (elist, e->src, e->dest);
          if (index == EDGE_INDEX_NO_EDGE)
            {
-             fprintf (f, "*p* No index for edge from %d to %d\n",pred, succ);
+             fprintf (f, "*p* No index for edge from %d to %d\n", pred, succ);
              continue;
            }
          if (INDEX_EDGE_PRED_BB (elist, index)->index != pred)
@@ -6711,7 +7153,7 @@ verify_edge_list (f, elist)
       index = EDGE_INDEX (elist, e->src, e->dest);
       if (index == EDGE_INDEX_NO_EDGE)
        {
-         fprintf (f, "*p* No index for edge from %d to %d\n",pred, succ);
+         fprintf (f, "*p* No index for edge from %d to %d\n", pred, succ);
          continue;
        }
       if (INDEX_EDGE_PRED_BB (elist, index)->index != pred)
@@ -6723,95 +7165,95 @@ verify_edge_list (f, elist)
     }
   /* We've verified that all the edges are in the list, no lets make sure
      there are no spurious edges in the list.  */
-  
-  for (pred = 0 ; pred < n_basic_blocks; pred++)
-    for (succ = 0 ; succ < n_basic_blocks; succ++)
+
+  for (pred = 0; pred < n_basic_blocks; pred++)
+    for (succ = 0; succ < n_basic_blocks; succ++)
       {
-        basic_block p = BASIC_BLOCK (pred);
-        basic_block s = BASIC_BLOCK (succ);
+       basic_block p = BASIC_BLOCK (pred);
+       basic_block s = BASIC_BLOCK (succ);
 
-        int found_edge = 0;
+       int found_edge = 0;
 
-        for (e = p->succ; e; e = e->succ_next)
-          if (e->dest == s)
+       for (e = p->succ; e; e = e->succ_next)
+         if (e->dest == s)
            {
              found_edge = 1;
              break;
            }
-        for (e = s->pred; e; e = e->pred_next)
-          if (e->src == p)
+       for (e = s->pred; e; e = e->pred_next)
+         if (e->src == p)
            {
              found_edge = 1;
              break;
            }
-        if (EDGE_INDEX (elist, BASIC_BLOCK (pred), BASIC_BLOCK (succ)) 
+       if (EDGE_INDEX (elist, BASIC_BLOCK (pred), BASIC_BLOCK (succ))
            == EDGE_INDEX_NO_EDGE && found_edge != 0)
          fprintf (f, "*** Edge (%d, %d) appears to not have an index\n",
-                  pred, succ);
-        if (EDGE_INDEX (elist, BASIC_BLOCK (pred), BASIC_BLOCK (succ)) 
+                  pred, succ);
+       if (EDGE_INDEX (elist, BASIC_BLOCK (pred), BASIC_BLOCK (succ))
            != EDGE_INDEX_NO_EDGE && found_edge == 0)
          fprintf (f, "*** Edge (%d, %d) has index %d, but there is no edge\n",
-                  pred, succ, EDGE_INDEX (elist, BASIC_BLOCK (pred), 
+                  pred, succ, EDGE_INDEX (elist, BASIC_BLOCK (pred),
                                           BASIC_BLOCK (succ)));
       }
-    for (succ = 0 ; succ < n_basic_blocks; succ++)
-      {
-        basic_block p = ENTRY_BLOCK_PTR;
-        basic_block s = BASIC_BLOCK (succ);
+  for (succ = 0; succ < n_basic_blocks; succ++)
+    {
+      basic_block p = ENTRY_BLOCK_PTR;
+      basic_block s = BASIC_BLOCK (succ);
 
-        int found_edge = 0;
+      int found_edge = 0;
 
-        for (e = p->succ; e; e = e->succ_next)
-          if (e->dest == s)
-           {
-             found_edge = 1;
-             break;
-           }
-        for (e = s->pred; e; e = e->pred_next)
-          if (e->src == p)
-           {
-             found_edge = 1;
-             break;
-           }
-        if (EDGE_INDEX (elist, ENTRY_BLOCK_PTR, BASIC_BLOCK (succ)) 
-           == EDGE_INDEX_NO_EDGE && found_edge != 0)
-         fprintf (f, "*** Edge (entry, %d) appears to not have an index\n",
-                  succ);
-        if (EDGE_INDEX (elist, ENTRY_BLOCK_PTR, BASIC_BLOCK (succ)) 
-           != EDGE_INDEX_NO_EDGE && found_edge == 0)
-         fprintf (f, "*** Edge (entry, %d) has index %d, but no edge exists\n",
-                  succ, EDGE_INDEX (elist, ENTRY_BLOCK_PTR, 
-                                    BASIC_BLOCK (succ)));
-      }
-    for (pred = 0 ; pred < n_basic_blocks; pred++)
-      {
-        basic_block p = BASIC_BLOCK (pred);
-        basic_block s = EXIT_BLOCK_PTR;
+      for (e = p->succ; e; e = e->succ_next)
+       if (e->dest == s)
+         {
+           found_edge = 1;
+           break;
+         }
+      for (e = s->pred; e; e = e->pred_next)
+       if (e->src == p)
+         {
+           found_edge = 1;
+           break;
+         }
+      if (EDGE_INDEX (elist, ENTRY_BLOCK_PTR, BASIC_BLOCK (succ))
+         == EDGE_INDEX_NO_EDGE && found_edge != 0)
+       fprintf (f, "*** Edge (entry, %d) appears to not have an index\n",
+                succ);
+      if (EDGE_INDEX (elist, ENTRY_BLOCK_PTR, BASIC_BLOCK (succ))
+         != EDGE_INDEX_NO_EDGE && found_edge == 0)
+       fprintf (f, "*** Edge (entry, %d) has index %d, but no edge exists\n",
+                succ, EDGE_INDEX (elist, ENTRY_BLOCK_PTR,
+                                  BASIC_BLOCK (succ)));
+    }
+  for (pred = 0; pred < n_basic_blocks; pred++)
+    {
+      basic_block p = BASIC_BLOCK (pred);
+      basic_block s = EXIT_BLOCK_PTR;
 
-        int found_edge = 0;
+      int found_edge = 0;
 
-        for (e = p->succ; e; e = e->succ_next)
-          if (e->dest == s)
-           {
-             found_edge = 1;
-             break;
-           }
-        for (e = s->pred; e; e = e->pred_next)
-          if (e->src == p)
-           {
-             found_edge = 1;
-             break;
-           }
-        if (EDGE_INDEX (elist, BASIC_BLOCK (pred), EXIT_BLOCK_PTR) 
-           == EDGE_INDEX_NO_EDGE && found_edge != 0)
-         fprintf (f, "*** Edge (%d, exit) appears to not have an index\n",
-                  pred);
-        if (EDGE_INDEX (elist, BASIC_BLOCK (pred), EXIT_BLOCK_PTR) 
-           != EDGE_INDEX_NO_EDGE && found_edge == 0)
-         fprintf (f, "*** Edge (%d, exit) has index %d, but no edge exists\n",
-                  pred, EDGE_INDEX (elist, BASIC_BLOCK (pred), 
-                                    EXIT_BLOCK_PTR));
-      }
+      for (e = p->succ; e; e = e->succ_next)
+       if (e->dest == s)
+         {
+           found_edge = 1;
+           break;
+         }
+      for (e = s->pred; e; e = e->pred_next)
+       if (e->src == p)
+         {
+           found_edge = 1;
+           break;
+         }
+      if (EDGE_INDEX (elist, BASIC_BLOCK (pred), EXIT_BLOCK_PTR)
+         == EDGE_INDEX_NO_EDGE && found_edge != 0)
+       fprintf (f, "*** Edge (%d, exit) appears to not have an index\n",
+                pred);
+      if (EDGE_INDEX (elist, BASIC_BLOCK (pred), EXIT_BLOCK_PTR)
+         != EDGE_INDEX_NO_EDGE && found_edge == 0)
+       fprintf (f, "*** Edge (%d, exit) has index %d, but no edge exists\n",
+                pred, EDGE_INDEX (elist, BASIC_BLOCK (pred),
+                                  EXIT_BLOCK_PTR));
+    }
 }
 
 /* This routine will determine what, if any, edge there is between
@@ -6833,6 +7275,7 @@ find_edge_index (edge_list, pred, succ)
 }
 
 /* This function will remove an edge from the flow graph.  */
+
 void
 remove_edge (e)
      edge e;
@@ -6870,12 +7313,13 @@ remove_edge (e)
 /* This routine will remove any fake successor edges for a basic block.
    When the edge is removed, it is also removed from whatever predecessor
    list it is in.  */
+
 static void
 remove_fake_successors (bb)
      basic_block bb;
 {
   edge e;
-  for (e = bb->succ; e ; )
+  for (e = bb->succ; e;)
     {
       edge tmp = e;
       e = e->succ_next;
@@ -6887,6 +7331,7 @@ remove_fake_successors (bb)
 /* This routine will remove all fake edges from the flow graph.  If
    we remove all fake successors, it will automatically remove all
    fake predecessors.  */
+
 void
 remove_fake_edges ()
 {
@@ -6899,9 +7344,10 @@ remove_fake_edges ()
   remove_fake_successors (ENTRY_BLOCK_PTR);
 }
 
-/* This functions will add a fake edge between any block which has no
+/* This function will add a fake edge between any block which has no
    successors, and the exit block. Some data flow equations require these
    edges to exist.  */
+
 void
 add_noreturn_fake_exit_edges ()
 {
@@ -6912,6 +7358,44 @@ add_noreturn_fake_exit_edges ()
       make_edge (NULL, BASIC_BLOCK (x), EXIT_BLOCK_PTR, EDGE_FAKE);
 }
 
+/* This function adds a fake edge between any infinite loops to the
+   exit block.  Some optimizations require a path from each node to
+   the exit node.
+
+   See also Morgan, Figure 3.10, pp. 82-83.
+
+   The current implementation is ugly, not attempting to minimize the
+   number of inserted fake edges.  To reduce the number of fake edges
+   to insert, add fake edges from _innermost_ loops containing only
+   nodes not reachable from the exit block.  */
+
+void
+connect_infinite_loops_to_exit ()
+{
+  basic_block unvisited_block;
+
+  /* Perform depth-first search in the reverse graph to find nodes
+     reachable from the exit block.  */
+  struct depth_first_search_dsS dfs_ds;
+
+  flow_dfs_compute_reverse_init (&dfs_ds);
+  flow_dfs_compute_reverse_add_bb (&dfs_ds, EXIT_BLOCK_PTR);
+
+  /* Repeatedly add fake edges, updating the unreachable nodes.  */
+  while (1)
+    {
+      unvisited_block = flow_dfs_compute_reverse_execute (&dfs_ds);
+      if (!unvisited_block)
+       break;
+      make_edge (NULL, unvisited_block, EXIT_BLOCK_PTR, EDGE_FAKE);
+      flow_dfs_compute_reverse_add_bb (&dfs_ds, unvisited_block);
+    }
+
+  flow_dfs_compute_reverse_finish (&dfs_ds);
+
+  return;
+}
+
 /* Redirect an edge's successor from one block to another.  */
 
 void
@@ -6922,7 +7406,7 @@ redirect_edge_succ (e, new_succ)
   edge *pe;
 
   /* Disconnect the edge from the old successor block.  */
-  for (pe = &e->dest->pred; *pe != e ; pe = &(*pe)->pred_next)
+  for (pe = &e->dest->pred; *pe != e; pe = &(*pe)->pred_next)
     continue;
   *pe = (*pe)->pred_next;
 
@@ -6942,7 +7426,7 @@ redirect_edge_pred (e, new_pred)
   edge *pe;
 
   /* Disconnect the edge from the old predecessor block.  */
-  for (pe = &e->src->succ; *pe != e ; pe = &(*pe)->succ_next)
+  for (pe = &e->src->succ; *pe != e; pe = &(*pe)->succ_next)
     continue;
   *pe = (*pe)->succ_next;
 
@@ -6953,7 +7437,8 @@ redirect_edge_pred (e, new_pred)
 }
 \f
 /* Dump the list of basic blocks in the bitmap NODES.  */
-static void 
+
+static void
 flow_nodes_print (str, nodes, file)
      const char *str;
      const sbitmap nodes;
@@ -6961,30 +7446,39 @@ flow_nodes_print (str, nodes, file)
 {
   int node;
 
+  if (! nodes)
+    return;
+
   fprintf (file, "%s { ", str);
   EXECUTE_IF_SET_IN_SBITMAP (nodes, 0, node, {fprintf (file, "%d ", node);});
   fputs ("}\n", file);
 }
 
 
-/* Dump the list of exiting edges in the array EDGES.  */
-static void 
-flow_exits_print (str, edges, num_edges, file)
+/* Dump the list of edges in the array EDGE_LIST.  */
+
+static void
+flow_edge_list_print (str, edge_list, num_edges, file)
      const char *str;
-     const edge *edges;
+     const edge *edge_list;
      int num_edges;
      FILE *file;
 {
   int i;
 
+  if (! edge_list)
+    return;
+
   fprintf (file, "%s { ", str);
   for (i = 0; i < num_edges; i++)
-    fprintf (file, "%d->%d ", edges[i]->src->index, edges[i]->dest->index);
+    fprintf (file, "%d->%d ", edge_list[i]->src->index,
+            edge_list[i]->dest->index);
   fputs ("}\n", file);
 }
 
 
 /* Dump loop related CFG information.  */
+
 static void
 flow_loops_cfg_dump (loops, file)
      const struct loops *loops;
@@ -7002,10 +7496,9 @@ flow_loops_cfg_dump (loops, file)
       fprintf (file, ";; %d succs { ", i);
       for (succ = BASIC_BLOCK (i)->succ; succ; succ = succ->succ_next)
        fprintf (file, "%d ", succ->dest->index);
-      flow_nodes_print ("} dom", loops->cfg.dom[i], file);     
+      flow_nodes_print ("} dom", loops->cfg.dom[i], file);
     }
 
-
   /* Dump the DFS node order.  */
   if (loops->cfg.dfs_order)
     {
@@ -7014,10 +7507,18 @@ flow_loops_cfg_dump (loops, file)
        fprintf (file, "%d ", loops->cfg.dfs_order[i]);
       fputs ("\n", file);
     }
+  /* Dump the reverse completion node order.  */
+  if (loops->cfg.rc_order)
+    {
+      fputs (";; RC order: ", file);
+      for (i = 0; i < n_basic_blocks; i++)
+       fprintf (file, "%d ", loops->cfg.rc_order[i]);
+      fputs ("\n", file);
+    }
 }
 
-
 /* Return non-zero if the nodes of LOOP are a subset of OUTER.  */
+
 static int
 flow_loop_nested_p (outer, loop)
      struct loop *outer;
@@ -7027,11 +7528,54 @@ flow_loop_nested_p (outer, loop)
 }
 
 
-/* Dump the loop information specified by LOOPS to the stream FILE.  */
-void 
-flow_loops_dump (loops, file, verbose)
+/* Dump the loop information specified by LOOP to the stream FILE
+   using auxiliary dump callback function LOOP_DUMP_AUX if non null.  */
+void
+flow_loop_dump (loop, file, loop_dump_aux, verbose)
+     const struct loop *loop;
+     FILE *file;
+     void (*loop_dump_aux) PARAMS((const struct loop *, FILE *, int));
+     int verbose;
+{
+  if (! loop || ! loop->header)
+    return;
+
+  fprintf (file, ";;\n;; Loop %d (%d to %d):%s%s\n",
+          loop->num, INSN_UID (loop->first->head),
+          INSN_UID (loop->last->end),
+          loop->shared ? " shared" : "",
+          loop->invalid ? " invalid" : "");
+  fprintf (file, ";;  header %d, latch %d, pre-header %d, first %d, last %d\n",
+          loop->header->index, loop->latch->index,
+          loop->pre_header ? loop->pre_header->index : -1,
+          loop->first->index, loop->last->index);
+  fprintf (file, ";;  depth %d, level %d, outer %ld\n",
+          loop->depth, loop->level,
+          (long) (loop->outer ? loop->outer->num : -1));
+
+  if (loop->pre_header_edges)
+    flow_edge_list_print (";;  pre-header edges", loop->pre_header_edges,
+                         loop->num_pre_header_edges, file);
+  flow_edge_list_print (";;  entry edges", loop->entry_edges,
+                       loop->num_entries, file);
+  fprintf (file, ";;  %d", loop->num_nodes);
+  flow_nodes_print (" nodes", loop->nodes, file);
+  flow_edge_list_print (";;  exit edges", loop->exit_edges,
+                       loop->num_exits, file);
+  if (loop->exits_doms)
+    flow_nodes_print (";;  exit doms", loop->exits_doms, file);
+  if (loop_dump_aux)
+    loop_dump_aux (loop, file, verbose);
+}
+
+
+/* Dump the loop information specified by LOOPS to the stream FILE,
+   using auxiliary dump callback function LOOP_DUMP_AUX if non null.  */
+void
+flow_loops_dump (loops, file, loop_dump_aux, verbose)
      const struct loops *loops;
      FILE *file;
+     void (*loop_dump_aux) PARAMS((const struct loop *, FILE *, int));
      int verbose;
 {
   int i;
@@ -7041,23 +7585,14 @@ flow_loops_dump (loops, file, verbose)
   if (! num_loops || ! file)
     return;
 
-  fprintf (file, ";; %d loops found, %d levels\n", 
+  fprintf (file, ";; %d loops found, %d levels\n",
           num_loops, loops->levels);
 
   for (i = 0; i < num_loops; i++)
     {
       struct loop *loop = &loops->array[i];
 
-      fprintf (file, ";; loop %d (%d to %d):\n;;   header %d, latch %d, pre-header %d, depth %d, level %d, outer %ld\n",
-              i, INSN_UID (loop->header->head), INSN_UID (loop->latch->end),
-              loop->header->index, loop->latch->index,
-              loop->pre_header ? loop->pre_header->index : -1, 
-              loop->depth, loop->level,
-              (long) (loop->outer ? (loop->outer - loops->array) : -1));
-      fprintf (file, ";;   %d", loop->num_nodes);
-      flow_nodes_print (" nodes", loop->nodes, file);
-      fprintf (file, ";;   %d", loop->num_exits);
-      flow_exits_print (" exits", loop->exits, loop->num_exits, file);
+      flow_loop_dump (loop, file, loop_dump_aux, verbose);
 
       if (loop->shared)
        {
@@ -7079,28 +7614,13 @@ flow_loops_dump (loops, file, verbose)
                     must be disjoint.  */
                  disjoint = ! flow_loop_nested_p (smaller ? loop : oloop,
                                                   smaller ? oloop : loop);
-                 fprintf (file, ";; loop header %d shared by loops %d, %d %s\n",
+                 fprintf (file,
+                          ";; loop header %d shared by loops %d, %d %s\n",
                           loop->header->index, i, j,
                           disjoint ? "disjoint" : "nested");
                }
            }
        }
-
-      if (verbose)
-       {
-         /* Print diagnostics to compare our concept of a loop with
-            what the loop notes say.  */
-         if (GET_CODE (PREV_INSN (loop->first->head)) != NOTE
-             || NOTE_LINE_NUMBER (PREV_INSN (loop->first->head))
-             != NOTE_INSN_LOOP_BEG)
-           fprintf (file, ";; No NOTE_INSN_LOOP_BEG at %d\n", 
-                    INSN_UID (PREV_INSN (loop->first->head)));
-         if (GET_CODE (NEXT_INSN (loop->last->end)) != NOTE
-             || NOTE_LINE_NUMBER (NEXT_INSN (loop->last->end))
-             != NOTE_INSN_LOOP_END)
-           fprintf (file, ";; No NOTE_INSN_LOOP_END at %d\n",
-                    INSN_UID (NEXT_INSN (loop->last->end)));
-       }
     }
 
   if (verbose)
@@ -7109,9 +7629,10 @@ flow_loops_dump (loops, file, verbose)
 
 
 /* Free all the memory allocated for LOOPS.  */
-void 
+
+void
 flow_loops_free (loops)
-       struct loops *loops;
+     struct loops *loops;
 {
   if (loops->array)
     {
@@ -7124,47 +7645,98 @@ flow_loops_free (loops)
       for (i = 0; i < loops->num; i++)
        {
          struct loop *loop = &loops->array[i];
-         
+
+         if (loop->pre_header_edges)
+           free (loop->pre_header_edges);
          if (loop->nodes)
            sbitmap_free (loop->nodes);
-         if (loop->exits)
-           free (loop->exits);
+         if (loop->entry_edges)
+           free (loop->entry_edges);
+         if (loop->exit_edges)
+           free (loop->exit_edges);
+         if (loop->exits_doms)
+           sbitmap_free (loop->exits_doms);
        }
       free (loops->array);
       loops->array = NULL;
-      
+
       if (loops->cfg.dom)
        sbitmap_vector_free (loops->cfg.dom);
       if (loops->cfg.dfs_order)
        free (loops->cfg.dfs_order);
 
-      sbitmap_free (loops->shared_headers);
+      if (loops->shared_headers)
+       sbitmap_free (loops->shared_headers);
     }
 }
 
 
-/* Find the exits from the loop using the bitmap of loop nodes NODES
-   and store in EXITS array.  Return the number of exits from the
-   loop.  */
+/* Find the entry edges into the loop with header HEADER and nodes
+   NODES and store in ENTRY_EDGES array.  Return the number of entry
+   edges from the loop.  */
+
+static int
+flow_loop_entry_edges_find (header, nodes, entry_edges)
+     basic_block header;
+     const sbitmap nodes;
+     edge **entry_edges;
+{
+  edge e;
+  int num_entries;
+
+  *entry_edges = NULL;
+
+  num_entries = 0;
+  for (e = header->pred; e; e = e->pred_next)
+    {
+      basic_block src = e->src;
+
+      if (src == ENTRY_BLOCK_PTR || ! TEST_BIT (nodes, src->index))
+       num_entries++;
+    }
+
+  if (! num_entries)
+    abort ();
+
+  *entry_edges = (edge *) xmalloc (num_entries * sizeof (edge *));
+
+  num_entries = 0;
+  for (e = header->pred; e; e = e->pred_next)
+    {
+      basic_block src = e->src;
+
+      if (src == ENTRY_BLOCK_PTR || ! TEST_BIT (nodes, src->index))
+       (*entry_edges)[num_entries++] = e;
+    }
+
+  return num_entries;
+}
+
+
+/* Find the exit edges from the loop using the bitmap of loop nodes
+   NODES and store in EXIT_EDGES array.  Return the number of
+   exit edges from the loop.  */
+
 static int
-flow_loop_exits_find (nodes, exits)
+flow_loop_exit_edges_find (nodes, exit_edges)
      const sbitmap nodes;
-     edge **exits;
+     edge **exit_edges;
 {
   edge e;
   int node;
   int num_exits;
 
-  *exits = NULL;
+  *exit_edges = NULL;
 
   /* Check all nodes within the loop to see if there are any
      successors not in the loop.  Note that a node may have multiple
-     exiting edges.  */
+     exiting edges ?????  A node can have one jumping edge and one fallthru
+     edge so only one of these can exit the loop.  */
   num_exits = 0;
   EXECUTE_IF_SET_IN_SBITMAP (nodes, 0, node, {
     for (e = BASIC_BLOCK (node)->succ; e; e = e->succ_next)
       {
-       basic_block dest = e->dest;       
+       basic_block dest = e->dest;
 
        if (dest == EXIT_BLOCK_PTR || ! TEST_BIT (nodes, dest->index))
            num_exits++;
@@ -7174,17 +7746,17 @@ flow_loop_exits_find (nodes, exits)
   if (! num_exits)
     return 0;
 
-  *exits = (edge *) xmalloc (num_exits * sizeof (edge *));
+  *exit_edges = (edge *) xmalloc (num_exits * sizeof (edge *));
 
   /* Store all exiting edges into an array.  */
   num_exits = 0;
   EXECUTE_IF_SET_IN_SBITMAP (nodes, 0, node, {
     for (e = BASIC_BLOCK (node)->succ; e; e = e->succ_next)
       {
-       basic_block dest = e->dest;       
+       basic_block dest = e->dest;
 
        if (dest == EXIT_BLOCK_PTR || ! TEST_BIT (nodes, dest->index))
-         (*exits)[num_exits++] = e;
+         (*exit_edges)[num_exits++] = e;
       }
   });
 
@@ -7195,7 +7767,8 @@ flow_loop_exits_find (nodes, exits)
 /* Find the nodes contained within the loop with header HEADER and
    latch LATCH and store in NODES.  Return the number of nodes within
    the loop.  */
-static int 
+
+static int
 flow_loop_nodes_find (header, latch, nodes)
      basic_block header;
      basic_block latch;
@@ -7232,7 +7805,7 @@ flow_loop_nodes_find (header, latch, nodes)
       for (e = node->pred; e; e = e->pred_next)
        {
          basic_block ancestor = e->src;
-         
+
          /* If each ancestor not marked as part of loop, add to set of
             loop nodes and push on to stack.  */
          if (ancestor != ENTRY_BLOCK_PTR
@@ -7249,18 +7822,22 @@ flow_loop_nodes_find (header, latch, nodes)
   return num_nodes;
 }
 
-
 /* Compute the depth first search order and store in the array
-   DFS_ORDER, marking the nodes visited in VISITED.  Returns the
-   number of nodes visited.  A depth first search tries to get as far
-   away from the starting point as quickly as possible.  */
+  DFS_ORDER if non-zero, marking the nodes visited in VISITED.  If
+  RC_ORDER is non-zero, return the reverse completion number for each
+  node.  Returns the number of nodes visited.  A depth first search
+  tries to get as far away from the starting point as quickly as
+  possible.  */
+
 static int
-flow_depth_first_order_compute (dfs_order)
+flow_depth_first_order_compute (dfs_order, rc_order)
      int *dfs_order;
+     int *rc_order;
 {
   edge *stack;
   int sp;
   int dfsnum = 0;
+  int rcnum = n_basic_blocks - 1;
   sbitmap visited;
 
   /* Allocate stack for back-tracking up CFG.  */
@@ -7272,7 +7849,7 @@ flow_depth_first_order_compute (dfs_order)
 
   /* None of the nodes in the CFG have been visited yet.  */
   sbitmap_zero (visited);
-  
+
   /* Push the first edge on to the stack.  */
   stack[sp++] = ENTRY_BLOCK_PTR->succ;
 
@@ -7286,35 +7863,40 @@ flow_depth_first_order_compute (dfs_order)
       e = stack[sp - 1];
       src = e->src;
       dest = e->dest;
-      
+
       /* Check if the edge destination has been visited yet.  */
       if (dest != EXIT_BLOCK_PTR && ! TEST_BIT (visited, dest->index))
        {
          /* Mark that we have visited the destination.  */
          SET_BIT (visited, dest->index);
 
-         if (dest->succ)
-           {
-             /* Since the DEST node has been visited for the first
-                time, check its successors.  */
-             stack[sp++] = dest->succ;
-           }
-         else
-           {
-             /* There are no successors for the DEST node so assign
-                its DFS number.  */
-             dfs_order[n_basic_blocks - ++dfsnum] = dest->index;
-           }
+         if (dfs_order)
+           dfs_order[dfsnum++] = dest->index;
+
+         if (dest->succ)
+           {
+             /* Since the DEST node has been visited for the first
+                time, check its successors.  */
+             stack[sp++] = dest->succ;
+           }
+         else
+           {
+             /* There are no successors for the DEST node so assign
+                its reverse completion number.  */
+             if (rc_order)
+               rc_order[rcnum--] = dest->index;
+           }
        }
       else
        {
          if (! e->succ_next && src != ENTRY_BLOCK_PTR)
-           {
-             /* There are no more successors for the SRC node
-                so assign its DFS number.  */
-             dfs_order[n_basic_blocks - ++dfsnum] = src->index;
-           }
-         
+           {
+             /* There are no more successors for the SRC node
+                so assign its reverse completion number.  */
+             if (rc_order)
+               rc_order[rcnum--] = src->index;
+           }
+
          if (e->succ_next)
            stack[sp - 1] = e->succ_next;
          else
@@ -7336,14 +7918,170 @@ flow_depth_first_order_compute (dfs_order)
   return dfsnum;
 }
 
+/* Compute the depth first search order on the _reverse_ graph and
+   store in the array DFS_ORDER, marking the nodes visited in VISITED.
+   Returns the number of nodes visited.
+
+   The computation is split into three pieces:
+
+   flow_dfs_compute_reverse_init () creates the necessary data
+   structures.
+
+   flow_dfs_compute_reverse_add_bb () adds a basic block to the data
+   structures.  The block will start the search.
+
+   flow_dfs_compute_reverse_execute () continues (or starts) the
+   search using the block on the top of the stack, stopping when the
+   stack is empty.
+
+   flow_dfs_compute_reverse_finish () destroys the necessary data
+   structures.
+
+   Thus, the user will probably call ..._init(), call ..._add_bb() to
+   add a beginning basic block to the stack, call ..._execute(),
+   possibly add another bb to the stack and again call ..._execute(),
+   ..., and finally call _finish().  */
+
+/* Initialize the data structures used for depth-first search on the
+   reverse graph.  If INITIALIZE_STACK is nonzero, the exit block is
+   added to the basic block stack.  DATA is the current depth-first
+   search context.  If INITIALIZE_STACK is non-zero, there is an
+   element on the stack.  */
+
+static void
+flow_dfs_compute_reverse_init (data)
+     depth_first_search_ds data;
+{
+  /* Allocate stack for back-tracking up CFG.  */
+  data->stack =
+    (basic_block *) xmalloc ((n_basic_blocks - (INVALID_BLOCK + 1))
+                            * sizeof (basic_block));
+  data->sp = 0;
+
+  /* Allocate bitmap to track nodes that have been visited.  */
+  data->visited_blocks = sbitmap_alloc (n_basic_blocks - (INVALID_BLOCK + 1));
+
+  /* None of the nodes in the CFG have been visited yet.  */
+  sbitmap_zero (data->visited_blocks);
+
+  return;
+}
+
+/* Add the specified basic block to the top of the dfs data
+   structures.  When the search continues, it will start at the
+   block.  */
+
+static void
+flow_dfs_compute_reverse_add_bb (data, bb)
+     depth_first_search_ds data;
+     basic_block bb;
+{
+  data->stack[data->sp++] = bb;
+  return;
+}
+
+/* Continue the depth-first search through the reverse graph starting
+   with the block at the stack's top and ending when the stack is
+   empty.  Visited nodes are marked.  Returns an unvisited basic
+   block, or NULL if there is none available.  */
+
+static basic_block
+flow_dfs_compute_reverse_execute (data)
+     depth_first_search_ds data;
+{
+  basic_block bb;
+  edge e;
+  int i;
+
+  while (data->sp > 0)
+    {
+      bb = data->stack[--data->sp];
+
+      /* Mark that we have visited this node.  */
+      if (!TEST_BIT (data->visited_blocks, bb->index - (INVALID_BLOCK + 1)))
+       {
+         SET_BIT (data->visited_blocks, bb->index - (INVALID_BLOCK + 1));
+
+         /* Perform depth-first search on adjacent vertices.  */
+         for (e = bb->pred; e; e = e->pred_next)
+           flow_dfs_compute_reverse_add_bb (data, e->src);
+       }
+    }
+
+  /* Determine if there are unvisited basic blocks.  */
+  for (i = n_basic_blocks - (INVALID_BLOCK + 1); --i >= 0;)
+    if (!TEST_BIT (data->visited_blocks, i))
+      return BASIC_BLOCK (i + (INVALID_BLOCK + 1));
+  return NULL;
+}
+
+/* Destroy the data structures needed for depth-first search on the
+   reverse graph.  */
+
+static void
+flow_dfs_compute_reverse_finish (data)
+     depth_first_search_ds data;
+{
+  free (data->stack);
+  sbitmap_free (data->visited_blocks);
+  return;
+}
+
+
+/* Find the root node of the loop pre-header extended basic block and
+   the edges along the trace from the root node to the loop header.  */
+
+static void
+flow_loop_pre_header_scan (loop)
+     struct loop *loop;
+{
+  int num = 0;
+  basic_block ebb;
+
+  loop->num_pre_header_edges = 0;
+
+  if (loop->num_entries != 1)
+     return;
+
+  ebb = loop->entry_edges[0]->src;
+
+  if (ebb != ENTRY_BLOCK_PTR)
+    {
+      edge e;
+
+      /* Count number of edges along trace from loop header to
+        root of pre-header extended basic block.  Usually this is
+        only one or two edges. */
+      num++;
+      while (ebb->pred->src != ENTRY_BLOCK_PTR && ! ebb->pred->pred_next)
+       {
+         ebb = ebb->pred->src;
+         num++;
+       }
+
+      loop->pre_header_edges = (edge *) xmalloc (num * sizeof (edge *));
+      loop->num_pre_header_edges = num;
+
+      /* Store edges in order that they are followed.   The source
+        of the first edge is the root node of the pre-header extended
+        basic block and the destination of the last last edge is
+        the loop header.  */
+      for (e = loop->entry_edges[0]; num; e = e->src->pred)
+       {
+         loop->pre_header_edges[--num] = e;
+       }
+    }
+}
+
 
 /* Return the block for the pre-header of the loop with header
    HEADER where DOM specifies the dominator information.  Return NULL if
    there is no pre-header.  */
+
 static basic_block
 flow_loop_pre_header_find (header, dom)
      basic_block header;
-     const sbitmap *dom;     
+     const sbitmap *dom;
 {
   basic_block pre_header;
   edge e;
@@ -7354,7 +8092,7 @@ flow_loop_pre_header_find (header, dom)
   for (e = header->pred; e; e = e->pred_next)
     {
       basic_block node = e->src;
-      
+
       if (node != ENTRY_BLOCK_PTR
          && ! TEST_BIT (dom[node->index], header->index))
        {
@@ -7362,7 +8100,7 @@ flow_loop_pre_header_find (header, dom)
            pre_header = node;
          else
            {
-             /* There are multiple edges into the header from outside 
+             /* There are multiple edges into the header from outside
                 the loop so there is no pre-header block.  */
              pre_header = NULL;
              break;
@@ -7372,10 +8110,10 @@ flow_loop_pre_header_find (header, dom)
   return pre_header;
 }
 
-
 /* Add LOOP to the loop hierarchy tree where PREVLOOP was the loop
    previously added.  The insertion algorithm assumes that the loops
    are added in the order found by a depth first search of the CFG.  */
+
 static void
 flow_loop_tree_node_add (prevloop, loop)
      struct loop *prevloop;
@@ -7399,16 +8137,16 @@ flow_loop_tree_node_add (prevloop, loop)
        }
       prevloop = prevloop->outer;
     }
-  
+
   prevloop->next = loop;
   loop->outer = NULL;
 }
 
-
 /* Build the loop hierarchy tree for LOOPS.  */
+
 static void
 flow_loops_tree_build (loops)
-       struct loops *loops;
+     struct loops *loops;
 {
   int i;
   int num_loops;
@@ -7418,7 +8156,7 @@ flow_loops_tree_build (loops)
     return;
 
   /* Root the loop hierarchy tree with the first loop found.
-     Since we used a depth first search this should be the 
+     Since we used a depth first search this should be the
      outermost loop.  */
   loops->tree = &loops->array[0];
   loops->tree->outer = loops->tree->inner = loops->tree->next = NULL;
@@ -7428,10 +8166,10 @@ flow_loops_tree_build (loops)
     flow_loop_tree_node_add (&loops->array[i - 1], &loops->array[i]);
 }
 
-
 /* Helper function to compute loop nesting depth and enclosed loop level
-   for the natural loop specified by LOOP at the loop depth DEPTH.   
+   for the natural loop specified by LOOP at the loop depth DEPTH.
    Returns the loop level.  */
+
 static int
 flow_loop_level_compute (loop, depth)
      struct loop *loop;
@@ -7462,7 +8200,6 @@ flow_loop_level_compute (loop, depth)
   return level;
 }
 
-
 /* Compute the loop nesting depth and enclosed loop level for the loop
    hierarchy tree specfied by LOOPS.  Return the maximum enclosed loop
    level.  */
@@ -7486,13 +8223,79 @@ flow_loops_level_compute (loops)
 }
 
 
+/* Scan a single natural loop specified by LOOP collecting information
+   about it specified by FLAGS.  */
+
+int
+flow_loop_scan (loops, loop, flags)
+     struct loops *loops;
+     struct loop *loop;
+     int flags;
+{
+  /* Determine prerequisites.  */
+  if ((flags & LOOP_EXITS_DOMS) && ! loop->exit_edges)
+    flags |= LOOP_EXIT_EDGES;
+
+  if (flags & LOOP_ENTRY_EDGES)
+    {
+      /* Find edges which enter the loop header.
+        Note that the entry edges should only
+        enter the header of a natural loop.  */
+      loop->num_entries
+       = flow_loop_entry_edges_find (loop->header,
+                                     loop->nodes,
+                                     &loop->entry_edges);
+    }
+
+  if (flags & LOOP_EXIT_EDGES)
+    {
+      /* Find edges which exit the loop.  */
+      loop->num_exits
+       = flow_loop_exit_edges_find (loop->nodes,
+                                    &loop->exit_edges);
+    }
+
+  if (flags & LOOP_EXITS_DOMS)
+    {
+      int j;
+
+      /* Determine which loop nodes dominate all the exits
+        of the loop.  */
+      loop->exits_doms = sbitmap_alloc (n_basic_blocks);
+      sbitmap_copy (loop->exits_doms, loop->nodes);
+      for (j = 0; j < loop->num_exits; j++)
+       sbitmap_a_and_b (loop->exits_doms, loop->exits_doms,
+                        loops->cfg.dom[loop->exit_edges[j]->src->index]);
+      
+      /* The header of a natural loop must dominate
+        all exits.  */
+      if (! TEST_BIT (loop->exits_doms, loop->header->index))
+       abort ();
+    }
+  
+  if (flags & LOOP_PRE_HEADER)
+    {
+      /* Look to see if the loop has a pre-header node.  */
+      loop->pre_header
+       = flow_loop_pre_header_find (loop->header, loops->cfg.dom);
+
+      /* Find the blocks within the extended basic block of
+        the loop pre-header.  */
+      flow_loop_pre_header_scan (loop);
+    }
+  return 1;
+}
+
+
 /* Find all the natural loops in the function and save in LOOPS structure
    and recalculate loop_depth information in basic block structures.
+   FLAGS controls which loop information is collected.
    Return the number of natural loops found.  */
 
-int 
-flow_loops_find (loops)
-       struct loops *loops;
+int
+flow_loops_find (loops, flags)
+     struct loops *loops;
+     int flags;
 {
   int i;
   int b;
@@ -7501,57 +8304,74 @@ flow_loops_find (loops)
   sbitmap headers;
   sbitmap *dom;
   int *dfs_order;
-  
-  loops->num = 0;
-  loops->array = NULL;
-  loops->tree = NULL;
-  dfs_order = NULL;
+  int *rc_order;
+
+  /* This function cannot be repeatedly called with different
+     flags to build up the loop information.  The loop tree
+     must always be built if this function is called.  */
+  if (! (flags & LOOP_TREE))
+    abort ();
+
+  memset (loops, 0, sizeof (*loops));
 
   /* Taking care of this degenerate case makes the rest of
      this code simpler.  */
   if (n_basic_blocks == 0)
     return 0;
 
+  dfs_order = NULL;
+  rc_order = NULL;
+
   /* Compute the dominators.  */
   dom = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
-  compute_flow_dominators (dom, NULL);
+  calculate_dominance_info (NULL, dom, CDI_DOMINATORS);
 
   /* Count the number of loop edges (back edges).  This should be the
-     same as the number of natural loops.  Also clear the loop_depth
-     and as we work from inner->outer in a loop nest we call
-     find_loop_nodes_find which will increment loop_depth for nodes
-     within the current loop, which happens to enclose inner loops.  */
+     same as the number of natural loops.  */
 
   num_loops = 0;
   for (b = 0; b < n_basic_blocks; b++)
     {
-      BASIC_BLOCK (b)->loop_depth = 0;
-      for (e = BASIC_BLOCK (b)->pred; e; e = e->pred_next)
+      basic_block header;
+
+      header = BASIC_BLOCK (b);
+      header->loop_depth = 0;
+
+      for (e = header->pred; e; e = e->pred_next)
        {
          basic_block latch = e->src;
-         
+
          /* Look for back edges where a predecessor is dominated
             by this block.  A natural loop has a single entry
             node (header) that dominates all the nodes in the
             loop.  It also has single back edge to the header
             from a latch node.  Note that multiple natural loops
             may share the same header.  */
+         if (b != header->index)
+           abort ();
+
          if (latch != ENTRY_BLOCK_PTR && TEST_BIT (dom[latch->index], b))
            num_loops++;
        }
     }
-  
+
   if (num_loops)
     {
       /* Compute depth first search order of the CFG so that outer
         natural loops will be found before inner natural loops.  */
       dfs_order = (int *) xmalloc (n_basic_blocks * sizeof (int));
-      flow_depth_first_order_compute (dfs_order);
+      rc_order = (int *) xmalloc (n_basic_blocks * sizeof (int));
+      flow_depth_first_order_compute (dfs_order, rc_order);
+
+      /* Save CFG derived information to avoid recomputing it.  */
+      loops->cfg.dom = dom;
+      loops->cfg.dfs_order = dfs_order;
+      loops->cfg.rc_order = rc_order;
 
       /* Allocate loop structures.  */
       loops->array
        = (struct loop *) xcalloc (num_loops, sizeof (struct loop));
-      
+
       headers = sbitmap_alloc (n_basic_blocks);
       sbitmap_zero (headers);
 
@@ -7565,15 +8385,15 @@ flow_loops_find (loops)
        {
          basic_block header;
 
-         /* Search the nodes of the CFG in DFS order that we can find
-            outer loops first.  */
-         header = BASIC_BLOCK (dfs_order[b]);
-         
+         /* Search the nodes of the CFG in reverse completion order
+            so that we can find outer loops first.  */
+         header = BASIC_BLOCK (rc_order[b]);
+
          /* Look for all the possible latch blocks for this header.  */
          for (e = header->pred; e; e = e->pred_next)
            {
              basic_block latch = e->src;
-             
+
              /* Look for back edges where a predecessor is dominated
                 by this block.  A natural loop has a single entry
                 node (header) that dominates all the nodes in the
@@ -7584,46 +8404,45 @@ flow_loops_find (loops)
                  && TEST_BIT (dom[latch->index], header->index))
                {
                  struct loop *loop;
-                 
+
                  loop = loops->array + num_loops;
-                 
+
                  loop->header = header;
                  loop->latch = latch;
-                 
-                 /* Keep track of blocks that are loop headers so
-                    that we can tell which loops should be merged.  */
-                 if (TEST_BIT (headers, header->index))
-                   SET_BIT (loops->shared_headers, header->index);
-                 SET_BIT (headers, header->index);
-                 
-                 /* Find nodes contained within the loop.  */
-                 loop->nodes = sbitmap_alloc (n_basic_blocks);
-                 loop->num_nodes
-                   = flow_loop_nodes_find (header, latch, loop->nodes);
-
-                 /* Compute first and last blocks within the loop.
-                    These are often the same as the loop header and
-                    loop latch respectively, but this is not always
-                    the case.  */
-                 loop->first
-                   = BASIC_BLOCK (sbitmap_first_set_bit (loop->nodes));
-                 loop->last
-                   = BASIC_BLOCK (sbitmap_last_set_bit (loop->nodes)); 
-         
-                 /* Find edges which exit the loop.  Note that a node
-                    may have several exit edges.  */
-                 loop->num_exits
-                   = flow_loop_exits_find (loop->nodes, &loop->exits);
-
-                 /* Look to see if the loop has a pre-header node.  */
-                 loop->pre_header 
-                   = flow_loop_pre_header_find (header, dom);
+                 loop->num = num_loops;
 
                  num_loops++;
                }
            }
        }
-      
+
+      for (i = 0; i < num_loops; i++)
+       {
+         struct loop *loop = &loops->array[i];
+
+         /* Keep track of blocks that are loop headers so
+            that we can tell which loops should be merged.  */
+         if (TEST_BIT (headers, loop->header->index))
+           SET_BIT (loops->shared_headers, loop->header->index);
+         SET_BIT (headers, loop->header->index);
+
+         /* Find nodes contained within the loop.  */
+         loop->nodes = sbitmap_alloc (n_basic_blocks);
+         loop->num_nodes
+           = flow_loop_nodes_find (loop->header, loop->latch, loop->nodes);
+
+         /* Compute first and last blocks within the loop.
+            These are often the same as the loop header and
+            loop latch respectively, but this is not always
+            the case.  */
+         loop->first
+           = BASIC_BLOCK (sbitmap_first_set_bit (loop->nodes));
+         loop->last
+           = BASIC_BLOCK (sbitmap_last_set_bit (loop->nodes));
+
+         flow_loop_scan (loops, loop, flags);
+       }
+
       /* Natural loops with shared headers may either be disjoint or
         nested.  Disjoint loops with shared headers cannot be inner
         loops and should be merged.  For now just mark loops that share
@@ -7637,10 +8456,6 @@ flow_loops_find (loops)
 
   loops->num = num_loops;
 
-  /* Save CFG derived information to avoid recomputing it.  */
-  loops->cfg.dom = dom;
-  loops->cfg.dfs_order = dfs_order;
-
   /* Build the loop hierarchy tree.  */
   flow_loops_tree_build (loops);
 
@@ -7652,6 +8467,22 @@ flow_loops_find (loops)
 }
 
 
+/* Update the information regarding the loops in the CFG
+   specified by LOOPS.  */
+int
+flow_loops_update (loops, flags)
+     struct loops *loops;
+     int flags;
+{
+  /* One day we may want to update the current loop data.  For now
+     throw away the old stuff and rebuild what we need.  */
+  if (loops->array)
+    flow_loops_free (loops);
+
+  return flow_loops_find (loops, flags);
+}
+
+
 /* Return non-zero if edge E enters header of LOOP from outside of LOOP.  */
 
 int
@@ -7665,17 +8496,31 @@ flow_loop_outside_edge_p (loop, e)
     || ! TEST_BIT (loop->nodes, e->src->index);
 }
 
-
-/* Clear LOG_LINKS fields of insns in a chain.  */
+/* Clear LOG_LINKS fields of insns in a chain.
+   Also clear the global_live_at_{start,end} fields of the basic block
+   structures.  */
 
 void
 clear_log_links (insns)
      rtx insns;
 {
   rtx i;
+  int b;
+
   for (i = insns; i; i = NEXT_INSN (i))
-    if (GET_RTX_CLASS (GET_CODE (i)) == 'i')
+    if (INSN_P (i))
       LOG_LINKS (i) = 0;
+
+  for (b = 0; b < n_basic_blocks; b++)
+    {
+      basic_block bb = BASIC_BLOCK (b);
+
+      bb->global_live_at_start = NULL;
+      bb->global_live_at_end = NULL;
+    }
+
+  ENTRY_BLOCK_PTR->global_live_at_end = NULL;
+  EXIT_BLOCK_PTR->global_live_at_start = NULL;
 }
 
 /* Given a register bitmap, turn on the bits in a HARD_REG_SET that
@@ -7699,3 +8544,22 @@ reg_set_to_hard_reg_set (to, from)
      });
 }
 
+/* Called once at intialization time.  */
+
+void
+init_flow ()
+{
+  static int initialized;
+
+  if (!initialized)
+    {
+      gcc_obstack_init (&flow_obstack);
+      flow_firstobj = (char *) obstack_alloc (&flow_obstack, 0);
+      initialized = 1;
+    }
+  else
+    {
+      obstack_free (&flow_obstack, flow_firstobj);
+      flow_firstobj = (char *) obstack_alloc (&flow_obstack, 0);
+    }
+}