OSDN Git Service

* config/arm/netbsd.h (TARGET_OS_CPP_BUILTINS): Use
[pf3gnuchains/gcc-fork.git] / gcc / ifcvt.c
index 4a76d22..4ed1494 100644 (file)
@@ -1,5 +1,5 @@
 /* If-conversion support.
-   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
@@ -27,6 +27,7 @@
 #include "flags.h"
 #include "insn-config.h"
 #include "recog.h"
+#include "except.h"
 #include "hard-reg-set.h"
 #include "basic-block.h"
 #include "expr.h"
@@ -104,21 +105,12 @@ static int find_if_block          PARAMS ((basic_block, edge, edge));
 static int find_if_case_1              PARAMS ((basic_block, edge, edge));
 static int find_if_case_2              PARAMS ((basic_block, edge, edge));
 static int find_cond_trap              PARAMS ((basic_block, edge, edge));
+static rtx block_has_only_trap         PARAMS ((basic_block));
 static int find_memory                 PARAMS ((rtx *, void *));
 static int dead_or_predicable          PARAMS ((basic_block, basic_block,
                                                 basic_block, basic_block, int));
 static void noce_emit_move_insn                PARAMS ((rtx, rtx));
 \f
-/* Abuse the basic_block AUX field to store the original block index,
-   as well as a flag indicating that the block should be rescaned for
-   life analysis.  */
-
-#define SET_ORIG_INDEX(BB,I)   ((BB)->aux = (void *)((size_t)(I) << 1))
-#define ORIG_INDEX(BB)         ((size_t)(BB)->aux >> 1)
-#define SET_UPDATE_LIFE(BB)    ((BB)->aux = (void *)((size_t)(BB)->aux | 1))
-#define UPDATE_LIFE(BB)                ((size_t)(BB)->aux & 1)
-
-\f
 /* Count the number of non-jump active insns in BB.  */
 
 static int
@@ -560,7 +552,7 @@ noce_emit_store_flag (if_info, x, reversep, normalize)
                           || code == GEU || code == GTU), normalize);
 }
 
-/* Emit instruction to move a rtx into STRICT_LOW_PART.  */
+/* Emit instruction to move an rtx into STRICT_LOW_PART.  */
 static void
 noce_emit_move_insn (x, y)
      rtx x, y;
@@ -580,8 +572,7 @@ noce_emit_move_insn (x, y)
   outmode = GET_MODE (outer);
   inmode = GET_MODE (inner);
   bitpos = SUBREG_BYTE (outer) * BITS_PER_UNIT;
-  store_bit_field (inner, GET_MODE_BITSIZE (outmode),
-                  bitpos, outmode, y, GET_MODE_BITSIZE (inmode),
+  store_bit_field (inner, GET_MODE_BITSIZE (outmode), bitpos, outmode, y,
                   GET_MODE_BITSIZE (inmode));
 }
 
@@ -621,7 +612,7 @@ noce_try_store_flag (if_info)
 
       seq = get_insns ();
       end_sequence ();
-      emit_insns_before (seq, if_info->cond_earliest);
+      emit_insns_before (seq, if_info->jump);
 
       return TRUE;
     }
@@ -651,6 +642,12 @@ noce_try_store_flag_constants (if_info)
       mode = GET_MODE (if_info->x);
       ifalse = INTVAL (if_info->a);
       itrue = INTVAL (if_info->b);
+
+      /* Make sure we can represent the difference between the two values.  */
+      if ((itrue - ifalse > 0)
+         != ((ifalse < 0) != (itrue < 0) ? ifalse < 0 : ifalse < itrue))
+       return FALSE;
+
       diff = trunc_int_for_mode (itrue - ifalse, mode);
 
       can_reverse = (reversed_comparison_code (if_info->cond, if_info->jump)
@@ -750,7 +747,7 @@ noce_try_store_flag_constants (if_info)
       if (seq_contains_jump (seq))
        return FALSE;
 
-      emit_insns_before (seq, if_info->cond_earliest);
+      emit_insns_before (seq, if_info->jump);
 
       return TRUE;
     }
@@ -810,7 +807,7 @@ noce_try_store_flag_inc (if_info)
          if (seq_contains_jump (seq))
            return FALSE;
 
-         emit_insns_before (seq, if_info->cond_earliest);
+         emit_insns_before (seq, if_info->jump);
 
          return TRUE;
        }
