OSDN Git Service

2004-04-15 Pat Haugen <pthaugen@us.ibm.com>
[pf3gnuchains/gcc-fork.git] / gcc / cfgcleanup.c
index 056a32f..51182e3 100644 (file)
@@ -1,6 +1,6 @@
 /* Control flow optimization code for GNU compiler.
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -23,7 +23,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    cleanup_cfg.  Following optimizations are performed:
 
    - Unreachable blocks removal
-   - Edge forwarding (edge to the forwarder block is forwarded to it's
+   - Edge forwarding (edge to the forwarder block is forwarded to its
      successor.  Simplification of the branch instruction is performed by
      underlying infrastructure so branch can be converted to simplejump or
      eliminated).
@@ -48,6 +48,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "params.h"
 #include "tm_p.h"
 #include "target.h"
+#include "regs.h"
+#include "cfglayout.h"
+#include "expr.h"
 
 /* cleanup_cfg maintains following flags for each basic block.  */
 
@@ -67,13 +70,14 @@ enum bb_flags
 
 #define FORWARDER_BLOCK_P(BB) (BB_FLAGS (BB) & BB_FORWARDER_BLOCK)
 
+/* Set to true when we are running first pass of try_optimize_cfg loop.  */
+static bool first_pass;
 static bool try_crossjump_to_edge (int, edge, edge);
 static bool try_crossjump_bb (int, basic_block);
 static bool outgoing_edges_match (int, basic_block, basic_block);
 static int flow_find_cross_jump (int, basic_block, basic_block, rtx *, rtx *);
 static bool insns_match_p (int, rtx, rtx);
 
-static bool label_is_jump_target_p (rtx, rtx);
 static bool tail_recursion_label_p (rtx);
 static void merge_blocks_move_predecessor_nojumps (basic_block, basic_block);
 static void merge_blocks_move_successor_nojumps (basic_block, basic_block);
@@ -85,6 +89,7 @@ static bool mark_effect (rtx, bitmap);
 static void notice_new_block (basic_block);
 static void update_forwarder_flag (basic_block);
 static int mentions_nonequal_regs (rtx *, void *);
+static void merge_memattrs (rtx, rtx);
 \f
 /* Set flags for newly created block.  */
 
@@ -146,6 +151,15 @@ try_simplify_condjump (basic_block cbranch_block)
     return false;
   jump_dest_block = jump_block->succ->dest;
 
+  /* If we are partitioning hot/cold basic blocks, we don't want to
+     mess up unconditional or indirect jumps that cross between hot
+     and cold sections.  */
+
+  if (flag_reorder_blocks_and_partition
+      && (jump_block->partition != jump_dest_block->partition
+         || cbranch_jump_edge->crossing_edge))
+    return false;
+
   /* The conditional branch must target the block after the
      unconditional branch.  */
   cbranch_dest_block = cbranch_jump_edge->dest;
@@ -157,8 +171,8 @@ try_simplify_condjump (basic_block cbranch_block)
   if (!invert_jump (cbranch_insn, block_label (jump_dest_block), 0))
     return false;
 
-  if (rtl_dump_file)
-    fprintf (rtl_dump_file, "Simplifying condjump %i around jump %i\n",
+  if (dump_file)
+    fprintf (dump_file, "Simplifying condjump %i around jump %i\n",
             INSN_UID (cbranch_insn), INSN_UID (BB_END (jump_block)));
 
   /* Success.  Update the CFG to match.  Note that after this point
@@ -193,8 +207,8 @@ try_simplify_condjump (basic_block cbranch_block)
        }
     }
   /* Delete the block with the unconditional jump, and clean up the mess.  */
-  delete_block (jump_block);
-  tidy_fallthru_edge (cbranch_jump_edge, cbranch_block, cbranch_dest_block);
+  delete_basic_block (jump_block);
+  tidy_fallthru_edge (cbranch_jump_edge);
 
   return true;
 }
@@ -219,7 +233,7 @@ mark_effect (rtx exp, regset nonequal)
          CLEAR_REGNO_REG_SET (nonequal, regno);
          if (regno < FIRST_PSEUDO_REGISTER)
            {
-             int n = HARD_REGNO_NREGS (regno, GET_MODE (dest));
+             int n = hard_regno_nregs[regno][GET_MODE (dest)];
              while (--n > 0)
                CLEAR_REGNO_REG_SET (nonequal, regno + n);
            }
