OSDN Git Service

2005-12-02 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / tree-cfg.c
index c141982..c468b64 100644 (file)
@@ -16,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -29,7 +29,6 @@ Boston, MA 02111-1307, USA.  */
 #include "hard-reg-set.h"
 #include "basic-block.h"
 #include "output.h"
-#include "errors.h"
 #include "flags.h"
 #include "function.h"
 #include "expr.h"
@@ -45,6 +44,7 @@ Boston, MA 02111-1307, USA.  */
 #include "cfgloop.h"
 #include "cfglayout.h"
 #include "hashtab.h"
+#include "tree-ssa-propagate.h"
 
 /* This file contains functions for building the Control Flow Graph (CFG)
    for a function tree.  */
@@ -94,9 +94,6 @@ static bool found_computed_goto;
 
 /* Basic blocks and flowgraphs.  */
 static basic_block create_bb (void *, void *, basic_block);
-static void create_block_annotation (basic_block);
-static void free_blocks_annotations (void);
-static void clear_blocks_annotations (void);
 static void make_blocks (tree);
 static void factor_computed_gotos (void);
 
@@ -110,27 +107,21 @@ static void make_goto_expr_edges (basic_block);
 static edge tree_redirect_edge_and_branch (edge, basic_block);
 static edge tree_try_redirect_by_replacing_jump (edge, basic_block);
 static void split_critical_edges (void);
-static bool remove_fallthru_edge (VEC(edge,gc) *);
 
 /* Various helpers.  */
 static inline bool stmt_starts_bb_p (tree, tree);
 static int tree_verify_flow_info (void);
 static void tree_make_forwarder_block (edge);
-static bool tree_forwarder_block_p (basic_block, bool);
 static void tree_cfg2vcg (FILE *);
 
 /* Flowgraph optimization and cleanup.  */
 static void tree_merge_blocks (basic_block, basic_block);
 static bool tree_can_merge_blocks_p (basic_block, basic_block);
 static void remove_bb (basic_block);
-static bool cleanup_control_flow (void);
-static bool cleanup_control_expr_graph (basic_block, block_stmt_iterator);
 static edge find_taken_edge_computed_goto (basic_block, tree);
 static edge find_taken_edge_cond_expr (basic_block, tree);
 static edge find_taken_edge_switch_expr (basic_block, tree);
 static tree find_case_label_for_value (tree, tree);
-static bool phi_alternatives_equal (basic_block, edge, edge);
-static bool cleanup_forwarder_blocks (void);
 
 void
 init_empty_tree_cfg (void)
@@ -148,9 +139,6 @@ init_empty_tree_cfg (void)
 
   ENTRY_BLOCK_PTR->next_bb = EXIT_BLOCK_PTR;
   EXIT_BLOCK_PTR->prev_bb = ENTRY_BLOCK_PTR;
-
-  create_block_annotation (ENTRY_BLOCK_PTR);
-  create_block_annotation (EXIT_BLOCK_PTR);
 }
 
 /*---------------------------------------------------------------------------
@@ -310,8 +298,8 @@ factor_computed_gotos (void)
            }
 
          /* Copy the original computed goto's destination into VAR.  */
-         assignment = build (MODIFY_EXPR, ptr_type_node,
-                             var, GOTO_DESTINATION (last));
+         assignment = build2 (MODIFY_EXPR, ptr_type_node,
+                              var, GOTO_DESTINATION (last));
          bsi_insert_before (&bsi, assignment, BSI_SAME_STMT);
 
          /* And re-vector the computed goto to the new destination.  */
@@ -321,37 +309,6 @@ factor_computed_gotos (void)
 }
 
 
-/* Create annotations for a single basic block.  */
-
-static void
-create_block_annotation (basic_block bb)
-{
-  /* Verify that the tree_annotations field is clear.  */
-  gcc_assert (!bb->tree_annotations);
-  bb->tree_annotations = ggc_alloc_cleared (sizeof (struct bb_ann_d));
-}
-
-
-/* Free the annotations for all the basic blocks.  */
-
-static void free_blocks_annotations (void)
-{
-  clear_blocks_annotations ();  
-}
-
-
-/* Clear the annotations for all the basic blocks.  */
-
-static void
-clear_blocks_annotations (void)
-{
-  basic_block bb;
-
-  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
-    bb->tree_annotations = NULL;
-}
-
-
 /* Build a flowgraph for the statement_list STMT_LIST.  */
 
 static void
@@ -430,12 +387,9 @@ create_bb (void *h, void *e, basic_block after)
   /* Add the newly created block to the array.  */
   BASIC_BLOCK (last_basic_block) = bb;
 
-  create_block_annotation (bb);
-
   n_basic_blocks++;
   last_basic_block++;
 
-  initialize_bb_rbi (bb);
   return bb;
 }
 
@@ -623,6 +577,7 @@ make_cond_expr_edges (basic_block bb)
   tree entry = last_stmt (bb);
   basic_block then_bb, else_bb;
   tree then_label, else_label;
+  edge e;
 
   gcc_assert (entry);
   gcc_assert (TREE_CODE (entry) == COND_EXPR);
@@ -633,8 +588,21 @@ make_cond_expr_edges (basic_block bb)
   then_bb = label_to_block (then_label);
   else_bb = label_to_block (else_label);
 
-  make_edge (bb, then_bb, EDGE_TRUE_VALUE);
-  make_edge (bb, else_bb, EDGE_FALSE_VALUE);
+  e = make_edge (bb, then_bb, EDGE_TRUE_VALUE);
+#ifdef USE_MAPPED_LOCATION
+  e->goto_locus = EXPR_LOCATION (COND_EXPR_THEN (entry));
+#else
+  e->goto_locus = EXPR_LOCUS (COND_EXPR_THEN (entry));
+#endif
+  e = make_edge (bb, else_bb, EDGE_FALSE_VALUE);
+  if (e)
+    {
+#ifdef USE_MAPPED_LOCATION
+      e->goto_locus = EXPR_LOCATION (COND_EXPR_ELSE (entry));
+#else
+      e->goto_locus = EXPR_LOCUS (COND_EXPR_ELSE (entry));
+#endif
+    }
 }
 
 /* Hashing routine for EDGE_TO_CASES.  */
@@ -683,7 +651,7 @@ edge_to_cases_cleanup (void *p)
 
 /* Start recording information mapping edges to case labels.  */
 