@@ -862,7 +859,7 @@ noce_try_store_flag_mask (if_info)
          if (seq_contains_jump (seq))
            return FALSE;
 
-         emit_insns_before (seq, if_info->cond_earliest);
+         emit_insns_before (seq, if_info->jump);
 
          return TRUE;
        }
@@ -957,7 +954,7 @@ noce_try_cmove (if_info)
 
          seq = get_insns ();
          end_sequence ();
-         emit_insns_before (seq, if_info->cond_earliest);
+         emit_insns_before (seq, if_info->jump);
          return TRUE;
        }
       else
@@ -1109,6 +1106,8 @@ noce_try_cmove_arith (if_info)
        MEM_SCALAR_P (tmp) = 1;
       if (MEM_ALIAS_SET (if_info->a) == MEM_ALIAS_SET (if_info->b))
        set_mem_alias_set (tmp, MEM_ALIAS_SET (if_info->a));
+      set_mem_align (tmp,
+                    MIN (MEM_ALIGN (if_info->a), MEM_ALIGN (if_info->b)));
 
       noce_emit_move_insn (if_info->x, tmp);
     }
@@ -1117,7 +1116,7 @@ noce_try_cmove_arith (if_info)
 
   tmp = get_insns ();
   end_sequence ();
-  emit_insns_before (tmp, if_info->cond_earliest);
+  emit_insns_before (tmp, if_info->jump);
   return TRUE;
 
  end_seq_and_fail:
@@ -1290,12 +1289,11 @@ noce_try_minmax (if_info)
   if (no_new_pseudos)
     return FALSE;
 
-  /* ??? Reject FP modes since we don't know how 0 vs -0 or NaNs
-     will be resolved with an SMIN/SMAX.  It wouldn't be too hard
+  /* ??? Reject modes with NaNs or signed zeros since we don't know how
+     they will be resolved with an SMIN/SMAX.  It wouldn't be too hard
      to get the target to tell us...  */
-  if (FLOAT_MODE_P (GET_MODE (if_info->x))
-      && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
-      && ! flag_unsafe_math_optimizations)
+  if (HONOR_SIGNED_ZEROS (GET_MODE (if_info->x))
+      || HONOR_NANS (GET_MODE (if_info->x)))
     return FALSE;
 
   cond = noce_get_alt_condition (if_info, if_info->a, &earliest);
@@ -1370,7 +1368,7 @@ noce_try_minmax (if_info)
   if (seq_contains_jump (seq))
     return FALSE;
 
-  emit_insns_before (seq, earliest);
+  emit_insns_before (seq, if_info->jump);
   if_info->cond = cond;
   if_info->cond_earliest = earliest;
 
@@ -1488,7 +1486,7 @@ noce_try_abs (if_info)
   if (seq_contains_jump (seq))
     return FALSE;
 
-  emit_insns_before (seq, earliest);
+  emit_insns_before (seq, if_info->jump);
   if_info->cond = cond;
   if_info->cond_earliest = earliest;
 
@@ -1550,35 +1548,6 @@ noce_operand_ok (op)
   if (side_effects_p (op))
     return FALSE;
 
-  /* ??? Unfortuantely may_trap_p can't look at flag_trapping_math, due to
-     being linked into the genfoo programs.  This is probably a mistake.
-     With finite operands, most fp operations don't trap.  */
-  if (!flag_trapping_math && FLOAT_MODE_P (GET_MODE (op)))
-    switch (GET_CODE (op))
-      {
-      case DIV:
-      case MOD:
-      case UDIV:
-      case UMOD:
-       /* ??? This is kinda lame -- almost every target will have forced
-          the constant into a register first.  But given the expense of
-          division, this is probably for the best.  */
-       return (CONSTANT_P (XEXP (op, 1))
-               && XEXP (op, 1) != CONST0_RTX (GET_MODE (op))
-               && ! may_trap_p (XEXP (op, 0)));
-
-      default:
-       switch (GET_RTX_CLASS (GET_CODE (op)))
-         {
-         case '1':
-           return ! may_trap_p (XEXP (op, 0));
-         case 'c':
-         case '2':
-           return ! may_trap_p (XEXP (op, 0)) && ! may_trap_p (XEXP (op, 1));
-         }
-       break;
-      }
-
   return ! may_trap_p (op);
 }
 