@@ -238,7 +252,7 @@ mark_effect (rtx exp, regset nonequal)
       SET_REGNO_REG_SET (nonequal, regno);
       if (regno < FIRST_PSEUDO_REGISTER)
        {
-         int n = HARD_REGNO_NREGS (regno, GET_MODE (dest));
+         int n = hard_regno_nregs[regno][GET_MODE (dest)];
          while (--n > 0)
            SET_REGNO_REG_SET (nonequal, regno + n);
        }
@@ -264,7 +278,7 @@ mentions_nonequal_regs (rtx *x, void *data)
        return 1;
       if (regno < FIRST_PSEUDO_REGISTER)
        {
-         int n = HARD_REGNO_NREGS (regno, GET_MODE (*x));
+         int n = hard_regno_nregs[regno][GET_MODE (*x)];
          while (--n > 0)
            if (REGNO_REG_SET_P (nonequal, regno + n))
              return 1;
@@ -347,7 +361,7 @@ thread_jump (int mode, edge e, basic_block b)
        return NULL;
       }
 
-  cselib_init ();
+  cselib_init (false);
 
   /* First process all values computed in the source basic block.  */
   for (insn = NEXT_INSN (BB_HEAD (e->src)); insn != NEXT_INSN (BB_END (e->src));
@@ -424,12 +438,21 @@ try_forward_edges (int mode, basic_block b)
   bool changed = false;
   edge e, next, *threaded_edges = NULL;
 
+  /* If we are partitioning hot/cold basic blocks, we don't want to
+     mess up unconditional or indirect jumps that cross between hot
+     and cold sections.  */
+  
+  if (flag_reorder_blocks_and_partition
+      && find_reg_note (BB_END (b), REG_CROSSING_JUMP, NULL_RTX))
+    return false;
+
   for (e = b->succ; e; e = next)
     {
       basic_block target, first;
       int counter;
       bool threaded = false;
       int nthreaded_edges = 0;
+      bool may_thread = first_pass | (b->flags & BB_DIRTY);
 
       next = e->succ_next;
 
@@ -448,6 +471,7 @@ try_forward_edges (int mode, basic_block b)
        {
          basic_block new_target = NULL;
          bool new_target_threaded = false;
+         may_thread |= target->flags & BB_DIRTY;
 
          if (FORWARDER_BLOCK_P (target)
              && target->succ->dest != EXIT_BLOCK_PTR)
@@ -460,7 +484,7 @@ try_forward_edges (int mode, basic_block b)
 
          /* Allow to thread only over one edge at time to simplify updating
             of probabilities.  */
-         else if (mode & CLEANUP_THREADING)
+         else if ((mode & CLEANUP_THREADING) && may_thread)
            {
              edge t = thread_jump (mode, e, target);
              if (t)
@@ -540,8 +564,8 @@ try_forward_edges (int mode, basic_block b)
 
       if (counter >= n_basic_blocks)
        {
-         if (rtl_dump_file)
-           fprintf (rtl_dump_file, "Infinite loop in BB %i.\n",
+         if (dump_file)
+           fprintf (dump_file, "Infinite loop in BB %i.\n",
                     target->index);
        }
       else if (target == first)
@@ -558,13 +582,13 @@ try_forward_edges (int mode, basic_block b)
          if (threaded && target != EXIT_BLOCK_PTR)
            {
              notice_new_block (redirect_edge_and_branch_force (e, target));
-             if (rtl_dump_file)
-               fprintf (rtl_dump_file, "Conditionals threaded.\n");
+             if (dump_file)
+               fprintf (dump_file, "Conditionals threaded.\n");
            }
          else if (!redirect_edge_and_branch (e, target))
            {
-             if (rtl_dump_file)
-               fprintf (rtl_dump_file,
+             if (dump_file)
+               fprintf (dump_file,
                         "Forwarding edge %i->%i to %i failed.\n",
                         b->index, e->dest->index, target->index);
              continue;
@@ -646,33 +670,6 @@ try_forward_edges (int mode, basic_block b)
   return changed;
 }
 \f
-/* Return true if LABEL is a target of JUMP_INSN.  This applies only
-   to non-complex jumps.  That is, direct unconditional, conditional,
-   and tablejumps, but not computed jumps or returns.  It also does
-   not apply to the fallthru case of a conditional jump.  */
-
-static bool
-label_is_jump_target_p (rtx label, rtx jump_insn)
-{
-  rtx tmp = JUMP_LABEL (jump_insn);
-
-  if (label == tmp)
-    return true;
-
-  if (tablejump_p (jump_insn, NULL, &tmp))
-    {
-      rtvec vec = XVEC (PATTERN (tmp),
-                       GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC);
-      int i, veclen = GET_NUM_ELEM (vec);
-
-      for (i = 0; i < veclen; ++i)
-       if (XEXP (RTVEC_ELT (vec, i), 0) == label)
-         return true;
-    }
-
-  return false;
-}
-
 /* Return true if LABEL is used for tail recursion.  */
 
 static bool
@@ -696,6 +693,15 @@ merge_blocks_move_predecessor_nojumps (basic_block a, basic_block b)
 {
   rtx barrier;
 
+  /* If we are partitioning hot/cold basic blocks, we don't want to
+     mess up unconditional or indirect jumps that cross between hot
+     and cold sections.  */
+  
+  if (flag_reorder_blocks_and_partition
+      && (a->partition != b->partition
+         || find_reg_note (BB_END (a), REG_CROSSING_JUMP, NULL_RTX)))
+    return;
+
   barrier = next_nonnote_insn (BB_END (a));
   if (GET_CODE (barrier) != BARRIER)
     abort ();
@@ -716,8 +722,8 @@ merge_blocks_move_predecessor_nojumps (basic_block a, basic_block b)
     reorder_insns_nobb (BB_HEAD (a), BB_END (a), PREV_INSN (BB_HEAD (b)));
   a->flags |= BB_DIRTY;
 
-  if (rtl_dump_file)
-    fprintf (rtl_dump_file, "Moved block %d before %d and merged.\n",
+  if (dump_file)
+    fprintf (dump_file, "Moved block %d before %d and merged.\n",
             a->index, b->index);
 
   /* Swap the records for the two blocks around.  */
@@ -739,6 +745,15 @@ merge_blocks_move_successor_nojumps (basic_block a, basic_block b)
   rtx barrier, real_b_end;
   rtx label, table;
 
+  /* If we are partitioning hot/cold basic blocks, we don't want to
+     mess up unconditional or indirect jumps that cross between hot
+     and cold sections.  */
+  
+  if (flag_reorder_blocks_and_partition
+      && (find_reg_note (BB_END (a), REG_CROSSING_JUMP, NULL_RTX)
+         || a->partition != b->partition))
+    return;
+
   real_b_end = BB_END (b);
 
   /* If there is a jump table following block B temporarily add the jump table
@@ -770,8 +785,8 @@ merge_blocks_move_successor_nojumps (basic_block a, basic_block b)
   /* Restore the real end of b.  */
   BB_END (b) = real_b_end;
 
-  if (rtl_dump_file)
-    fprintf (rtl_dump_file, "Moved block %d after %d and merged.\n",
+  if (dump_file)
+    fprintf (dump_file, "Moved block %d after %d and merged.\n",
             b->index, a->index);
 
   /* Now blocks A and B are contiguous.  Merge them.  */
@@ -803,6 +818,18 @@ merge_blocks_move (edge e, basic_block b, basic_block c, int mode)
       && tail_recursion_label_p (BB_HEAD (c)))
     return NULL;
 
+  /* If we are partitioning hot/cold basic blocks, we don't want to
+     mess up unconditional or indirect jumps that cross between hot
+     and cold sections.  */
+  
+  if (flag_reorder_blocks_and_partition
+      && (find_reg_note (BB_END (b), REG_CROSSING_JUMP, NULL_RTX)
+         || find_reg_note (BB_END (c), REG_CROSSING_JUMP, NULL_RTX)
+         || b->partition != c->partition))
+    return NULL;
+      
+    
+
   /* If B has a fallthru edge to C, no need to move anything.  */
   if (e->flags & EDGE_FALLTHRU)
     {
@@ -810,8 +837,8 @@ merge_blocks_move (edge e, basic_block b, basic_block c, int mode)
       merge_blocks (b, c);
       update_forwarder_flag (b);
 
-      if (rtl_dump_file)
-       fprintf (rtl_dump_file, "Merged %d and %d without moving.\n",
+      if (dump_file)
+       fprintf (dump_file, "Merged %d and %d without moving.\n",
                 b_index, c_index);
 
       return b->prev_bb == ENTRY_BLOCK_PTR ? b : b->prev_bb;
@@ -885,6 +912,88 @@ merge_blocks_move (edge e, basic_block b, basic_block c, int mode)
 }
 \f
 
+/* Removes the memory attributes of MEM expression
+   if they are not equal.  */
+
+void
+merge_memattrs (rtx x, rtx y)
+{
+  int i;
+  int j;
+  enum rtx_code code;
+  const char *fmt;
+
+  if (x == y)
+    return;
+  if (x == 0 || y == 0)
+    return;
+
+  code = GET_CODE (x);
+
+  if (code != GET_CODE (y))
+    return;
+
+  if (GET_MODE (x) != GET_MODE (y))
+    return;
+
+  if (code == MEM && MEM_ATTRS (x) != MEM_ATTRS (y))
+    {
+      if (! MEM_ATTRS (x))
+       MEM_ATTRS (y) = 0;
+      else if (! MEM_ATTRS (y))
+       MEM_ATTRS (x) = 0;
+      else 
+       {
+         if (MEM_ALIAS_SET (x) != MEM_ALIAS_SET (y))
+           {
+             set_mem_alias_set (x, 0);
+             set_mem_alias_set (y, 0);
+           }
+         
+         if (! mem_expr_equal_p (MEM_EXPR (x), MEM_EXPR (y)))
+           {
+             set_mem_expr (x, 0);
+             set_mem_expr (y, 0);
+             set_mem_offset (x, 0);
+             set_mem_offset (y, 0);
+           }
+         else if (MEM_OFFSET (x) != MEM_OFFSET (y))
+           {
+             set_mem_offset (x, 0);
+             set_mem_offset (y, 0);
+           }
+         
+         set_mem_size (x, MAX (MEM_SIZE (x), MEM_SIZE (y)));
+         set_mem_size (y, MEM_SIZE (x));
+
+         set_mem_align (x, MIN (MEM_ALIGN (x), MEM_ALIGN (y)));
+         set_mem_align (y, MEM_ALIGN (x));
+       }
+    }
+  
+  fmt = GET_RTX_FORMAT (code);
+  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
+    {
+      switch (fmt[i])
+       {
+       case 'E':
+         /* Two vectors must have the same length.  */
+         if (XVECLEN (x, i) != XVECLEN (y, i))
+           return;
+
+         for (j = 0; j < XVECLEN (x, i); j++)
+           merge_memattrs (XVECEXP (x, i, j), XVECEXP (y, i, j));
+
+         break;
+
+       case 'e':
+         merge_memattrs (XEXP (x, i), XEXP (y, i));
+       }
+    }
+  return;
+}
+
+
 /* Return true if I1 and I2 are equivalent and thus can be crossjumped.  */
 
 static bool
@@ -1045,6 +1154,8 @@ flow_find_cross_jump (int mode ATTRIBUTE_UNUSED, basic_block bb1,
       if (!insns_match_p (mode, i1, i2))
        break;
 
+      merge_memattrs (i1, i2);
+
       /* Don't begin a cross-jump with a NOTE insn.  */
       if (INSN_P (i1))
        {
@@ -1224,8 +1335,8 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
             outcomes.  */
          if (abs (b1->probability - prob2) > REG_BR_PROB_BASE / 2)
            {
-             if (rtl_dump_file)
-               fprintf (rtl_dump_file,
+             if (dump_file)
+               fprintf (dump_file,
                         "Outcomes of branch in bb %i and %i differs to much (%i %i)\n",
                         bb1->index, bb2->index, b1->probability, prob2);
 
@@ -1233,8 +1344,8 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
            }
        }
 
-      if (rtl_dump_file && match)
-       fprintf (rtl_dump_file, "Conditionals in bb %i and %i match.\n",
+      if (dump_file && match)
+       fprintf (dump_file, "Conditionals in bb %i and %i match.\n",
                 bb1->index, bb2->index);
 
       return match;
@@ -1299,8 +1410,8 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
                  for_each_rtx (&BB_END (bb1), replace_label, &rr);
 
                  match = insns_match_p (mode, BB_END (bb1), BB_END (bb2));
-                 if (rtl_dump_file && match)
-                   fprintf (rtl_dump_file,
+                 if (dump_file && match)
+                   fprintf (dump_file,
                             "Tablejumps in bb %i and %i match.\n",
                             bb1->index, bb2->index);
 
@@ -1390,6 +1501,12 @@ try_crossjump_to_edge (int mode, edge e1, edge e2)
   rtx newpos1, newpos2;
   edge s;
 
+  /* If we have partitioned hot/cold basic blocks, it is a bad idea
+     to try this optimization.  */
+
+  if (flag_reorder_blocks_and_partition && no_new_pseudos)
+    return false;
+
   /* Search backward through forwarder blocks.  We don't need to worry
      about multiple entry or chained forwarders, as they will be optimized
      away.  We do this to look past the unconditional jump following a
@@ -1471,14 +1588,14 @@ try_crossjump_to_edge (int mode, edge e1, edge e2)
     redirect_to = src2;
   else
     {
-      if (rtl_dump_file)
-       fprintf (rtl_dump_file, "Splitting bb %i before %i insns\n",
+      if (dump_file)
+       fprintf (dump_file, "Splitting bb %i before %i insns\n",
                 src2->index, nmatch);
       redirect_to = split_block (src2, PREV_INSN (newpos2))->dest;
     }
 
-  if (rtl_dump_file)
-    fprintf (rtl_dump_file,
+  if (dump_file)
+    fprintf (dump_file,
             "Cross jumping from bb %i to bb %i; %i common insns\n",
             src1->index, src2->index, nmatch);
 
@@ -1554,7 +1671,7 @@ try_crossjump_to_edge (int mode, edge e1, edge e2)
   to_remove = redirect_from->succ->dest;
 
   redirect_edge_and_branch_force (redirect_from->succ, redirect_to);
-  delete_block (to_remove);
+  delete_basic_block (to_remove);
 
   update_forwarder_flag (redirect_from);
 
@@ -1576,6 +1693,15 @@ try_crossjump_bb (int mode, basic_block bb)
   if (!bb->pred || !bb->pred->pred_next)
     return false;
 
+  /* If we are partitioning hot/cold basic blocks, we don't want to
+     mess up unconditional or indirect jumps that cross between hot
+     and cold sections.  */
+  
+  if (flag_reorder_blocks_and_partition
+      && (bb->pred->src->partition != bb->pred->pred_next->src->partition
+         || bb->pred->crossing_edge))
+    return false;
+
   /* It is always cheapest to redirect a block that ends in a branch to
      a block that falls through into BB, as that adds no branches to the
      program.  We'll try that combination first.  */
@@ -1601,6 +1727,12 @@ try_crossjump_bb (int mode, basic_block bb)
             If there is a match, we'll do it the other way around.  */
          if (e == fallthru)
            continue;
+         /* If nothing changed since the last attempt, there is nothing
+            we can do.  */
+         if (!first_pass
+             && (!(e->src->flags & BB_DIRTY)
+                 && !(fallthru->src->flags & BB_DIRTY)))
+           continue;
 
          if (try_crossjump_to_edge (mode, e, fallthru))
            {
@@ -1643,6 +1775,13 @@ try_crossjump_bb (int mode, basic_block bb)
          if (e->src->index > e2->src->index)
            continue;
 
+         /* If nothing changed since the last attempt, there is nothing
+            we can do.  */
+         if (!first_pass
+             && (!(e->src->flags & BB_DIRTY)
+                 && !(e2->src->flags & BB_DIRTY)))
+           continue;
+
          if (try_crossjump_to_edge (mode, e, e2))
            {
              changed = true;
@@ -1672,11 +1811,12 @@ try_optimize_cfg (int mode)
   FOR_EACH_BB (bb)
     update_forwarder_flag (bb);
 
-  if (mode & CLEANUP_UPDATE_LIFE)
+  if (mode & (CLEANUP_UPDATE_LIFE | CLEANUP_CROSSJUMP | CLEANUP_THREADING))
     clear_bb_flags ();
 
-  if (! (* targetm.cannot_modify_jumps_p) ())
+  if (! targetm.cannot_modify_jumps_p ())
     {
+      first_pass = true;
       /* Attempt to merge blocks as made possible by edge removal.  If
         a block has only one successor, and the successor has only
         one predecessor, they may be combined.  */
@@ -1685,8 +1825,8 @@ try_optimize_cfg (int mode)
          changed = false;
          iterations++;
 
-         if (rtl_dump_file)
-           fprintf (rtl_dump_file,
+         if (dump_file)
+           fprintf (dump_file,
                     "\n\ntry_optimize_cfg iteration %i\n\n",
                     iterations);
 
@@ -1700,11 +1840,11 @@ try_optimize_cfg (int mode)
              while (b->pred == NULL)
                {
                  c = b->prev_bb;
-                 if (rtl_dump_file)
-                   fprintf (rtl_dump_file, "Deleting block %i.\n",
+                 if (dump_file)
+                   fprintf (dump_file, "Deleting block %i.\n",
                             b->index);
 
-                 delete_block (b);
+                 delete_basic_block (b);
                  if (!(mode & CLEANUP_CFGLAYOUT))
                    changed = true;
                  b = c;
@@ -1742,8 +1882,8 @@ try_optimize_cfg (int mode)
                      reorder_insns_nobb (label, label, bb_note);
                      BB_HEAD (b) = bb_note;
                    }
-                 if (rtl_dump_file)
-                   fprintf (rtl_dump_file, "Deleted label in block %i.\n",
+                 if (dump_file)
+                   fprintf (dump_file, "Deleted label in block %i.\n",
                             b->index);
                }
 
@@ -1758,14 +1898,14 @@ try_optimize_cfg (int mode)
                  && (b->succ->flags & EDGE_FALLTHRU)
                  && n_basic_blocks > 1)
                {
-                 if (rtl_dump_file)
-                   fprintf (rtl_dump_file,
+                 if (dump_file)
+                   fprintf (dump_file,
                             "Deleting fallthru block %i.\n",
                             b->index);
 
                  c = b->prev_bb == ENTRY_BLOCK_PTR ? b->next_bb : b->prev_bb;
                  redirect_edge_succ_nodup (b->pred, b->succ->dest);
-                 delete_block (b);
+                 delete_basic_block (b);
                  changed = true;
                  b = c;
                }
@@ -1794,7 +1934,7 @@ try_optimize_cfg (int mode)
                           /* If the jump insn has side effects,
                              we can't kill the edge.  */
                           && (GET_CODE (BB_END (b)) != JUMP_INSN
-                              || (flow2_completed
+                              || (reload_completed
                                   ? simplejump_p (BB_END (b))
                                   : onlyjump_p (BB_END (b))))
                           && (next = merge_blocks_move (s, b, c, mode)))
@@ -1813,13 +1953,14 @@ try_optimize_cfg (int mode)
              /* If B has a single outgoing edge, but uses a
                 non-trivial jump instruction without side-effects, we
                 can either delete the jump entirely, or replace it
-                with a simple unconditional jump.  Use
-                redirect_edge_and_branch to do the dirty work.  */
+                with a simple unconditional jump.  */
              if (b->succ
                  && ! b->succ->succ_next
                  && b->succ->dest != EXIT_BLOCK_PTR
                  && onlyjump_p (BB_END (b))
-                 && redirect_edge_and_branch (b->succ, b->succ->dest))
+                 && !find_reg_note (BB_END (b), REG_CROSSING_JUMP, NULL_RTX)
+                 && try_redirect_by_replacing_jump (b->succ, b->succ->dest,
+                                                    (mode & CLEANUP_CFGLAYOUT) != 0))
                {
                  update_forwarder_flag (b);
                  changed_here = true;
@@ -1852,6 +1993,7 @@ try_optimize_cfg (int mode)
 #endif
 
          changed_overall |= changed;
+         first_pass = false;
        }
       while (changed);
     }
@@ -1882,7 +2024,7 @@ delete_unreachable_blocks (void)
 
       if (!(b->flags & BB_REACHABLE))
        {
-         delete_block (b);
+         delete_basic_block (b);
          changed = true;
        }
     }
@@ -1925,7 +2067,8 @@ cleanup_cfg (int mode)
                                                 PROP_DEATH_NOTES
                                                 | PROP_SCAN_DEAD_CODE
                                                 | PROP_KILL_DEAD_CODE
-                                                | PROP_LOG_LINKS))
+                                                | ((mode & CLEANUP_LOG_LINKS)
+                                                   ? PROP_LOG_LINKS : 0)))
            break;
        }
       else if (!(mode & (CLEANUP_NO_INSN_DEL | CLEANUP_PRE_SIBCALL))