OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / cfgcleanup.c
index 27af12f..6ff1614 100644 (file)
@@ -69,7 +69,7 @@ static bool crossjumps_occured;
    information; we should run df_analyze to enable more opportunities.  */
 static bool block_was_dirty;
 
-static bool try_crossjump_to_edge (int, edge, edge);
+static bool try_crossjump_to_edge (int, edge, edge, enum replace_direction);
 static bool try_crossjump_bb (int, basic_block);
 static bool outgoing_edges_match (int, basic_block, basic_block);
 static enum replace_direction old_insns_match_p (int, rtx, rtx);
@@ -599,9 +599,6 @@ try_forward_edges (int mode, basic_block b)
                             + REG_BR_PROB_BASE / 2)
                            / REG_BR_PROB_BASE);
 
-         if (!FORWARDER_BLOCK_P (b) && forwarder_block_p (b))
-           b->flags |= BB_FORWARDER_BLOCK;
-
          do
            {
              edge t;
@@ -646,8 +643,7 @@ try_forward_edges (int mode, basic_block b)
       ei_next (&ei);
     }
 
-  if (threaded_edges)
-    free (threaded_edges);
+  free (threaded_edges);
   return changed;
 }
 \f
@@ -887,7 +883,7 @@ merge_memattrs (rtx x, rtx y)
        MEM_ATTRS (x) = 0;
       else
        {
-         rtx mem_size;
+         HOST_WIDE_INT mem_size;
 
          if (MEM_ALIAS_SET (x) != MEM_ALIAS_SET (y))
            {
@@ -899,24 +895,28 @@ merge_memattrs (rtx x, rtx y)
            {
              set_mem_expr (x, 0);
              set_mem_expr (y, 0);
-             set_mem_offset (x, 0);
-             set_mem_offset (y, 0);
+             clear_mem_offset (x);
+             clear_mem_offset (y);
            }
-         else if (MEM_OFFSET (x) != MEM_OFFSET (y))
+         else if (MEM_OFFSET_KNOWN_P (x) != MEM_OFFSET_KNOWN_P (y)
+                  || (MEM_OFFSET_KNOWN_P (x)
+                      && MEM_OFFSET (x) != MEM_OFFSET (y)))
            {
-             set_mem_offset (x, 0);
-             set_mem_offset (y, 0);
+             clear_mem_offset (x);
+             clear_mem_offset (y);
            }
 
-         if (!MEM_SIZE (x))
-           mem_size = NULL_RTX;
-         else if (!MEM_SIZE (y))
-           mem_size = NULL_RTX;
+         if (MEM_SIZE_KNOWN_P (x) && MEM_SIZE_KNOWN_P (y))
+           {
+             mem_size = MAX (MEM_SIZE (x), MEM_SIZE (y));
+             set_mem_size (x, mem_size);
+             set_mem_size (y, mem_size);
+           }
          else
-           mem_size = GEN_INT (MAX (INTVAL (MEM_SIZE (x)),
-                                    INTVAL (MEM_SIZE (y))));
-         set_mem_size (x, mem_size);
-         set_mem_size (y, mem_size);
+           {
+             clear_mem_size (x);
+             clear_mem_size (y);
+           }
 
          set_mem_align (x, MIN (MEM_ALIGN (x), MEM_ALIGN (y)));
          set_mem_align (y, MEM_ALIGN (x));
@@ -1078,6 +1078,25 @@ old_insns_match_p (int mode ATTRIBUTE_UNUSED, rtx i1, rtx i2)
   if (NOTE_INSN_BASIC_BLOCK_P (i1) && NOTE_INSN_BASIC_BLOCK_P (i2))
     return dir_both;
 
+  /* ??? Do not allow cross-jumping between different stack levels.  */
+  p1 = find_reg_note (i1, REG_ARGS_SIZE, NULL);
+  p2 = find_reg_note (i2, REG_ARGS_SIZE, NULL);
+  if (p1 && p2)
+    {
+      p1 = XEXP (p1, 0);
+      p2 = XEXP (p2, 0);
+      if (!rtx_equal_p (p1, p2))
+        return dir_none;
+
+      /* ??? Worse, this adjustment had better be constant lest we
+         have differing incoming stack levels.  */
+      if (!frame_pointer_needed
+          && find_args_size_adjust (i1) == HOST_WIDE_INT_MIN)
+       return dir_none;
+    }
+  else if (p1 || p2)
+    return dir_none;
+
   p1 = PATTERN (i1);
   p2 = PATTERN (i2);
 
@@ -1468,7 +1487,19 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
   edge fallthru1 = 0, fallthru2 = 0;
   edge e1, e2;
   edge_iterator ei;
-
+  rtx last1, last2;
+  bool nonfakeedges;
+
+  /* If we performed shrink-wrapping, edges to the EXIT_BLOCK_PTR can
+     only be distinguished for JUMP_INSNs.  The two paths may differ in
+     whether they went through the prologue.  Sibcalls are fine, we know
+     that we either didn't need or inserted an epilogue before them.  */
+  if (crtl->shrink_wrapped
+      && single_succ_p (bb1) && single_succ (bb1) == EXIT_BLOCK_PTR
+      && !JUMP_P (BB_END (bb1))
+      && !(CALL_P (BB_END (bb1)) && SIBLING_CALL_P (BB_END (bb1))))
+    return false;
+  
   /* If BB1 has only one successor, we may be looking at either an
      unconditional jump, or a fake edge to exit.  */
   if (single_succ_p (bb1)
@@ -1666,9 +1697,15 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
        }
     }
 
+  last1 = BB_END (bb1);
+  last2 = BB_END (bb2);
+  if (DEBUG_INSN_P (last1))
+    last1 = prev_nondebug_insn (last1);
+  if (DEBUG_INSN_P (last2))
+    last2 = prev_nondebug_insn (last2);
   /* First ensure that the instructions match.  There may be many outgoing
      edges so this test is generally cheaper.  */
-  if (old_insns_match_p (mode, BB_END (bb1), BB_END (bb2)) != dir_both)
+  if (old_insns_match_p (mode, last1, last2) != dir_both)
     return false;
 
   /* Search the outgoing edges, ensure that the counts do match, find possible
@@ -1677,10 +1714,14 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
   if (EDGE_COUNT (bb1->succs) != EDGE_COUNT (bb2->succs))
     return false;
 
+  nonfakeedges = false;
   FOR_EACH_EDGE (e1, ei, bb1->succs)
     {
       e2 = EDGE_SUCC (bb2, ei.index);
 
+      if ((e1->flags & EDGE_FAKE) == 0)
+       nonfakeedges = true;
+
       if (e1->flags & EDGE_EH)
        nehedges1++;
 
@@ -1698,6 +1739,18 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
       || (fallthru1 != 0) != (fallthru2 != 0))
     return false;
 
+  /* If !ACCUMULATE_OUTGOING_ARGS, bb1 (and bb2) have no successors
+     and the last real insn doesn't have REG_ARGS_SIZE note, don't
+     attempt to optimize, as the two basic blocks might have different
+     REG_ARGS_SIZE depths.  For noreturn calls and unconditional
+     traps there should be REG_ARG_SIZE notes, they could be missing
+     for __builtin_unreachable () uses though.  */
+  if (!nonfakeedges
+      && !ACCUMULATE_OUTGOING_ARGS
+      && (!INSN_P (last1)
+          || !find_reg_note (last1, REG_ARGS_SIZE, NULL)))
+    return false;
+
   /* fallthru edges must be forwarded to the same destination.  */
   if (fallthru1)
     {
@@ -1761,16 +1814,18 @@ block_has_preserve_label (basic_block bb)
 
 /* E1 and E2 are edges with the same destination block.  Search their
    predecessors for common code.  If found, redirect control flow from
-   (maybe the middle of) E1->SRC to (maybe the middle of) E2->SRC.  */
+   (maybe the middle of) E1->SRC to (maybe the middle of) E2->SRC (dir_forward),
+   or the other way around (dir_backward).  DIR specifies the allowed
+   replacement direction.  */
 
 static bool
-try_crossjump_to_edge (int mode, edge e1, edge e2)
+try_crossjump_to_edge (int mode, edge e1, edge e2,
+                       enum replace_direction dir)
 {
   int nmatch;
   basic_block src1 = e1->src, src2 = e2->src;
   basic_block redirect_to, redirect_from, to_remove;
   basic_block osrc1, osrc2, redirect_edges_to, tmp;
-  enum replace_direction dir;
   rtx newpos1, newpos2;
   edge s;
   edge_iterator ei;
@@ -1826,7 +1881,6 @@ try_crossjump_to_edge (int mode, edge e1, edge e2)
     return false;
 
   /* ... and part the second.  */
-  dir = dir_forward;
   nmatch = flow_find_cross_jump (src1, src2, &newpos1, &newpos2, &dir);
 
   osrc1 = src1;
@@ -1836,6 +1890,16 @@ try_crossjump_to_edge (int mode, edge e1, edge e2)
   if (newpos2 != NULL_RTX)
     src2 = BLOCK_FOR_INSN (newpos2);
 
+  if (dir == dir_backward)
+    {
+#define SWAP(T, X, Y) do { T tmp = (X); (X) = (Y); (Y) = tmp; } while (0)
+      SWAP (basic_block, osrc1, osrc2);
+      SWAP (basic_block, src1, src2);
+      SWAP (edge, e1, e2);
+      SWAP (rtx, newpos1, newpos2);
+#undef SWAP
+    }
+
   /* Don't proceed with the crossjump unless we found a sufficient number
      of matching instructions or the 'from' block was totally matched
      (such that its predecessors will hopefully be redirected and the
@@ -2088,7 +2152,7 @@ try_crossjump_bb (int mode, basic_block bb)
                   || (fallthru->src->flags & BB_MODIFIED)))
            continue;
 
-         if (try_crossjump_to_edge (mode, e, fallthru))
+         if (try_crossjump_to_edge (mode, e, fallthru, dir_forward))
            {
              changed = true;
              ix = 0;
@@ -2136,7 +2200,9 @@ try_crossjump_bb (int mode, basic_block bb)
                   || (e2->src->flags & BB_MODIFIED)))
            continue;
 
-         if (try_crossjump_to_edge (mode, e, e2))
+         /* Both e and e2 are not fallthru edges, so we can crossjump in either
+            direction.  */
+         if (try_crossjump_to_edge (mode, e, e2, dir_both))
            {
              changed = true;
              ix = 0;
@@ -2182,7 +2248,14 @@ try_head_merge_bb (basic_block bb)
 
   cond = get_condition (jump, &move_before, true, false);
   if (cond == NULL_RTX)
-    move_before = jump;
+    {
+#ifdef HAVE_cc0
+      if (reg_mentioned_p (cc0_rtx, jump))
+       move_before = prev_nonnote_nondebug_insn (jump);
+      else
+#endif
+       move_before = jump;
+    }
 
   for (ix = 0; ix < nedges; ix++)
     if (EDGE_SUCC (bb, ix)->dest == EXIT_BLOCK_PTR)
@@ -2344,7 +2417,14 @@ try_head_merge_bb (basic_block bb)
       jump = BB_END (final_dest_bb);
       cond = get_condition (jump, &move_before, true, false);
       if (cond == NULL_RTX)
-       move_before = jump;
+       {
+#ifdef HAVE_cc0
+         if (reg_mentioned_p (cc0_rtx, jump))
+           move_before = prev_nonnote_nondebug_insn (jump);
+         else
+#endif
+           move_before = jump;
+       }
     }
 
   do
@@ -2681,7 +2761,10 @@ try_optimize_cfg (int mode)
 
              /* Simplify branch to branch.  */
              if (try_forward_edges (mode, b))
-               changed_here = true;
+               {
+                 update_forwarder_flag (b);
+                 changed_here = true;
+               }
 
              /* Look for shared code between blocks.  */
              if ((mode & CLEANUP_CROSSJUMP)
@@ -2977,8 +3060,6 @@ struct rtl_opt_pass pass_jump2 =
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
   TODO_ggc_collect,                     /* todo_flags_start */
-  TODO_dump_func | TODO_verify_rtl_sharing,/* todo_flags_finish */
+  TODO_verify_rtl_sharing,              /* todo_flags_finish */
  }
 };
-
-