@@ -1765,9 +1734,7 @@ noce_process_if_block (test_bb, then_bb, else_bb, join_bb)
 
  success:
   /* The original sets may now be killed.  */
-  if (insn_a == then_bb->end)
-    then_bb->end = PREV_INSN (insn_a);
-  flow_delete_insn (insn_a);
+  delete_insn (insn_a);
 
   /* Several special cases here: First, we may have reused insn_b above,
      in which case insn_b is now NULL.  Second, we want to delete insn_b
@@ -1776,23 +1743,18 @@ noce_process_if_block (test_bb, then_bb, else_bb, join_bb)
      the TEST block, it may in fact be loading data needed for the comparison.
      We'll let life_analysis remove the insn if it's really dead.  */
   if (insn_b && else_bb)
-    {
-      if (insn_b == else_bb->end)
-       else_bb->end = PREV_INSN (insn_b);
-      flow_delete_insn (insn_b);
-    }
+    delete_insn (insn_b);
 
-  /* The new insns will have been inserted before cond_earliest.  We should
+  /* The new insns will have been inserted just before the jump.  We should
      be able to remove the jump with impunity, but the condition itself may
      have been modified by gcse to be shared across basic blocks.  */
-  test_bb->end = PREV_INSN (jump);
-  flow_delete_insn (jump);
+  delete_insn (jump);
 
   /* If we used a temporary, fix it up now.  */
   if (orig_x != x)
     {
       start_sequence ();
-      noce_emit_move_insn (orig_x, x);
+      noce_emit_move_insn (copy_rtx (orig_x), x);
       insn_b = gen_sequence ();
       end_sequence ();
 
@@ -1844,11 +1806,14 @@ merge_if_block (test_bb, then_bb, else_bb, join_bb)
 
   /* First merge TEST block into THEN block.  This is a no-brainer since
      the THEN block did not have a code label to begin with.  */
-
-  if (life_data_ok)
-    COPY_REG_SET (combo_bb->global_live_at_end, then_bb->global_live_at_end);
-  merge_blocks_nomove (combo_bb, then_bb);
-  num_removed_blocks++;
+  if (then_bb)
+    {
+      if (combo_bb->global_live_at_end)
+       COPY_REG_SET (combo_bb->global_live_at_end,
+                     then_bb->global_live_at_end);
+      merge_blocks_nomove (combo_bb, then_bb);
+      num_removed_blocks++;
+    }
 
   /* The ELSE block, if it existed, had a label.  That label count
      will almost always be zero, but odd things can happen when labels
@@ -1864,14 +1829,34 @@ merge_if_block (test_bb, then_bb, else_bb, join_bb)
 
   if (! join_bb)
     {
+      rtx last = combo_bb->end;
+
       /* The outgoing edge for the current COMBO block should already
         be correct.  Verify this.  */
       if (combo_bb->succ == NULL_EDGE)
-       abort ();
+       {
+         if (find_reg_note (last, REG_NORETURN, NULL))
+           ;
+         else if (GET_CODE (last) == INSN
+                  && GET_CODE (PATTERN (last)) == TRAP_IF
+                  && TRAP_CONDITION (PATTERN (last)) == const_true_rtx)
+           ;
+         else
+           abort ();
+       }
 
-      /* There should still be a branch at the end of the THEN or ELSE
+      /* There should still be something at the end of the THEN or ELSE
          blocks taking us to our final destination.  */
-      if (GET_CODE (combo_bb->end) != JUMP_INSN)
+      else if (GET_CODE (last) == JUMP_INSN)
+       ;
+      else if (combo_bb->succ->dest == EXIT_BLOCK_PTR
+              && GET_CODE (last) == CALL_INSN
+              && SIBLING_CALL_P (last))
+       ;
+      else if ((combo_bb->succ->flags & EDGE_EH)
+              && can_throw_internal (last))
+       ;
+      else
        abort ();
     }
 
@@ -1886,7 +1871,7 @@ merge_if_block (test_bb, then_bb, else_bb, join_bb)
           && join_bb != EXIT_BLOCK_PTR)
     {
       /* We can merge the JOIN.  */
-      if (life_data_ok)
+      if (combo_bb->global_live_at_end)
        COPY_REG_SET (combo_bb->global_live_at_end,
                      join_bb->global_live_at_end);
       merge_blocks_nomove (combo_bb, join_bb);
@@ -1907,9 +1892,6 @@ merge_if_block (test_bb, then_bb, else_bb, join_bb)
         tidy_fallthru_edge (combo_bb->succ, combo_bb, join_bb);
     }
 