-static void
+void
 start_recording_case_labels (void)
 {
   gcc_assert (edge_to_cases == NULL);
@@ -704,7 +672,7 @@ recording_case_labels_p (void)
 
 /* Stop recording information mapping edges to case labels and
    remove any information we have recorded.  */
-static void
+void
 end_recording_case_labels (void)
 {
   htab_delete (edge_to_cases);
@@ -919,73 +887,6 @@ make_goto_expr_edges (basic_block bb)
                               Flowgraph analysis
 ---------------------------------------------------------------------------*/
 
-/* Remove unreachable blocks and other miscellaneous clean up work.  */
-
-bool
-cleanup_tree_cfg (void)
-{
-  bool retval = false;
-
-  timevar_push (TV_TREE_CLEANUP_CFG);
-
-  retval = cleanup_control_flow ();
-  retval |= delete_unreachable_blocks ();
-
-  /* cleanup_forwarder_blocks can redirect edges out of SWITCH_EXPRs,
-     which can get expensive.  So we want to enable recording of edge
-     to CASE_LABEL_EXPR mappings around the call to
-     cleanup_forwarder_blocks.  */
-  start_recording_case_labels ();
-  retval |= cleanup_forwarder_blocks ();
-  end_recording_case_labels ();
-
-#ifdef ENABLE_CHECKING
-  if (retval)
-    {
-      gcc_assert (!cleanup_control_flow ());
-      gcc_assert (!delete_unreachable_blocks ());
-      gcc_assert (!cleanup_forwarder_blocks ());
-    }
-#endif
-
-  /* Merging the blocks creates no new opportunities for the other
-     optimizations, so do it here.  */
-  retval |= merge_seq_blocks ();
-
-  compact_blocks ();
-
-#ifdef ENABLE_CHECKING
-  verify_flow_info ();
-#endif
-  timevar_pop (TV_TREE_CLEANUP_CFG);
-  return retval;
-}
-
-
-/* Cleanup cfg and repair loop structures.  */
-
-void
-cleanup_tree_cfg_loop (void)
-{
-  bitmap changed_bbs = BITMAP_ALLOC (NULL);
-
-  cleanup_tree_cfg ();
-
-  fix_loop_structure (current_loops, changed_bbs);
-  calculate_dominance_info (CDI_DOMINATORS);
-
-  /* This usually does nothing.  But sometimes parts of cfg that originally
-     were inside a loop get out of it due to edge removal (since they
-     become unreachable by back edges from latch).  */
-  rewrite_into_loop_closed_ssa (changed_bbs, TODO_update_ssa);
-
-  BITMAP_FREE (changed_bbs);
-
-#ifdef ENABLE_CHECKING
-  verify_loop_structure (current_loops);
-#endif
-}
-
 /* Cleanup useless labels in basic blocks.  This is something we wish
    to do early because it allows us to group case labels before creating
    the edges for the CFG, and it speeds up block statement iterators in
@@ -1336,8 +1237,7 @@ replace_uses_by (tree name, tree val)
   FOR_EACH_IMM_USE_SAFE (use, imm_iter, name)
     {
       stmt = USE_STMT (use);
-
-      SET_USE (use, val);
+      replace_exp (use, val);
 
       if (TREE_CODE (stmt) == PHI_NODE)
        {
@@ -1359,16 +1259,40 @@ replace_uses_by (tree name, tree val)
      x = w * w;
 
      If we performed the update in the first loop, the statement
-     would be rescanned after first occurence of w is replaced,
+     would be rescanned after first occurrence of w is replaced,
      the new uses would be placed to the beginning of the list,
      and we would never process them.  */
   for (i = 0; VEC_iterate (tree, stmts, i, stmt); i++)
     {
+      tree rhs;
+
       fold_stmt_inplace (stmt);
-      update_stmt (stmt);
+
+      rhs = get_rhs (stmt);
+      if (TREE_CODE (rhs) == ADDR_EXPR)
+       recompute_tree_invarant_for_addr_expr (rhs);
+
+      /* If the statement could throw and now cannot, we need to prune cfg.  */
+      if (maybe_clean_or_replace_eh_stmt (stmt, stmt))
+       tree_purge_dead_eh_edges (bb_for_stmt (stmt));
+
+      mark_new_vars_to_rename (stmt);
     }
 
   VEC_free (tree, heap, stmts);
+
+  /* Also update the trees stored in loop structures.  */
+  if (current_loops)
+    {
+      struct loop *loop;
+
+      for (i = 0; i < current_loops->num; i++)
+       {
+         loop = current_loops->parray[i];
+         if (loop)
+           substitute_in_loop_info (loop, name, val);
+       }
+    }
 }
 
 /* Merge block B into block A.  */
@@ -1383,22 +1307,28 @@ tree_merge_blocks (basic_block a, basic_block b)
   if (dump_file)
     fprintf (dump_file, "Merging blocks %d and %d\n", a->index, b->index);
 
-  /* Remove the phi nodes.  */
+  /* Remove all single-valued PHI nodes from block B of the form
+     V_i = PHI <V_j> by propagating V_j to all the uses of V_i.  */
   bsi = bsi_last (a);
   for (phi = phi_nodes (b); phi; phi = phi_nodes (b))
     {
       tree def = PHI_RESULT (phi), use = PHI_ARG_DEF (phi, 0);
       tree copy;
-      
-      if (!may_propagate_copy (def, use)
-         /* Propagating pointers might cause the set of vops for statements
-            to be changed, and thus require ssa form update.  */
-         || (is_gimple_reg (def)
-             && POINTER_TYPE_P (TREE_TYPE (def))))
+      bool may_replace_uses = may_propagate_copy (def, use);
+
+      /* In case we have loops to care about, do not propagate arguments of
+        loop closed ssa phi nodes.  */
+      if (current_loops
+         && is_gimple_reg (def)
+         && TREE_CODE (use) == SSA_NAME
+         && a->loop_father != b->loop_father)
+       may_replace_uses = false;
+
+      if (!may_replace_uses)
        {
          gcc_assert (is_gimple_reg (def));
 
-         /* Note that just emiting the copies is fine -- there is no problem
+         /* Note that just emitting the copies is fine -- there is no problem
             with ordering of phi nodes.  This is because A is the single
             predecessor of B, therefore results of the phi nodes cannot
             appear as arguments of the phi nodes.  */
@@ -1409,6 +1339,7 @@ tree_merge_blocks (basic_block a, basic_block b)
        }
       else
        replace_uses_by (def, use);
+
       remove_phi_node (phi, NULL);
     }
 
@@ -2056,6 +1987,12 @@ remove_bb (basic_block bb)
        {
          loop->latch = NULL;
          loop->header = NULL;
+
+         /* Also clean up the information associated with the loop.  Updating
+            it would waste time. More importantly, it may refer to ssa
+            names that were defined in other removed basic block -- these
+            ssa names are now removed and invalid.  */
+         free_numbers_of_iterations_estimates_loop (loop);
        }
     }
 
@@ -2064,17 +2001,34 @@ remove_bb (basic_block bb)
     {
       tree stmt = bsi_stmt (i);
       if (TREE_CODE (stmt) == LABEL_EXPR
-          && FORCED_LABEL (LABEL_EXPR_LABEL (stmt)))
+          && (FORCED_LABEL (LABEL_EXPR_LABEL (stmt))
+             || DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt))))
        {
-         basic_block new_bb = bb->prev_bb;
-         block_stmt_iterator new_bsi = bsi_start (new_bb);
+         basic_block new_bb;
+         block_stmt_iterator new_bsi;
+
+         /* A non-reachable non-local label may still be referenced.
+            But it no longer needs to carry the extra semantics of
+            non-locality.  */
+         if (DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt)))
+           {
+             DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt)) = 0;
+             FORCED_LABEL (LABEL_EXPR_LABEL (stmt)) = 1;
+           }
                  
+         new_bb = bb->prev_bb;
+         new_bsi = bsi_start (new_bb);
          bsi_remove (&i);
          bsi_insert_before (&new_bsi, stmt, BSI_NEW_STMT);
        }
       else
         {
-         release_defs (stmt);
+         /* Release SSA definitions if we are in SSA.  Note that we
+            may be called when not in SSA.  For example,
+            final_cleanup calls this function via
+            cleanup_tree_cfg.  */
+         if (in_ssa_p)
+           release_defs (stmt);
 
          bsi_remove (&i);
        }
@@ -2102,192 +2056,16 @@ remove_bb (basic_block bb)
      loop above, so the last statement we process is the first statement
      in the block.  */
 #ifdef USE_MAPPED_LOCATION
-  if (warn_notreached && loc > BUILTINS_LOCATION)
-    warning (0, "%Hwill never be executed", &loc);
+  if (loc > BUILTINS_LOCATION)
+    warning (OPT_Wunreachable_code, "%Hwill never be executed", &loc);
 #else
-  if (warn_notreached && loc)
-    warning (0, "%Hwill never be executed", loc);
+  if (loc)
+    warning (OPT_Wunreachable_code, "%Hwill never be executed", loc);
 #endif
 
   remove_phi_nodes_and_edges_for_unreachable_block (bb);
 }
 
