OSDN Git Service

* varasm.c (default_assemble_visibility): Remove extra ().
[pf3gnuchains/gcc-fork.git] / gcc / tree-if-conv.c
index 52bcfba..d22a617 100644 (file)
@@ -126,7 +126,7 @@ static void combine_blocks (struct loop *);
 static tree ifc_temp_var (tree, tree);
 static bool pred_blocks_visited_p (basic_block, bitmap *);
 static basic_block * get_loop_body_in_if_conv_order (const struct loop *loop);
-static bool bb_with_exit_edge_p (basic_block);
+static bool bb_with_exit_edge_p (struct loop *, basic_block);
 
 /* List of basic blocks in if-conversion-suitable order.  */
 static basic_block *ifc_bbs;
@@ -187,9 +187,9 @@ tree_if_conversion (struct loop *loop, bool for_vectorizer)
 
       /* If current bb has only one successor, then consider it as an
         unconditional goto.  */
-      if (EDGE_COUNT (bb->succs) == 1)
+      if (single_succ_p (bb))
        {
-         basic_block bb_n = EDGE_SUCC (bb, 0)->dest;
+         basic_block bb_n = single_succ (bb);
          if (cond != NULL_TREE)
            add_to_predicate_list (bb_n, cond);
          cond = NULL_TREE;
@@ -271,9 +271,8 @@ static void
 tree_if_convert_cond_expr (struct loop *loop, tree stmt, tree cond,
                           block_stmt_iterator *bsi)
 {
-  tree c, c2, new_cond;
+  tree c, c2;
   edge true_edge, false_edge;
-  new_cond = NULL_TREE;
 
   gcc_assert (TREE_CODE (stmt) == COND_EXPR);
 
@@ -294,8 +293,8 @@ tree_if_convert_cond_expr (struct loop *loop, tree stmt, tree cond,
   /* Add new condition into destination's predicate list.  */
 
   /* If 'c' is true then TRUE_EDGE is taken.  */
-  new_cond = add_to_dst_predicate_list (loop, true_edge->dest, cond,
-                                       unshare_expr (c), bsi);
+  add_to_dst_predicate_list (loop, true_edge->dest, cond,
+                            unshare_expr (c), bsi);
 
   if (!is_gimple_reg(c) && is_gimple_condexpr (c))
     {
@@ -312,7 +311,7 @@ tree_if_convert_cond_expr (struct loop *loop, tree stmt, tree cond,
   /* Now this conditional statement is redundant. Remove it.
      But, do not remove exit condition! Update exit condition
      using new condition.  */
-  if (!bb_with_exit_edge_p (bb_for_stmt (stmt)))
+  if (!bb_with_exit_edge_p (loop, bb_for_stmt (stmt)))
     {
       bsi_remove (bsi);
       cond = NULL_TREE;
@@ -405,7 +404,7 @@ if_convertible_modify_expr_p (struct loop *loop, basic_block bb, tree m_expr)
 
   if (TREE_CODE (TREE_OPERAND (m_expr, 0)) != SSA_NAME
       && bb != loop->header
-      && !bb_with_exit_edge_p (bb))
+      && !bb_with_exit_edge_p (loop, bb))
     {
       if (dump_file && (dump_flags & TDF_DETAILS))
        {
@@ -534,8 +533,6 @@ if_convertible_loop_p (struct loop *loop, bool for_vectorizer ATTRIBUTE_UNUSED)
       return false;
     }
 
-  flow_loop_scan (loop, LOOP_ALL);
-
   /* If only one block, no need for if-conversion.  */
   if (loop->num_nodes <= 2)
     {
@@ -545,7 +542,7 @@ if_convertible_loop_p (struct loop *loop, bool for_vectorizer ATTRIBUTE_UNUSED)
     }
 
   /* More than one loop exit is too much to handle.  */
-  if (loop->num_exits > 1)
+  if (!loop->single_exit)
     {
       if (dump_file && (dump_flags & TDF_DETAILS))
        fprintf (dump_file, "multiple exits\n");
@@ -557,8 +554,10 @@ if_convertible_loop_p (struct loop *loop, bool for_vectorizer ATTRIBUTE_UNUSED)
   /* If one of the loop header's edge is exit edge then do not apply
      if-conversion.  */
   FOR_EACH_EDGE (e, ei, loop->header->succs)
-    if ( e->flags & EDGE_LOOP_EXIT)
-      return false;
+    {
+      if (loop_exit_edge_p (loop, e))
+       return false;
+    }
 
   compute_immediate_uses (TDFA_USE_OPS|TDFA_USE_VOPS, NULL);
 
@@ -593,7 +592,7 @@ if_convertible_loop_p (struct loop *loop, bool for_vectorizer ATTRIBUTE_UNUSED)
        if (!if_convertible_phi_p (loop, bb, phi))
          return false;
 
-      if (bb_with_exit_edge_p (bb))
+      if (bb_with_exit_edge_p (loop, bb))
        exit_bb_seen = true;
     }
 
@@ -858,7 +857,9 @@ combine_blocks (struct loop *loop)
   basic_block bb, exit_bb, merge_target_bb;
   unsigned int orig_loop_num_nodes = loop->num_nodes;
   unsigned int i;
+  unsigned int n_exits;
 
+  get_loop_exit_edges (loop, &n_exits);
   /* Process phi nodes to prepare blocks for merge.  */
   process_phi_nodes (loop);
 
@@ -874,27 +875,28 @@ combine_blocks (struct loop *loop)
 
       bb = ifc_bbs[i];
 
-      if (!exit_bb && bb_with_exit_edge_p (bb))
+      if (!exit_bb && bb_with_exit_edge_p (loop, bb))
          exit_bb = bb;
 
       if (bb == exit_bb)
        {
-         edge new_e;
          edge_iterator ei;
 
          /* Connect this node with loop header.  */
-         new_e = make_edge (ifc_bbs[0], bb, EDGE_FALLTHRU);
+         make_edge (ifc_bbs[0], bb, EDGE_FALLTHRU);
          set_immediate_dominator (CDI_DOMINATORS, bb, ifc_bbs[0]);
 
          if (exit_bb != loop->latch)
            {
              /* Redirect non-exit edge to loop->latch.  */
              FOR_EACH_EDGE (e, ei, bb->succs)
-               if (!(e->flags & EDGE_LOOP_EXIT))
-                 {
-                   redirect_edge_and_branch (e, loop->latch);
-                   set_immediate_dominator (CDI_DOMINATORS, loop->latch, bb);
-                 }
+               {
+                 if (!loop_exit_edge_p (loop, e))
+                   {
+                     redirect_edge_and_branch (e, loop->latch);
+                     set_immediate_dominator (CDI_DOMINATORS, loop->latch, bb);
+                   }
+               }
            }
          continue;
        }
@@ -903,11 +905,22 @@ combine_blocks (struct loop *loop)
        continue;
 
       /* It is time to remove this basic block.         First remove edges.  */
-      while (EDGE_COUNT (bb->succs) > 0)
-       remove_edge (EDGE_SUCC (bb, 0));
       while (EDGE_COUNT (bb->preds) > 0)
        remove_edge (EDGE_PRED (bb, 0));
 
+      /* This is loop latch and loop does not have exit then do not
+        delete this basic block. Just remove its PREDS and reconnect 
+        loop->header and loop->latch blocks.  */
+      if (bb == loop->latch && n_exits == 0)
+       {
+         make_edge (loop->header, loop->latch, EDGE_FALLTHRU);
+         set_immediate_dominator (CDI_DOMINATORS, loop->latch, loop->header);
+         continue;
+       }
+
+      while (EDGE_COUNT (bb->succs) > 0)
+       remove_edge (EDGE_SUCC (bb, 0));
+
       /* Remove labels and make stmts member of loop->header.  */
       for (bsi = bsi_start (bb); !bsi_end_p (bsi); )
        {
@@ -1056,17 +1069,17 @@ get_loop_body_in_if_conv_order (const struct loop *loop)
   return blocks;
 }
 
-/* Return true if one of the basic block BB edge is loop exit.  */
+/* Return true if one of the basic block BB edge is exit of LOOP.  */
 
 static bool
-bb_with_exit_edge_p (basic_block bb)
+bb_with_exit_edge_p (struct loop *loop, basic_block bb)
 {
   edge e;
   edge_iterator ei;
   bool exit_edge_found = false;
 
   FOR_EACH_EDGE (e, ei, bb->succs)
-    if (e->flags & EDGE_LOOP_EXIT)
+    if (loop_exit_edge_p (loop, e))
       {
        exit_edge_found = true;
        break;