-  /* Make sure we update life info properly.  */
-  SET_UPDATE_LIFE (combo_bb);
-
   num_updated_if_blocks++;
 }
 \f
@@ -1983,7 +1965,7 @@ find_if_block (test_bb, then_edge, else_edge)
   basic_block join_bb = NULL_BLOCK;
   edge then_succ = then_bb->succ;
   edge else_succ = else_bb->succ;
-  int next_index;
+  basic_block next;
 
   /* The THEN block of an IF-THEN combo must have exactly one predecessor.  */
   if (then_bb->pred->pred_next != NULL_EDGE)
@@ -2067,10 +2049,10 @@ find_if_block (test_bb, then_edge, else_edge)
   /* ??? As an enhancement, move the ELSE block.  Have to deal with
      BLOCK notes, if by no other means than aborting the merge if they
      exist.  Sticky enough I don't want to think about it now.  */
-  next_index = then_bb->index;
-  if (else_bb && ++next_index != else_bb->index)
+  next = then_bb;
+  if (else_bb && (next = next->next_bb) != else_bb)
     return FALSE;
-  if (++next_index != join_bb->index && join_bb->index != EXIT_BLOCK)
+  if ((next = next->next_bb) != join_bb && join_bb != EXIT_BLOCK_PTR)
     {
       if (else_bb)
        join_bb = NULL;
@@ -2090,68 +2072,27 @@ find_cond_trap (test_bb, then_edge, else_edge)
      basic_block test_bb;
      edge then_edge, else_edge;
 {
-  basic_block then_bb, else_bb, join_bb, trap_bb;
+  basic_block then_bb, else_bb, trap_bb, other_bb;
   rtx trap, jump, cond, cond_earliest, seq;
   enum rtx_code code;
 
   then_bb = then_edge->dest;
   else_bb = else_edge->dest;
-  join_bb = NULL;
 
   /* Locate the block with the trap instruction.  */
   /* ??? While we look for no successors, we really ought to allow
      EH successors.  Need to fix merge_if_block for that to work.  */
-  /* ??? We can't currently handle merging the blocks if they are not
-     already adjacent.  Prevent losage in merge_if_block by detecting
-     this now.  */
-  if (then_bb->succ == NULL)
-    {
-      trap_bb = then_bb;
-      if (else_bb->index != then_bb->index + 1)
-       return FALSE;
-      join_bb = else_bb;
-      else_bb = NULL;
-    }
-  else if (else_bb->succ == NULL)
-    {
-      trap_bb = else_bb;
-      if (else_bb->index != then_bb->index + 1)
-       else_bb = NULL;
-      else if (then_bb->succ
-         && ! then_bb->succ->succ_next
-         && ! (then_bb->succ->flags & EDGE_COMPLEX)
-         && then_bb->succ->dest->index == else_bb->index + 1)
-       join_bb = then_bb->succ->dest;
-    }
+  if ((trap = block_has_only_trap (then_bb)) != NULL)
+    trap_bb = then_bb, other_bb = else_bb;
+  else if ((trap = block_has_only_trap (else_bb)) != NULL)
+    trap_bb = else_bb, other_bb = then_bb;
   else
     return FALSE;
 
-  /* Don't confuse a conditional return with something we want to
-     optimize here.  */
-  if (trap_bb == EXIT_BLOCK_PTR)
-    return FALSE;
-
-  /* The only instruction in the THEN block must be the trap.  */
-  trap = first_active_insn (trap_bb);
-  if (! (trap == trap_bb->end
-        && GET_CODE (PATTERN (trap)) == TRAP_IF
-         && TRAP_CONDITION (PATTERN (trap)) == const_true_rtx))
-    return FALSE;
-
   if (rtl_dump_file)
     {
-      if (trap_bb == then_bb)
-       fprintf (rtl_dump_file,
-                "\nTRAP-IF block found, start %d, trap %d",
-                test_bb->index, then_bb->index);
-      else
-       fprintf (rtl_dump_file,
-                "\nTRAP-IF block found, start %d, then %d, trap %d",
-                test_bb->index, then_bb->index, trap_bb->index);
-      if (join_bb)
-       fprintf (rtl_dump_file, ", join %d\n", join_bb->index);
-      else
-       fputc ('\n', rtl_dump_file);
+      fprintf (rtl_dump_file, "\nTRAP-IF block found, start %d, trap %d\n",
+              test_bb->index, trap_bb->index);
     }
 
   /* If this is not a standard conditional jump, we can't parse it.  */
@@ -2184,28 +2125,67 @@ find_cond_trap (test_bb, then_edge, else_edge)
   if (seq == NULL)
     return FALSE;
 
-  /* Emit the new insns before cond_earliest; delete the old jump
-     and trap insns.  */
-
+  /* Emit the new insns before cond_earliest.  */
   emit_insn_before (seq, cond_earliest);
 
-  test_bb->end = PREV_INSN (jump);
-  flow_delete_insn (jump);
-
-  trap_bb->end = PREV_INSN (trap);
-  flow_delete_insn (trap);
-
-  /* Merge the blocks!  */
-  if (trap_bb != then_bb && ! else_bb)
+  /* Delete the trap block if possible.  */
+  remove_edge (trap_bb == then_bb ? then_edge : else_edge);
+  if (trap_bb->pred == NULL)
     {
       flow_delete_block (trap_bb);
       num_removed_blocks++;
     }
-  merge_if_block (test_bb, then_bb, else_bb, join_bb);
+
+  /* If the non-trap block and the test are now adjacent, merge them.
+     Otherwise we must insert a direct branch.  */
+  if (test_bb->next_bb == other_bb)
+    {
+      delete_insn (jump);
+      merge_if_block (test_bb, NULL, NULL, other_bb);
+    }
+  else
+    {
+      rtx lab, newjump;
+
+      lab = JUMP_LABEL (jump);
+      newjump = emit_jump_insn_after (gen_jump (lab), jump);
+      LABEL_NUSES (lab) += 1;
+      JUMP_LABEL (newjump) = lab;
+      emit_barrier_after (newjump);
+
+      delete_insn (jump);
+    }
 
   return TRUE;
 }
 
+/* Subroutine of find_cond_trap: if BB contains only a trap insn, 
+   return it.  */
+
+static rtx
+block_has_only_trap (bb)
+     basic_block bb;
+{
+  rtx trap;
+
+  /* We're not the exit block.  */
+  if (bb == EXIT_BLOCK_PTR)
+    return NULL_RTX;
+
+  /* The block must have no successors.  */
+  if (bb->succ)
+    return NULL_RTX;
+
+  /* The only instruction in the THEN block must be the trap.  */
+  trap = first_active_insn (bb);
+  if (! (trap == bb->end
+        && GET_CODE (PATTERN (trap)) == TRAP_IF
+         && TRAP_CONDITION (PATTERN (trap)) == const_true_rtx))
+    return NULL_RTX;
+
+  return trap;
+}
+
 /* Look for IF-THEN-ELSE cases in which one of THEN or ELSE is
    transformable, but not necessarily the other.  There need be no
    JOIN block.
@@ -2291,6 +2271,7 @@ find_if_case_1 (test_bb, then_edge, else_edge)
   basic_block then_bb = then_edge->dest;
   basic_block else_bb = else_edge->dest, new_bb;
   edge then_succ = then_bb->succ;
+  int then_bb_index;
 
   /* THEN has one successor.  */
   if (!then_succ || then_succ->succ_next != NULL)
@@ -2326,20 +2307,20 @@ find_if_case_1 (test_bb, then_edge, else_edge)
   /* Conversion went ok, including moving the insns and fixing up the
      jump.  Adjust the CFG to match.  */
 
-  SET_UPDATE_LIFE (test_bb);
   bitmap_operation (test_bb->global_live_at_end,
                    else_bb->global_live_at_start,
                    then_bb->global_live_at_end, BITMAP_IOR);
   
   new_bb = redirect_edge_and_branch_force (FALLTHRU_EDGE (test_bb), else_bb);
+  then_bb_index = then_bb->index;
+  flow_delete_block (then_bb);
   /* Make rest of code believe that the newly created block is the THEN_BB
-     block we are going to remove.  */
+     block we removed.  */
   if (new_bb)
     {
-      new_bb->aux = then_bb->aux;
-      SET_UPDATE_LIFE (then_bb);
+      new_bb->index = then_bb_index;
+      BASIC_BLOCK (then_bb_index) = new_bb;
     }
-  flow_delete_block (then_bb);
   /* We've possibly created jump to next insn, cleanup_cfg will solve that
      later.  */
 
@@ -2382,8 +2363,8 @@ find_if_case_2 (test_bb, then_edge, else_edge)
   if (note && INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2)
     ;
   else if (else_succ->dest->index < 0
-          || TEST_BIT (post_dominators[ORIG_INDEX (then_bb)], 
-                       ORIG_INDEX (else_succ->dest)))
+          || TEST_BIT (post_dominators[then_bb->index], 
+                       else_succ->dest->index))
     ;
   else
     return FALSE;