-/* A list of all the noreturn calls passed to modify_stmt.
-   cleanup_control_flow uses it to detect cases where a mid-block
-   indirect call has been turned into a noreturn call.  When this
-   happens, all the instructions after the call are no longer
-   reachable and must be deleted as dead.  */
-
-VEC(tree,gc) *modified_noreturn_calls;
-
-/* Try to remove superfluous control structures.  */
-
-static bool
-cleanup_control_flow (void)
-{
-  basic_block bb;
-  block_stmt_iterator bsi;
-  bool retval = false;
-  tree stmt;
-
-  /* Detect cases where a mid-block call is now known not to return.  */
-  while (VEC_length (tree, modified_noreturn_calls))
-    {
-      stmt = VEC_pop (tree, modified_noreturn_calls);
-      bb = bb_for_stmt (stmt);
-      if (bb != NULL && last_stmt (bb) != stmt && noreturn_call_p (stmt))
-       split_block (bb, stmt);
-    }
-
-  FOR_EACH_BB (bb)
-    {
-      bsi = bsi_last (bb);
-
-      if (bsi_end_p (bsi))
-       continue;
-      
-      stmt = bsi_stmt (bsi);
-      if (TREE_CODE (stmt) == COND_EXPR
-         || TREE_CODE (stmt) == SWITCH_EXPR)
-       retval |= cleanup_control_expr_graph (bb, bsi);
-
-      /* If we had a computed goto which has a compile-time determinable
-        destination, then we can eliminate the goto.  */
-      if (TREE_CODE (stmt) == GOTO_EXPR
-         && TREE_CODE (GOTO_DESTINATION (stmt)) == ADDR_EXPR
-         && TREE_CODE (TREE_OPERAND (GOTO_DESTINATION (stmt), 0)) == LABEL_DECL)
-       {
-         edge e;
-         tree label;
-         edge_iterator ei;
-         basic_block target_block;
-         bool removed_edge = false;
-
-         /* First look at all the outgoing edges.  Delete any outgoing
-            edges which do not go to the right block.  For the one
-            edge which goes to the right block, fix up its flags.  */
-         label = TREE_OPERAND (GOTO_DESTINATION (stmt), 0);
-         target_block = label_to_block (label);
-         for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
-           {
-             if (e->dest != target_block)
-               {
-                 removed_edge = true;
-                 remove_edge (e);
-               }
-             else
-               {
-                 /* Turn off the EDGE_ABNORMAL flag.  */
-                 e->flags &= ~EDGE_ABNORMAL;
-
-                 /* And set EDGE_FALLTHRU.  */
-                 e->flags |= EDGE_FALLTHRU;
-                 ei_next (&ei);
-               }
-           }
-
-         /* If we removed one or more edges, then we will need to fix the
-            dominators.  It may be possible to incrementally update them.  */
-         if (removed_edge)
-           free_dominance_info (CDI_DOMINATORS);
-
-         /* Remove the GOTO_EXPR as it is not needed.  The CFG has all the
-            relevant information we need.  */
-         bsi_remove (&bsi);
-         retval = true;
-       }
-
-      /* Check for indirect calls that have been turned into
-        noreturn calls.  */
-      if (noreturn_call_p (stmt) && remove_fallthru_edge (bb->succs))
-       {
-         free_dominance_info (CDI_DOMINATORS);
-         retval = true;
-       }
-    }
-  return retval;
-}
-
-
-/* Disconnect an unreachable block in the control expression starting
-   at block BB.  */
-
-static bool
-cleanup_control_expr_graph (basic_block bb, block_stmt_iterator bsi)
-{
-  edge taken_edge;
-  bool retval = false;
-  tree expr = bsi_stmt (bsi), val;
-
-  if (!single_succ_p (bb))
-    {
-      edge e;
-      edge_iterator ei;
-
-      switch (TREE_CODE (expr))
-       {
-       case COND_EXPR:
-         val = COND_EXPR_COND (expr);
-         break;
-
-       case SWITCH_EXPR:
-         val = SWITCH_COND (expr);
-         if (TREE_CODE (val) != INTEGER_CST)
-           return false;
-         break;
-
-       default:
-         gcc_unreachable ();
-       }
-
-      taken_edge = find_taken_edge (bb, val);
-      if (!taken_edge)
-       return false;
-
-      /* Remove all the edges except the one that is always executed.  */
-      for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
-       {
-         if (e != taken_edge)
-           {
-             taken_edge->probability += e->probability;
-             taken_edge->count += e->count;
-             remove_edge (e);
-             retval = true;
-           }
-         else
-           ei_next (&ei);
-       }
-      if (taken_edge->probability > REG_BR_PROB_BASE)
-       taken_edge->probability = REG_BR_PROB_BASE;
-    }
-  else
-    taken_edge = single_succ_edge (bb);
-
-  bsi_remove (&bsi);
-  taken_edge->flags = EDGE_FALLTHRU;
-
-  /* We removed some paths from the cfg.  */
-  free_dominance_info (CDI_DOMINATORS);
-
-  return retval;
-}
-
-/* Remove any fallthru edge from EV.  Return true if an edge was removed.  */
-
-static bool
-remove_fallthru_edge (VEC(edge,gc) *ev)
-{
-  edge_iterator ei;
-  edge e;
-
-  FOR_EACH_EDGE (e, ei, ev)
-    if ((e->flags & EDGE_FALLTHRU) != 0)
-      {
-       remove_edge (e);
-       return true;
-      }
-  return false;
-}
 
 /* Given a basic block BB ending with COND_EXPR or SWITCH_EXPR, and a
    predicate VAL, return the edge that will be taken out of the block.
@@ -2418,31 +2196,6 @@ find_case_label_for_value (tree switch_expr, tree val)
 }
 
 
-/* If all the PHI nodes in DEST have alternatives for E1 and E2 and
-   those alternatives are equal in each of the PHI nodes, then return
-   true, else return false.  */
-
-static bool
-phi_alternatives_equal (basic_block dest, edge e1, edge e2)
-{
-  int n1 = e1->dest_idx;
-  int n2 = e2->dest_idx;
-  tree phi;
-
-  for (phi = phi_nodes (dest); phi; phi = PHI_CHAIN (phi))
-    {
-      tree val1 = PHI_ARG_DEF (phi, n1);
-      tree val2 = PHI_ARG_DEF (phi, n2);
-
-      gcc_assert (val1 != NULL_TREE);
-      gcc_assert (val2 != NULL_TREE);
-
-      if (!operand_equal_for_phi_arg_p (val1, val2))
-       return false;
-    }
-
-  return true;
-}
 
 
 /*---------------------------------------------------------------------------
@@ -2529,6 +2282,7 @@ dump_cfg_stats (FILE *file)
   basic_block bb;
   const char * const fmt_str   = "%-30s%-13s%12s\n";
   const char * const fmt_str_1 = "%-30s%13d%11lu%c\n";
+  const char * const fmt_str_2 = "%-30s%13ld%11lu%c\n";
   const char * const fmt_str_3 = "%-43s%11lu%c\n";
   const char *funcname
     = lang_hooks.decl_printable_name (current_function_decl, 2);
@@ -2551,12 +2305,7 @@ dump_cfg_stats (FILE *file)
     num_edges += EDGE_COUNT (bb->succs);
   size = num_edges * sizeof (struct edge_def);
   total += size;
-  fprintf (file, fmt_str_1, "Edges", num_edges, SCALE (size), LABEL (size));
-
-  size = n_basic_blocks * sizeof (struct bb_ann_d);
-  total += size;
-  fprintf (file, fmt_str_1, "Basic block annotations", n_basic_blocks,
-          SCALE (size), LABEL (size));
+  fprintf (file, fmt_str_2, "Edges", num_edges, SCALE (size), LABEL (size));
 
   fprintf (file, "---------------------------------------------------------\n");
   fprintf (file, fmt_str_3, "Total memory used by CFG data", SCALE (total),
@@ -2867,13 +2616,7 @@ disband_implicit_edges (void)
 void
 delete_tree_cfg_annotations (void)
 {
-  basic_block bb;
-  if (n_basic_blocks > 0)
-    free_blocks_annotations ();
-
   label_to_block_map = NULL;
-  FOR_EACH_BB (bb)
-    bb->rbi = NULL;
 }
 
 
@@ -3194,7 +2937,7 @@ tree_find_edge_insert_loc (edge e, block_stmt_iterator *bsi,
       if (TREE_CODE (tmp) == RETURN_EXPR)
         {
          tree op = TREE_OPERAND (tmp, 0);
-         if (!is_gimple_val (op))
+         if (op && !is_gimple_val (op))
            {
              gcc_assert (TREE_CODE (op) == MODIFY_EXPR);
              bsi_insert_before (bsi, op, BSI_NEW_STMT);
@@ -3312,6 +3055,22 @@ reinstall_phi_args (edge new_edge, edge old_edge)
   PENDING_STMT (old_edge) = NULL;
 }
 
+/* Returns the basic block after that the new basic block created
+   by splitting edge EDGE_IN should be placed.  Tries to keep the new block
+   near its "logical" location.  This is of most help to humans looking
+   at debugging dumps.  */
+
+static basic_block
+split_edge_bb_loc (edge edge_in)
+{
+  basic_block dest = edge_in->dest;
+
+  if (dest->prev_bb && find_edge (dest->prev_bb, dest))
+    return edge_in->src;
+  else
+    return dest->prev_bb;
+}
+
 /* Split a (typically critical) edge EDGE_IN.  Return the new block.
    Abort on abnormal edges.  */
 
@@ -3327,13 +3086,7 @@ tree_split_edge (edge edge_in)
   src = edge_in->src;
   dest = edge_in->dest;
 
-  /* Place the new block in the block list.  Try to keep the new block
-     near its "logical" location.  This is of most help to humans looking
-     at debugging dumps.  */
-  if (dest->prev_bb && find_edge (dest->prev_bb, dest))
-    after_bb = edge_in->src;
-  else
-    after_bb = dest->prev_bb;
+  after_bb = split_edge_bb_loc (edge_in);
 
   new_bb = create_empty_bb (after_bb);
   new_bb->frequency = EDGE_FREQUENCY (edge_in);
@@ -3383,12 +3136,9 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
   if (TYPE_P (t))
     *walk_subtrees = 0;
   
