OSDN Git Service

* gfortran.dg/underflow.f90: Use tiny(x)/huge(x).
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-loop-ch.c
index 6d12271..c465e2e 100644 (file)
@@ -127,9 +127,11 @@ copy_loop_headers (void)
   unsigned i;
   struct loop *loop;
   basic_block header;
-  edge exit;
-  basic_block *bbs;
+  edge exit, entry;
+  basic_block *bbs, *copied_bbs;
   unsigned n_bbs;
+  unsigned bbs_size;
+  gcov_type entry_count, body_count, total_count;
 
   loops = loop_optimizer_init (dump_file);
   if (!loops)
@@ -145,6 +147,8 @@ copy_loop_headers (void)
 #endif
 
   bbs = xmalloc (sizeof (basic_block) * n_basic_blocks);
+  copied_bbs = xmalloc (sizeof (basic_block) * n_basic_blocks);
+  bbs_size = n_basic_blocks;
 
   for (i = 1; i < loops->num; i++)
     {
@@ -180,6 +184,7 @@ copy_loop_headers (void)
          else
            exit = EDGE_SUCC (header, 1);
          bbs[n_bbs++] = header;
+         gcc_assert (bbs_size > n_bbs);
          header = exit->dest;
        }
 
@@ -196,13 +201,33 @@ copy_loop_headers (void)
       if (!single_pred_p (exit->dest))
        exit = single_succ_edge (loop_split_edge_with (exit, NULL));
 
-      if (!tree_duplicate_sese_region (loop_preheader_edge (loop), exit,
-                                      bbs, n_bbs, NULL))
+      entry = loop_preheader_edge (loop);
+      entry_count = entry->src->count;
+      body_count = exit->dest->count;
+
+      if (!tree_duplicate_sese_region (entry, exit, bbs, n_bbs, copied_bbs))
        {
          fprintf (dump_file, "Duplication failed.\n");
          continue;
        }
 
+      /* Fix profiling info.  Scaling is done in gcov_type arithmetic to
+        avoid losing information; this is slow, but is done at most
+        once per loop.  We special case 0 to avoid division by 0;
+         probably other special cases exist.  */
+      total_count = body_count + entry_count;
+      if (total_count == 0LL)
+       {
+         scale_bbs_frequencies_int (bbs, n_bbs, 0, 1);
+         scale_bbs_frequencies_int (copied_bbs, n_bbs, 0, 1);
+       }
+      else
+       {
+         scale_bbs_frequencies_gcov_type (bbs, n_bbs, body_count, total_count);
+         scale_bbs_frequencies_gcov_type (copied_bbs, n_bbs, entry_count, 
+                                          total_count);
+       }
+
       /* Ensure that the latch and the preheader is simple (we know that they
         are not now, since there was the loop exit condition.  */
       loop_split_edge_with (loop_preheader_edge (loop), NULL);
@@ -210,10 +235,7 @@ copy_loop_headers (void)
     }
 
   free (bbs);
-
-#ifdef ENABLE_CHECKING
-  verify_loop_closed_ssa ();
-#endif
+  free (copied_bbs);
 
   loop_optimizer_finalize (loops, NULL);
 }