@@ -2405,7 +2386,6 @@ find_if_case_2 (test_bb, then_edge, else_edge)
   /* Conversion went ok, including moving the insns and fixing up the
      jump.  Adjust the CFG to match.  */
 
-  SET_UPDATE_LIFE (test_bb);
   bitmap_operation (test_bb->global_live_at_end,
                    then_bb->global_live_at_start,
                    else_bb->global_live_at_end, BITMAP_IOR);
@@ -2446,7 +2426,7 @@ dead_or_predicable (test_bb, merge_bb, other_bb, new_dest, reversep)
      basic_block new_dest;
      int reversep;
 {
-  rtx head, end, jump, earliest, old_dest, new_label;
+  rtx head, end, jump, earliest, old_dest, new_label = NULL_RTX;
 
   jump = test_bb->end;
 
@@ -2539,7 +2519,7 @@ dead_or_predicable (test_bb, merge_bb, other_bb, new_dest, reversep)
              /* ??? Even non-trapping memories such as stack frame
                 references must be avoided.  For stores, we collect
                 no lifetime info; for reads, we'd have to assert
-                true_dependance false against every store in the
+                true_dependence false against every store in the
                 TEST range.  */
              if (for_each_rtx (&PATTERN (insn), find_memory, NULL))
                return FALSE;
@@ -2631,34 +2611,41 @@ dead_or_predicable (test_bb, merge_bb, other_bb, new_dest, reversep)
      change group management.  */
 
   old_dest = JUMP_LABEL (jump);
-  new_label = block_label (new_dest);
-  if (reversep
-      ? ! invert_jump_1 (jump, new_label)
-      : ! redirect_jump_1 (jump, new_label))
-    goto cancel;
+  if (other_bb != new_dest)
+    {
+      new_label = block_label (new_dest);
+      if (reversep
+         ? ! invert_jump_1 (jump, new_label)
+         : ! redirect_jump_1 (jump, new_label))
+       goto cancel;
+    }
 
   if (! apply_change_group ())
     return FALSE;
 
-  if (old_dest)
-    LABEL_NUSES (old_dest) -= 1;
-  if (new_label)
-    LABEL_NUSES (new_label) += 1;
-  JUMP_LABEL (jump) = new_label;
-
-  if (reversep)
-    invert_br_probabilities (jump);
-
-  redirect_edge_succ (BRANCH_EDGE (test_bb), new_dest);
-  if (reversep)
+  if (other_bb != new_dest)
     {
-      gcov_type count, probability;
-      count = BRANCH_EDGE (test_bb)->count;
-      BRANCH_EDGE (test_bb)->count = FALLTHRU_EDGE (test_bb)->count;
-      FALLTHRU_EDGE (test_bb)->count = count;
-      probability = BRANCH_EDGE (test_bb)->probability;
-      BRANCH_EDGE (test_bb)->probability = FALLTHRU_EDGE (test_bb)->probability;
-      FALLTHRU_EDGE (test_bb)->probability = probability;
+      if (old_dest)
+       LABEL_NUSES (old_dest) -= 1;
+      if (new_label)
+       LABEL_NUSES (new_label) += 1;
+      JUMP_LABEL (jump) = new_label;
+      if (reversep)
+       invert_br_probabilities (jump);
+
+      redirect_edge_succ (BRANCH_EDGE (test_bb), new_dest);
+      if (reversep)
+       {
+         gcov_type count, probability;
+         count = BRANCH_EDGE (test_bb)->count;
+         BRANCH_EDGE (test_bb)->count = FALLTHRU_EDGE (test_bb)->count;
+         FALLTHRU_EDGE (test_bb)->count = count;
+         probability = BRANCH_EDGE (test_bb)->probability;
+         BRANCH_EDGE (test_bb)->probability
+           = FALLTHRU_EDGE (test_bb)->probability;
+         FALLTHRU_EDGE (test_bb)->probability = probability;
+         update_br_prob_note (test_bb);
+       }
     }
 
   /* Move the insns out of MERGE_BB to before the branch.  */
@@ -2667,10 +2654,21 @@ dead_or_predicable (test_bb, merge_bb, other_bb, new_dest, reversep)
       if (end == merge_bb->end)
        merge_bb->end = PREV_INSN (head);
 
-      squeeze_notes (&head, &end);
+      if (squeeze_notes (&head, &end))
+       return TRUE;
 
       reorder_insns (head, end, PREV_INSN (earliest));
     }