-  /* Check operand N for being valid GIMPLE and give error MSG if not. 
-     We check for constants explicitly since they are not considered
-     gimple invariants if they overflowed.  */
+  /* Check operand N for being valid GIMPLE and give error MSG if not.  */
 #define CHECK_OP(N, MSG) \
-  do { if (!CONSTANT_CLASS_P (TREE_OPERAND (t, N))             \
-         && !is_gimple_val (TREE_OPERAND (t, N)))              \
+  do { if (!is_gimple_val (TREE_OPERAND (t, N)))               \
        { error (MSG); return TREE_OPERAND (t, N); }} while (0)
 
   switch (TREE_CODE (t))
@@ -3421,32 +3171,67 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
       break;
 
     case ADDR_EXPR:
-      /* ??? tree-ssa-alias.c may have overlooked dead PHI nodes, missing
-        dead PHIs that take the address of something.  But if the PHI
-        result is dead, the fact that it takes the address of anything
-        is irrelevant.  Because we can not tell from here if a PHI result
-        is dead, we just skip this check for PHIs altogether.  This means
-        we may be missing "valid" checks, but what can you do?
-        This was PR19217.  */
-      if (in_phi)
-       break;
+      {
+       bool old_invariant;
+       bool old_constant;
+       bool old_side_effects;
+       bool new_invariant;
+       bool new_constant;
+       bool new_side_effects;
+
+        /* ??? tree-ssa-alias.c may have overlooked dead PHI nodes, missing
+          dead PHIs that take the address of something.  But if the PHI
+          result is dead, the fact that it takes the address of anything
+          is irrelevant.  Because we can not tell from here if a PHI result
+          is dead, we just skip this check for PHIs altogether.  This means
+          we may be missing "valid" checks, but what can you do?
+          This was PR19217.  */
+        if (in_phi)
+         break;
 
-      /* Skip any references (they will be checked when we recurse down the
-        tree) and ensure that any variable used as a prefix is marked
-        addressable.  */
-      for (x = TREE_OPERAND (t, 0);
-          handled_component_p (x);
-          x = TREE_OPERAND (x, 0))
-       ;
-
-      if (TREE_CODE (x) != VAR_DECL && TREE_CODE (x) != PARM_DECL)
-       return NULL;
-      if (!TREE_ADDRESSABLE (x))
-       {
-         error ("address taken, but ADDRESSABLE bit not set");
-         return x;
-       }
-      break;
+       old_invariant = TREE_INVARIANT (t);
+       old_constant = TREE_CONSTANT (t);
+       old_side_effects = TREE_SIDE_EFFECTS (t);
+
+       recompute_tree_invarant_for_addr_expr (t);
+       new_invariant = TREE_INVARIANT (t);
+       new_side_effects = TREE_SIDE_EFFECTS (t);
+       new_constant = TREE_CONSTANT (t);
+
+       if (old_invariant != new_invariant)
+         {
+           error ("invariant not recomputed when ADDR_EXPR changed");
+           return t;
+         }
+
+        if (old_constant != new_constant)
+         {
+           error ("constant not recomputed when ADDR_EXPR changed");
+           return t;
+         }
+       if (old_side_effects != new_side_effects)
+         {
+           error ("side effects not recomputed when ADDR_EXPR changed");
+           return t;
+         }
+
+       /* Skip any references (they will be checked when we recurse down the
+          tree) and ensure that any variable used as a prefix is marked
+          addressable.  */
+       for (x = TREE_OPERAND (t, 0);
+            handled_component_p (x);
+            x = TREE_OPERAND (x, 0))
+         ;
+
+       if (TREE_CODE (x) != VAR_DECL && TREE_CODE (x) != PARM_DECL)
+         return NULL;
+       if (!TREE_ADDRESSABLE (x))
+         {
+           error ("address taken, but ADDRESSABLE bit not set");
+           return x;
+         }
+       break;
+      }
 
     case COND_EXPR:
       x = COND_EXPR_COND (t);
@@ -3455,6 +3240,11 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
          error ("non-boolean used in condition");
          return x;
        }
+      if (!is_gimple_condexpr (x))
+        {
+         error ("invalid conditional operand");
+         return x;
+       }
       break;
 
     case NOP_EXPR:
@@ -3469,7 +3259,7 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
     case BIT_NOT_EXPR:
     case NON_LVALUE_EXPR:
     case TRUTH_NOT_EXPR:
-      CHECK_OP (0, "Invalid operand to unary operator");
+      CHECK_OP (0, "invalid operand to unary operator");
       break;
 
     case REALPART_EXPR:
@@ -3486,20 +3276,20 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
       while (handled_component_p (t))
        {
          if (TREE_CODE (t) == COMPONENT_REF && TREE_OPERAND (t, 2))
-           CHECK_OP (2, "Invalid COMPONENT_REF offset operator");
+           CHECK_OP (2, "invalid COMPONENT_REF offset operator");
          else if (TREE_CODE (t) == ARRAY_REF
                   || TREE_CODE (t) == ARRAY_RANGE_REF)
            {
-             CHECK_OP (1, "Invalid array index.");
+             CHECK_OP (1, "invalid array index");
              if (TREE_OPERAND (t, 2))
-               CHECK_OP (2, "Invalid array lower bound.");
+               CHECK_OP (2, "invalid array lower bound");
              if (TREE_OPERAND (t, 3))
-               CHECK_OP (3, "Invalid array stride.");
+               CHECK_OP (3, "invalid array stride");
            }
          else if (TREE_CODE (t) == BIT_FIELD_REF)
            {
-             CHECK_OP (1, "Invalid operand to BIT_FIELD_REF");
-             CHECK_OP (2, "Invalid operand to BIT_FIELD_REF");
+             CHECK_OP (1, "invalid operand to BIT_FIELD_REF");
+             CHECK_OP (2, "invalid operand to BIT_FIELD_REF");
            }
 
          t = TREE_OPERAND (t, 0);
@@ -3507,7 +3297,7 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
 
       if (!CONSTANT_CLASS_P (t) && !is_gimple_lvalue (t))
        {
-         error ("Invalid reference prefix.");
+         error ("invalid reference prefix");
          return t;
        }
       *walk_subtrees = 0;
@@ -3549,8 +3339,8 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
     case BIT_IOR_EXPR:
     case BIT_XOR_EXPR:
     case BIT_AND_EXPR:
-      CHECK_OP (0, "Invalid operand to binary operator");
-      CHECK_OP (1, "Invalid operand to binary operator");
+      CHECK_OP (0, "invalid operand to binary operator");
+      CHECK_OP (1, "invalid operand to binary operator");
       break;
 
     default:
@@ -3572,7 +3362,7 @@ verify_stmt (tree stmt, bool last_in_block)
 
   if (!is_gimple_stmt (stmt))
     {
-      error ("Is not a valid GIMPLE statement.");
+      error ("is not a valid GIMPLE statement");
       goto fail;
     }
 
@@ -3592,12 +3382,12 @@ verify_stmt (tree stmt, bool last_in_block)
     {
       if (!tree_could_throw_p (stmt))
        {
-         error ("Statement marked for throw, but doesn%'t.");
+         error ("statement marked for throw, but doesn%'t");
          goto fail;
        }
       if (!last_in_block && tree_can_throw_internal (stmt))
        {
-         error ("Statement marked for throw in middle of block.");
+         error ("statement marked for throw in middle of block");
          goto fail;
        }
     }
@@ -3692,7 +3482,7 @@ verify_stmts (void)
 
          if (bb_for_stmt (phi) != bb)
            {
-             error ("bb_for_stmt (phi) is set to a wrong basic block\n");
+             error ("bb_for_stmt (phi) is set to a wrong basic block");
              err |= true;
            }
 
@@ -3723,7 +3513,7 @@ verify_stmts (void)
              addr = walk_tree (&t, verify_node_sharing, htab, NULL);
              if (addr)
                {
-                 error ("Incorrect sharing of tree nodes");
+                 error ("incorrect sharing of tree nodes");
                  debug_generic_stmt (phi);
                  debug_generic_stmt (addr);
                  err |= true;
@@ -3737,7 +3527,7 @@ verify_stmts (void)
 
          if (bb_for_stmt (stmt) != bb)
            {
-             error ("bb_for_stmt (stmt) is set to a wrong basic block\n");
+             error ("bb_for_stmt (stmt) is set to a wrong basic block");
              err |= true;
            }
 
@@ -3746,7 +3536,7 @@ verify_stmts (void)
          addr = walk_tree (&stmt, verify_node_sharing, htab, NULL);
          if (addr)
            {
-             error ("Incorrect sharing of tree nodes");
+             error ("incorrect sharing of tree nodes");
              debug_generic_stmt (stmt);
              debug_generic_stmt (addr);
              err |= true;
@@ -3755,7 +3545,7 @@ verify_stmts (void)
     }
 
   if (err)
-    internal_error ("verify_stmts failed.");
+    internal_error ("verify_stmts failed");
 
   htab_delete (htab);
   timevar_pop (TV_TREE_STMT_VERIFY);
@@ -3776,20 +3566,20 @@ tree_verify_flow_info (void)
 
   if (ENTRY_BLOCK_PTR->stmt_list)
     {
-      error ("ENTRY_BLOCK has a statement list associated with it\n");
+      error ("ENTRY_BLOCK has a statement list associated with it");
       err = 1;
     }
 
   if (EXIT_BLOCK_PTR->stmt_list)
     {
-      error ("EXIT_BLOCK has a statement list associated with it\n");
+      error ("EXIT_BLOCK has a statement list associated with it");
       err = 1;
     }
 
   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
     if (e->flags & EDGE_FALLTHRU)
       {
-       error ("Fallthru to exit from bb %d\n", e->src->index);
+       error ("fallthru to exit from bb %d", e->src->index);
        err = 1;
       }
 
@@ -3811,7 +3601,7 @@ tree_verify_flow_info (void)
 
          if (prev_stmt && DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt)))
            {
-             error ("Nonlocal label %s is not first "
+             error ("nonlocal label %s is not first "
                     "in a sequence of labels in bb %d",
                     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
                     bb->index);
@@ -3820,7 +3610,7 @@ tree_verify_flow_info (void)
 
          if (label_to_block (LABEL_EXPR_LABEL (stmt)) != bb)
            {
-             error ("Label %s to block does not match in bb %d\n",
+             error ("label %s to block does not match in bb %d",
                     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
                     bb->index);
              err = 1;
@@ -3829,7 +3619,7 @@ tree_verify_flow_info (void)
          if (decl_function_context (LABEL_EXPR_LABEL (stmt))
              != current_function_decl)
            {
-             error ("Label %s has incorrect context in bb %d\n",
+             error ("label %s has incorrect context in bb %d",
                     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
                     bb->index);
              err = 1;
@@ -3843,7 +3633,7 @@ tree_verify_flow_info (void)
 
          if (found_ctrl_stmt)
            {
-             error ("Control flow in the middle of basic block %d\n",
+             error ("control flow in the middle of basic block %d",
                     bb->index);
              err = 1;
            }
@@ -3853,7 +3643,7 @@ tree_verify_flow_info (void)
 
          if (TREE_CODE (stmt) == LABEL_EXPR)
            {
-             error ("Label %s in the middle of basic block %d\n",
+             error ("label %s in the middle of basic block %d",
                     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
                     bb->index);
              err = 1;
@@ -3872,7 +3662,7 @@ tree_verify_flow_info (void)
          FOR_EACH_EDGE (e, ei, bb->succs)
            if (e->flags & EDGE_FALLTHRU)
              {
-               error ("Fallthru edge after a control statement in bb %d \n",
+               error ("fallthru edge after a control statement in bb %d",
                       bb->index);
                err = 1;
              }
@@ -3887,7 +3677,7 @@ tree_verify_flow_info (void)
            if (TREE_CODE (COND_EXPR_THEN (stmt)) != GOTO_EXPR
                || TREE_CODE (COND_EXPR_ELSE (stmt)) != GOTO_EXPR)
              {
-               error ("Structured COND_EXPR at the end of bb %d\n", bb->index);
+               error ("structured COND_EXPR at the end of bb %d", bb->index);
                err = 1;
              }
 
@@ -3900,7 +3690,7 @@ tree_verify_flow_info (void)
                || (false_edge->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL))
                || EDGE_COUNT (bb->succs) >= 3)
              {
-               error ("Wrong outgoing edge flags at end of bb %d\n",
+               error ("wrong outgoing edge flags at end of bb %d",
                       bb->index);
                err = 1;
              }
@@ -3908,7 +3698,7 @@ tree_verify_flow_info (void)
            if (!has_label_p (true_edge->dest,
                              GOTO_DESTINATION (COND_EXPR_THEN (stmt))))
              {
-               error ("%<then%> label does not match edge at end of bb %d\n",
+               error ("%<then%> label does not match edge at end of bb %d",
                       bb->index);
                err = 1;
              }
@@ -3916,7 +3706,7 @@ tree_verify_flow_info (void)
            if (!has_label_p (false_edge->dest,
                              GOTO_DESTINATION (COND_EXPR_ELSE (stmt))))
              {
-               error ("%<else%> label does not match edge at end of bb %d\n",
+               error ("%<else%> label does not match edge at end of bb %d",
                       bb->index);
                err = 1;
              }
@@ -3926,7 +3716,7 @@ tree_verify_flow_info (void)
        case GOTO_EXPR:
          if (simple_goto_p (stmt))
            {
-             error ("Explicit goto at end of bb %d\n", bb->index);
+             error ("explicit goto at end of bb %d", bb->index);
              err = 1;
            }
          else
@@ -3938,7 +3728,7 @@ tree_verify_flow_info (void)
                                 | EDGE_FALSE_VALUE))
                    || !(e->flags & EDGE_ABNORMAL))
                  {
-                   error ("Wrong outgoing edge flags at end of bb %d\n",
+                   error ("wrong outgoing edge flags at end of bb %d",
                           bb->index);
                    err = 1;
                  }
@@ -3951,12 +3741,12 @@ tree_verify_flow_info (void)
                  & (EDGE_FALLTHRU | EDGE_ABNORMAL
                     | EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)))
            {
-             error ("Wrong outgoing edge flags at end of bb %d\n", bb->index);
+             error ("wrong outgoing edge flags at end of bb %d", bb->index);
              err = 1;
            }
          if (single_succ (bb) != EXIT_BLOCK_PTR)
            {
-             error ("Return edge does not point to exit in bb %d\n",
+             error ("return edge does not point to exit in bb %d",
                     bb->index);
              err = 1;
            }
@@ -3989,13 +3779,13 @@ tree_verify_flow_info (void)
                tree c = TREE_VEC_ELT (vec, i);
                if (! CASE_LOW (c))
                  {
-                   error ("Found default case not at end of case vector");
+                   error ("found default case not at end of case vector");
                    err = 1;
                    continue;
                  }
                if (! tree_int_cst_lt (CASE_LOW (prev), CASE_LOW (c)))
                  {
-                   error ("Case labels not sorted:\n ");
+                   error ("case labels not sorted:");
                    print_generic_expr (stderr, prev, 0);
                    fprintf (stderr," is greater than ");
                    print_generic_expr (stderr, c, 0);
@@ -4006,7 +3796,7 @@ tree_verify_flow_info (void)
              }
            if (CASE_LOW (TREE_VEC_ELT (vec, n - 1)))
              {
-               error ("No default case found at end of case vector");
+               error ("no default case found at end of case vector");
                err = 1;
              }
 
@@ -4014,7 +3804,7 @@ tree_verify_flow_info (void)
              {
                if (!e->dest->aux)
                  {
-                   error ("Extra outgoing edge %d->%d\n",
+                   error ("extra outgoing edge %d->%d",
                           bb->index, e->dest->index);
                    err = 1;
                  }
@@ -4022,7 +3812,7 @@ tree_verify_flow_info (void)
                if ((e->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL
                                 | EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)))
                  {
-                   error ("Wrong outgoing edge flags at end of bb %d\n",
+                   error ("wrong outgoing edge flags at end of bb %d",
                           bb->index);
                    err = 1;
                  }
@@ -4036,7 +3826,7 @@ tree_verify_flow_info (void)
 
                if (label_bb->aux != (void *)2)
                  {
-                   error ("Missing edge %i->%i",
+                   error ("missing edge %i->%i",
                           bb->index, label_bb->index);
                    err = 1;
                  }
@@ -4099,447 +3889,6 @@ tree_make_forwarder_block (edge fallthru)
 }
 
 
-/* Return true if basic block BB does nothing except pass control
-   flow to another block and that we can safely insert a label at
-   the start of the successor block.
-
-   As a precondition, we require that BB be not equal to
-   ENTRY_BLOCK_PTR.  */
-
-static bool
-tree_forwarder_block_p (basic_block bb, bool phi_wanted)
-{
-  block_stmt_iterator bsi;
-
-  /* BB must have a single outgoing edge.  */
-  if (single_succ_p (bb) != 1
-      /* If PHI_WANTED is false, BB must not have any PHI nodes.
-        Otherwise, BB must have PHI nodes.  */
-      || (phi_nodes (bb) != NULL_TREE) != phi_wanted
-      /* BB may not be a predecessor of EXIT_BLOCK_PTR.  */
-      || single_succ (bb) == EXIT_BLOCK_PTR
-      /* Nor should this be an infinite loop.  */
-      || single_succ (bb) == bb
-      /* BB may not have an abnormal outgoing edge.  */
-      || (single_succ_edge (bb)->flags & EDGE_ABNORMAL))
-    return false; 
-
-#if ENABLE_CHECKING
-  gcc_assert (bb != ENTRY_BLOCK_PTR);
-#endif
-
-  /* Now walk through the statements backward.  We can ignore labels,
-     anything else means this is not a forwarder block.  */
-  for (bsi = bsi_last (bb); !bsi_end_p (bsi); bsi_prev (&bsi))
-    {
-      tree stmt = bsi_stmt (bsi);
-      switch (TREE_CODE (stmt))
-       {
-       case LABEL_EXPR:
-         if (DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt)))
-           return false;
-         break;
-
-       default:
-         return false;
-       }
-    }
-
-  if (find_edge (ENTRY_BLOCK_PTR, bb))
-    return false;
-
-  if (current_loops)
-    { 
-      basic_block dest;
-      /* Protect loop latches, headers and preheaders.  */
-      if (bb->loop_father->header == bb)
-       return false;
-      dest = EDGE_SUCC (bb, 0)->dest;
-      if (dest->loop_father->header == dest)
-       return false;
-    }
-
-  return true;
-}
-
-/* Return true if BB has at least one abnormal incoming edge.  */
-
-static inline bool
-has_abnormal_incoming_edge_p (basic_block bb)
-{
-  edge e;
-  edge_iterator ei;
-
-  FOR_EACH_EDGE (e, ei, bb->preds)
-    if (e->flags & EDGE_ABNORMAL)
-      return true;
-
-  return false;
-}
-
-/* Removes forwarder block BB.  Returns false if this failed.  If a new
-   forwarder block is created due to redirection of edges, it is
-   stored to worklist.  */
-
-static bool
-remove_forwarder_block (basic_block bb, basic_block **worklist)
-{
-  edge succ = single_succ_edge (bb), e, s;
-  basic_block dest = succ->dest;
-  tree label;
-  tree phi;
-  edge_iterator ei;
-  block_stmt_iterator bsi, bsi_to;
-  bool seen_abnormal_edge = false;
-
-  /* We check for infinite loops already in tree_forwarder_block_p.
-     However it may happen that the infinite loop is created
-     afterwards due to removal of forwarders.  */
-  if (dest == bb)
-    return false;
-
-  /* If the destination block consists of a nonlocal label, do not merge
-     it.  */
-  label = first_stmt (dest);
-  if (label
-      && TREE_CODE (label) == LABEL_EXPR
-      && DECL_NONLOCAL (LABEL_EXPR_LABEL (label)))
-    return false;
-
-  /* If there is an abnormal edge to basic block BB, but not into
-     dest, problems might occur during removal of the phi node at out
-     of ssa due to overlapping live ranges of registers.
-
-     If there is an abnormal edge in DEST, the problems would occur
-     anyway since cleanup_dead_labels would then merge the labels for
-     two different eh regions, and rest of exception handling code
-     does not like it.
-     
-     So if there is an abnormal edge to BB, proceed only if there is
-     no abnormal edge to DEST and there are no phi nodes in DEST.  */
-  if (has_abnormal_incoming_edge_p (bb))
-    {
-      seen_abnormal_edge = true;
-
-      if (has_abnormal_incoming_edge_p (dest)
-         || phi_nodes (dest) != NULL_TREE)
-       return false;
-    }
-
-  /* If there are phi nodes in DEST, and some of the blocks that are
-     predecessors of BB are also predecessors of DEST, check that the
-     phi node arguments match.  */
-  if (phi_nodes (dest))
-    {
-      FOR_EACH_EDGE (e, ei, bb->preds)
-       {
-         s = find_edge (e->src, dest);
-         if (!s)
-           continue;
-
-         if (!phi_alternatives_equal (dest, succ, s))
-           return false;
-       }
-    }
-
-  /* Redirect the edges.  */
-  for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); )
-    {
-      if (e->flags & EDGE_ABNORMAL)
-       {
-         /* If there is an abnormal edge, redirect it anyway, and
-            move the labels to the new block to make it legal.  */
-         s = redirect_edge_succ_nodup (e, dest);
-       }
-      else
-       s = redirect_edge_and_branch (e, dest);
-
-      if (s == e)
-       {
-         /* Create arguments for the phi nodes, since the edge was not
-            here before.  */
-         for (phi = phi_nodes (dest); phi; phi = PHI_CHAIN (phi))
-           add_phi_arg (phi, PHI_ARG_DEF (phi, succ->dest_idx), s);
-       }
-      else
-       {
-         /* The source basic block might become a forwarder.  We know
-            that it was not a forwarder before, since it used to have
-            at least two outgoing edges, so we may just add it to
-            worklist.  */
-         if (tree_forwarder_block_p (s->src, false))
-           *(*worklist)++ = s->src;
-       }
-    }
-
-  if (seen_abnormal_edge)
-    {
-      /* Move the labels to the new block, so that the redirection of
-        the abnormal edges works.  */
-
-      bsi_to = bsi_start (dest);
-      for (bsi = bsi_start (bb); !bsi_end_p (bsi); )
-       {
-         label = bsi_stmt (bsi);
-         gcc_assert (TREE_CODE (label) == LABEL_EXPR);
-         bsi_remove (&bsi);
-         bsi_insert_before (&bsi_to, label, BSI_CONTINUE_LINKING);
-       }
-    }
-
-  /* Update the dominators.  */
-  if (dom_info_available_p (CDI_DOMINATORS))
-    {
-      basic_block dom, dombb, domdest;
-
-      dombb = get_immediate_dominator (CDI_DOMINATORS, bb);
-      domdest = get_immediate_dominator (CDI_DOMINATORS, dest);
-      if (domdest == bb)
-       {
-         /* Shortcut to avoid calling (relatively expensive)
-            nearest_common_dominator unless necessary.  */
-         dom = dombb;
-       }
-      else
-       dom = nearest_common_dominator (CDI_DOMINATORS, domdest, dombb);
-
-      set_immediate_dominator (CDI_DOMINATORS, dest, dom);
-    }
-
-  /* And kill the forwarder block.  */
-  delete_basic_block (bb);
-
-  return true;
-}
-
-/* Removes forwarder blocks.  */
-
-static bool
-cleanup_forwarder_blocks (void)
-{
-  basic_block bb;
-  bool changed = false;
-  basic_block *worklist = xmalloc (sizeof (basic_block) * n_basic_blocks);
-  basic_block *current = worklist;
-
-  FOR_EACH_BB (bb)
-    {
-      if (tree_forwarder_block_p (bb, false))
-       *current++ = bb;
-    }
-
-  while (current != worklist)
-    {
-      bb = *--current;
-      changed |= remove_forwarder_block (bb, &current);
-    }
-
-  free (worklist);
-  return changed;
-}
-
-/* Merge the PHI nodes at BB into those at BB's sole successor.  */
-
-static void
-remove_forwarder_block_with_phi (basic_block bb)
-{
-  edge succ = single_succ_edge (bb);
-  basic_block dest = succ->dest;
-  tree label;
-  basic_block dombb, domdest, dom;
-
-  /* We check for infinite loops already in tree_forwarder_block_p.
-     However it may happen that the infinite loop is created
-     afterwards due to removal of forwarders.  */
-  if (dest == bb)
-    return;
-
-  /* If the destination block consists of a nonlocal label, do not
-     merge it.  */
-  label = first_stmt (dest);
-  if (label
-      && TREE_CODE (label) == LABEL_EXPR
-      && DECL_NONLOCAL (LABEL_EXPR_LABEL (label)))
-    return;
-
-  /* Redirect each incoming edge to BB to DEST.  */
-  while (EDGE_COUNT (bb->preds) > 0)
-    {
-      edge e = EDGE_PRED (bb, 0), s;
-      tree phi;
-
-      s = find_edge (e->src, dest);
-      if (s)
-       {
-         /* We already have an edge S from E->src to DEST.  If S and
-            E->dest's sole successor edge have the same PHI arguments
-            at DEST, redirect S to DEST.  */
-         if (phi_alternatives_equal (dest, s, succ))
-           {
-             e = redirect_edge_and_branch (e, dest);
-             PENDING_STMT (e) = NULL_TREE;
-             continue;
-           }
-
-         /* PHI arguments are different.  Create a forwarder block by
-            splitting E so that we can merge PHI arguments on E to
-            DEST.  */
-         e = single_succ_edge (split_edge (e));
-       }
-
-      s = redirect_edge_and_branch (e, dest);
-
-      /* redirect_edge_and_branch must not create a new edge.  */
-      gcc_assert (s == e);
-
-      /* Add to the PHI nodes at DEST each PHI argument removed at the
-        destination of E.  */
-      for (phi = phi_nodes (dest); phi; phi = PHI_CHAIN (phi))
-       {
-         tree def = PHI_ARG_DEF (phi, succ->dest_idx);
-
-         if (TREE_CODE (def) == SSA_NAME)
-           {
-             tree var;
-
-             /* If DEF is one of the results of PHI nodes removed during
-                redirection, replace it with the PHI argument that used
-                to be on E.  */
-             for (var = PENDING_STMT (e); var; var = TREE_CHAIN (var))
-               {
-                 tree old_arg = TREE_PURPOSE (var);
-                 tree new_arg = TREE_VALUE (var);
-
-                 if (def == old_arg)
-                   {
-                     def = new_arg;
-                     break;
-                   }
-               }
-           }
-
-         add_phi_arg (phi, def, s);
-       }
-
-      PENDING_STMT (e) = NULL;
-    }
-
-  /* Update the dominators.  */
-  dombb = get_immediate_dominator (CDI_DOMINATORS, bb);
-  domdest = get_immediate_dominator (CDI_DOMINATORS, dest);
-  if (domdest == bb)
-    {
-      /* Shortcut to avoid calling (relatively expensive)
-        nearest_common_dominator unless necessary.  */
-      dom = dombb;
-    }
-  else
-    dom = nearest_common_dominator (CDI_DOMINATORS, domdest, dombb);
-
-  set_immediate_dominator (CDI_DOMINATORS, dest, dom);
-  
-  /* Remove BB since all of BB's incoming edges have been redirected
-     to DEST.  */
-  delete_basic_block (bb);
-}
-
-/* This pass merges PHI nodes if one feeds into another.  For example,
-   suppose we have the following:
-
-  goto <bb 9> (<L9>);
-
-<L8>:;
-  tem_17 = foo ();
-
-  # tem_6 = PHI <tem_17(8), tem_23(7)>;
-<L9>:;
-
-  # tem_3 = PHI <tem_6(9), tem_2(5)>;
-<L10>:;
-
-  Then we merge the first PHI node into the second one like so:
-
-  goto <bb 9> (<L10>);
-
-<L8>:;
-  tem_17 = foo ();
-
-  # tem_3 = PHI <tem_23(7), tem_2(5), tem_17(8)>;
-<L10>:;
-*/
-
-static void
-merge_phi_nodes (void)
-{
-  basic_block *worklist = xmalloc (sizeof (basic_block) * n_basic_blocks);
-  basic_block *current = worklist;
-  basic_block bb;
-
-  calculate_dominance_info (CDI_DOMINATORS);
-
-  /* Find all PHI nodes that we may be able to merge.  */
-  FOR_EACH_BB (bb)
-    {
-      basic_block dest;
-
-      /* Look for a forwarder block with PHI nodes.  */
-      if (!tree_forwarder_block_p (bb, true))
-       continue;
-
-      dest = single_succ (bb);
-
-      /* We have to feed into another basic block with PHI
-        nodes.  */
-      if (!phi_nodes (dest)
-         /* We don't want to deal with a basic block with
-            abnormal edges.  */
-         || has_abnormal_incoming_edge_p (bb))
-       continue;
-
-      if (!dominated_by_p (CDI_DOMINATORS, dest, bb))
-       {
-         /* If BB does not dominate DEST, then the PHI nodes at
-            DEST must be the only users of the results of the PHI
-            nodes at BB.  */
-         *current++ = bb;
-       }
-    }
-
-  /* Now let's drain WORKLIST.  */
-  while (current != worklist)
-    {
-      bb = *--current;
-      remove_forwarder_block_with_phi (bb);
-    }
-
-  free (worklist);
-}
-
-static bool
-gate_merge_phi (void)
-{
-  return 1;
-}
-
-struct tree_opt_pass pass_merge_phi = {
-  "mergephi",                  /* name */
-  gate_merge_phi,              /* gate */
-  merge_phi_nodes,             /* execute */
-  NULL,                                /* sub */
-  NULL,                                /* next */
-  0,                           /* static_pass_number */
-  TV_TREE_MERGE_PHI,           /* tv_id */
-  PROP_cfg | PROP_ssa,         /* properties_required */
-  0,                           /* properties_provided */
-  0,                           /* properties_destroyed */
-  0,                           /* todo_flags_start */
-  TODO_dump_func | TODO_ggc_collect    /* todo_flags_finish */
-  | TODO_verify_ssa,
-  0                            /* letter */
-};
-
 /* Return a non-special label in the head of basic block BLOCK.
    Create one if it doesn't exist.  */
 
@@ -4862,7 +4211,7 @@ tree_duplicate_bb (basic_block bb)
 
 /* Basic block BB_COPY was created by code duplication.  Add phi node
    arguments for edges going out of BB_COPY.  The blocks that were
-   duplicated have rbi->duplicated set to one.  */
+   duplicated have BB_DUPLICATED set.  */
 
 void
 add_phi_args_after_copy_bb (basic_block bb_copy)
@@ -4872,15 +4221,15 @@ add_phi_args_after_copy_bb (basic_block bb_copy)
   edge_iterator ei;
   tree phi, phi_copy, phi_next, def;
       
-  bb = bb_copy->rbi->original;
+  bb = get_bb_original (bb_copy);
 
   FOR_EACH_EDGE (e_copy, ei, bb_copy->succs)
     {
       if (!phi_nodes (e_copy->dest))
        continue;
 
-      if (e_copy->dest->rbi->duplicated)
-       dest = e_copy->dest->rbi->original;
+      if (e_copy->dest->flags & BB_DUPLICATED)
+       dest = get_bb_original (e_copy->dest);
       else
        dest = e_copy->dest;
 
@@ -4891,8 +4240,8 @@ add_phi_args_after_copy_bb (basic_block bb_copy)
             In this case we are not looking for edge to dest, but to
             duplicated block whose original was dest.  */
          FOR_EACH_EDGE (e, ei, bb->succs)
-           if (e->dest->rbi->duplicated
-               && e->dest->rbi->original == dest)
+           if ((e->dest->flags & BB_DUPLICATED)
+               && get_bb_original (e->dest) == dest)
              break;
 
          gcc_assert (e != NULL);
@@ -4919,13 +4268,13 @@ add_phi_args_after_copy (basic_block *region_copy, unsigned n_region)
   unsigned i;
 
   for (i = 0; i < n_region; i++)
-    region_copy[i]->rbi->duplicated = 1;
+    region_copy[i]->flags |= BB_DUPLICATED;
 
   for (i = 0; i < n_region; i++)
     add_phi_args_after_copy_bb (region_copy[i]);
 
   for (i = 0; i < n_region; i++)
-    region_copy[i]->rbi->duplicated = 0;
+    region_copy[i]->flags &= ~BB_DUPLICATED;
 }
 
 /* Duplicates a REGION (set of N_REGION basic blocks) with just a single
@@ -4949,7 +4298,8 @@ tree_duplicate_sese_region (edge entry, edge exit,
   edge exit_copy;
   basic_block *doms;
   edge redirected;
-  int total_freq, entry_freq;
+  int total_freq = 0, entry_freq = 0;
+  gcov_type total_count = 0, entry_count = 0;
 
   if (!can_copy_bbs_p (region, n_region))
     return false;
@@ -4999,21 +4349,47 @@ tree_duplicate_sese_region (edge entry, edge exit,
   /* Record blocks outside the region that are dominated by something
      inside.  */
   doms = xmalloc (sizeof (basic_block) * n_basic_blocks);
+  initialize_original_copy_tables ();
+
   n_doms = get_dominated_by_region (CDI_DOMINATORS, region, n_region, doms);
 
-  total_freq = entry->dest->frequency;
-  entry_freq = EDGE_FREQUENCY (entry);
-  /* Fix up corner cases, to avoid division by zero or creation of negative
-     frequencies.  */
-  if (total_freq == 0)
-    total_freq = 1;
-  else if (entry_freq > total_freq)
-    entry_freq = total_freq;
+  if (entry->dest->count)
+    {
+      total_count = entry->dest->count;
+      entry_count = entry->count;
+      /* Fix up corner cases, to avoid division by zero or creation of negative
+        frequencies.  */
+      if (entry_count > total_count)
+       entry_count = total_count;
+    }
+  else
+    {
+      total_freq = entry->dest->frequency;
+      entry_freq = EDGE_FREQUENCY (entry);
+      /* Fix up corner cases, to avoid division by zero or creation of negative
+        frequencies.  */
+      if (total_freq == 0)
+       total_freq = 1;
+      else if (entry_freq > total_freq)
+       entry_freq = total_freq;
+    }
 
-  copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop);
-  scale_bbs_frequencies_int (region, n_region, total_freq - entry_freq,
-                            total_freq);
-  scale_bbs_frequencies_int (region_copy, n_region, entry_freq, total_freq);
+  copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop,
+           split_edge_bb_loc (entry));
+  if (total_count)
+    {
+      scale_bbs_frequencies_gcov_type (region, n_region,
+                                      total_count - entry_count,
+                                      total_count);
+      scale_bbs_frequencies_gcov_type (region_copy, n_region, entry_count,
+                                      total_count);
+    }
+  else
+    {
+      scale_bbs_frequencies_int (region, n_region, total_freq - entry_freq,
+                                total_freq);
+      scale_bbs_frequencies_int (region_copy, n_region, entry_freq, total_freq);
+    }
 
   if (copying_header)
     {
@@ -5022,7 +4398,7 @@ tree_duplicate_sese_region (edge entry, edge exit,
     }
 
   /* Redirect the entry and add the phi node arguments.  */
-  redirected = redirect_edge_and_branch (entry, entry->dest->rbi->copy);
+  redirected = redirect_edge_and_branch (entry, get_bb_copy (entry->dest));
   gcc_assert (redirected != NULL);
   flush_pending_stmts (entry);
 
@@ -5031,7 +4407,7 @@ tree_duplicate_sese_region (edge entry, edge exit,
      region, but was dominated by something inside needs recounting as
      well.  */
   set_immediate_dominator (CDI_DOMINATORS, entry->dest, entry->src);
-  doms[n_doms++] = entry->dest->rbi->original;
+  doms[n_doms++] = get_bb_original (entry->dest);
   iterate_fix_dominators (CDI_DOMINATORS, doms, n_doms);
   free (doms);
 
@@ -5044,10 +4420,31 @@ tree_duplicate_sese_region (edge entry, edge exit,
   if (free_region_copy)
     free (region_copy);
 
+  free_original_copy_tables ();
   return true;
 }
 
 
+static tree
+mark_used_vars (tree *tp, int *walk_subtrees, void *used_vars_)
+{
+  bitmap *used_vars = (bitmap *)used_vars_;
+
+  if (walk_subtrees
+      && IS_TYPE_OR_DECL_P (*tp))
+    *walk_subtrees = 0;
+
+  if (!SSA_VAR_P (*tp))
+    return NULL_TREE;
+
+  if (TREE_CODE (*tp) == SSA_NAME)
+    bitmap_set_bit (*used_vars, DECL_UID (SSA_NAME_VAR (*tp)));
+  else
+    bitmap_set_bit (*used_vars, DECL_UID (*tp));
+
+  return NULL_TREE;
+}
+
 /* Dump FUNCTION_DECL FN to file FILE using FLAGS (see TDF_* in tree.h)  */
 
 void
@@ -5082,18 +4479,47 @@ dump_function_to_file (tree fn, FILE *file, int flags)
      BIND_EXPRs, so display them separately.  */
   if (cfun && cfun->decl == fn && cfun->unexpanded_var_list)
     {
+      bitmap used_vars = BITMAP_ALLOC (NULL);
       ignore_topmost_bind = true;
 
+      /* Record vars we'll use dumping the functions tree.  */
+      if (cfun->cfg && basic_block_info)
+       {
+         FOR_EACH_BB (bb)
+           {
+             block_stmt_iterator bsi;
+             for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+               walk_tree (bsi_stmt_ptr (bsi), mark_used_vars,
+                          &used_vars, NULL);
+           }
+         for (vars = cfun->unexpanded_var_list; vars;
+              vars = TREE_CHAIN (vars))
+           {
+             var = TREE_VALUE (vars);
+             if (TREE_CODE (var) == VAR_DECL
+                 && DECL_INITIAL (var)
+                 && bitmap_bit_p (used_vars, DECL_UID (var)))
+               walk_tree (&DECL_INITIAL (var), mark_used_vars,
+                          &used_vars, NULL);
+           }
+       }
+
+      /* Dump used vars.  */
       fprintf (file, "{\n");
       for (vars = cfun->unexpanded_var_list; vars; vars = TREE_CHAIN (vars))
        {
          var = TREE_VALUE (vars);
+         if (cfun->cfg && basic_block_info
+             && !bitmap_bit_p (used_vars, DECL_UID (var)))
+            continue;
 
          print_generic_decl (file, var, flags);
          fprintf (file, "\n");
 
          any_var = true;
        }
+
+      BITMAP_FREE (used_vars);
     }
 
   if (cfun && cfun->decl == fn && cfun->cfg && basic_block_info)
@@ -5154,7 +4580,7 @@ static void print_pred_bbs (FILE *, basic_block bb);
 static void print_succ_bbs (FILE *, basic_block bb);
 
 
-/* Print the predecessors indexes of edge E on FILE.  */
+/* Print on FILE the indexes for the predecessors of basic_block BB.  */
 
 static void
 print_pred_bbs (FILE *file, basic_block bb)
@@ -5163,11 +4589,11 @@ print_pred_bbs (FILE *file, basic_block bb)
   edge_iterator ei;
 
   FOR_EACH_EDGE (e, ei, bb->preds)
-    fprintf (file, "bb_%d", e->src->index);
+    fprintf (file, "bb_%d ", e->src->index);
 }
 
 
-/* Print the successors indexes of edge E on FILE.  */
+/* Print on FILE the indexes for the successors of basic_block BB.  */
 
 static void
 print_succ_bbs (FILE *file, basic_block bb)
@@ -5176,7 +4602,7 @@ print_succ_bbs (FILE *file, basic_block bb)
   edge_iterator ei;
 
   FOR_EACH_EDGE (e, ei, bb->succs)
-    fprintf (file, "bb_%d", e->src->index);
+    fprintf (file, "bb_%d ", e->dest->index);
 }
 
 
@@ -5648,7 +5074,7 @@ gimplify_val (block_stmt_iterator *bsi, tree type, tree exp)
     return exp;
 
   t = make_rename_temp (type, NULL);
-  new_stmt = build (MODIFY_EXPR, type, t, exp);
+  new_stmt = build2 (MODIFY_EXPR, type, t, exp);
 
   orig_stmt = bsi_stmt (*bsi);
   SET_EXPR_LOCUS (new_stmt, EXPR_LOCUS (orig_stmt));
@@ -5668,7 +5094,7 @@ gimplify_build3 (block_stmt_iterator *bsi, enum tree_code code,
 {
   tree ret;
 
-  ret = fold (build3 (code, type, a, b, c));
+  ret = fold_build3 (code, type, a, b, c);
   STRIP_NOPS (ret);
 
   return gimplify_val (bsi, type, ret);
@@ -5683,7 +5109,7 @@ gimplify_build2 (block_stmt_iterator *bsi, enum tree_code code,
 {
   tree ret;
 
-  ret = fold (build2 (code, type, a, b));
+  ret = fold_build2 (code, type, a, b);
   STRIP_NOPS (ret);
 
   return gimplify_val (bsi, type, ret);
@@ -5698,7 +5124,7 @@ gimplify_build1 (block_stmt_iterator *bsi, enum tree_code code, tree type,
 {
   tree ret;
 
-  ret = fold (build1 (code, type, a));
+  ret = fold_build1 (code, type, a);
   STRIP_NOPS (ret);
 
   return gimplify_val (bsi, type, ret);
@@ -5762,7 +5188,8 @@ execute_warn_function_return (void)
        {
          tree last = last_stmt (e->src);
          if (TREE_CODE (last) == RETURN_EXPR
-             && TREE_OPERAND (last, 0) == NULL)
+             && TREE_OPERAND (last, 0) == NULL
+             && !TREE_NO_WARNING (last))
            {
 #ifdef USE_MAPPED_LOCATION
              location = EXPR_LOCATION (last);
@@ -5833,8 +5260,8 @@ execute_warn_function_noreturn (void)
       && !TREE_THIS_VOLATILE (cfun->decl)
       && EDGE_COUNT (EXIT_BLOCK_PTR->preds) == 0
       && !lang_hooks.function.missing_noreturn_ok_p (cfun->decl))
-    warning (0, "%Jfunction might be possible candidate for "
-            "attribute %<noreturn%>",
+    warning (OPT_Wmissing_noreturn, "%Jfunction might be possible candidate "
+            "for attribute %<noreturn%>",
             cfun->decl);
 }