+
+  /* Remove the jump and edge if we can.  */
+  if (other_bb == new_dest)
+    {
+      delete_insn (jump);
+      remove_edge (BRANCH_EDGE (test_bb));
+      /* ??? Can't merge blocks here, as then_bb is still in use.
+        At minimum, the merge will get done just before bb-reorder.  */
+    }
+
   return TRUE;
 
  cancel:
@@ -2684,7 +2682,7 @@ void
 if_convert (x_life_data_ok)
      int x_life_data_ok;
 {
-  int block_num;
+  basic_block bb;
 
   num_possible_if_blocks = 0;
   num_updated_if_blocks = 0;
@@ -2699,23 +2697,16 @@ if_convert (x_life_data_ok)
   post_dominators = NULL;
   if (HAVE_conditional_execution || life_data_ok)
     {
-      post_dominators = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
+      post_dominators = sbitmap_vector_alloc (last_basic_block, last_basic_block);
       calculate_dominance_info (NULL, post_dominators, CDI_POST_DOMINATORS);
     }
-
-  /* Record initial block numbers.  */
-  for (block_num = 0; block_num < n_basic_blocks; block_num++)
-    SET_ORIG_INDEX (BASIC_BLOCK (block_num), block_num);
+  if (life_data_ok)
+    clear_bb_flags ();
 
   /* Go through each of the basic blocks looking for things to convert.  */
-  for (block_num = 0; block_num < n_basic_blocks; )
-    {
-      basic_block bb = BASIC_BLOCK (block_num);
-      if (find_if_header (bb))
-       block_num = bb->index;
-      else 
-       block_num++;
-    }
+  FOR_EACH_BB (bb)
+    while (find_if_header (bb))
+      continue;
 
   if (post_dominators)
     sbitmap_vector_free (post_dominators);
@@ -2723,31 +2714,20 @@ if_convert (x_life_data_ok)
   if (rtl_dump_file)
     fflush (rtl_dump_file);
 
+  clear_aux_for_blocks ();
+
   /* Rebuild life info for basic blocks that require it.  */
   if (num_removed_blocks && life_data_ok)
     {
-      sbitmap update_life_blocks = sbitmap_alloc (n_basic_blocks);
-      sbitmap_zero (update_life_blocks);
-
       /* If we allocated new pseudos, we must resize the array for sched1.  */
       if (max_regno < max_reg_num ())
        {
          max_regno = max_reg_num ();
          allocate_reg_info (max_regno, FALSE, FALSE);
        }
-
-      for (block_num = 0; block_num < n_basic_blocks; block_num++)
-       if (UPDATE_LIFE (BASIC_BLOCK (block_num)))
-         SET_BIT (update_life_blocks, block_num);
-
-      count_or_remove_death_notes (update_life_blocks, 1);
-      /* ??? See about adding a mode that verifies that the initial
-       set of blocks don't let registers come live.  */
-      update_life_info (update_life_blocks, UPDATE_LIFE_GLOBAL,
-                       PROP_DEATH_NOTES | PROP_SCAN_DEAD_CODE
-                       | PROP_KILL_DEAD_CODE);
-
-      sbitmap_free (update_life_blocks);
+      update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES,
+                                       PROP_DEATH_NOTES | PROP_SCAN_DEAD_CODE
+                                       | PROP_KILL_DEAD_CODE);
     }
 
   /* Write the final stats.  */