]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/23475
authorrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Aug 2005 07:13:06 +0000 (07:13 +0000)
committerrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Aug 2005 07:13:06 +0000 (07:13 +0000)
* tree-ssa-loop-ivcanon.c (remove_empty_loop): Update frequencies
and counts.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@103593 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/tree-ssa-loop-ivcanon.c

index b2297dd2981f3cbbda0b40fca44a2c8d25cbd806..1a2068fad06a7a3b8a26f0e9ea77853ed8f4198a 100644 (file)
@@ -1,3 +1,9 @@
+2005-08-29  Zdenek Dvorak  <dvorakz@suse.cz>
+
+       PR tree-optimization/23475
+       * tree-ssa-loop-ivcanon.c (remove_empty_loop): Update frequencies
+       and counts.
+
 2005-08-28  Daniel Berlin  <dberlin@dberlin.org>
 
        Fix PR middle-end/22455
index 1788c33e037ba73dc871f5e6b4024918e5420074..9b818b215f217c76413710fa2deadf8e2fb70dfd 100644 (file)
@@ -491,9 +491,16 @@ empty_loop_p (struct loop *loop)
 static void
 remove_empty_loop (struct loop *loop)
 {
-  edge exit = single_dom_exit (loop);
+  edge exit = single_dom_exit (loop), non_exit;
   tree cond_stmt = last_stmt (exit->src);
   tree do_exit;
+  basic_block *body;
+  unsigned n_before, freq_in, freq_h;
+  gcov_type exit_count = exit->count;
+
+  non_exit = EDGE_SUCC (exit->src, 0);
+  if (non_exit == exit)
+    non_exit = EDGE_SUCC (exit->src, 1);
 
   if (exit->flags & EDGE_TRUE_VALUE)
     do_exit = boolean_true_node;
@@ -502,6 +509,34 @@ remove_empty_loop (struct loop *loop)
 
   COND_EXPR_COND (cond_stmt) = do_exit;
   update_stmt (cond_stmt);
+
+  /* Let us set the probabilities of the edges coming from the exit block.  */
+  exit->probability = REG_BR_PROB_BASE;
+  non_exit->probability = 0;
+  non_exit->count = 0;
+
+  /* Update frequencies and counts.  Everything before
+     the exit needs to be scaled FREQ_IN/FREQ_H times,
+     where FREQ_IN is the frequency of the entry edge
+     and FREQ_H is the frequency of the loop header.
+     Everything after the exit has zero frequency.  */
+  freq_h = loop->header->frequency;
+  freq_in = EDGE_FREQUENCY (loop_preheader_edge (loop));
+  if (freq_h != 0)
+    {
+      body = get_loop_body_in_dom_order (loop);
+      for (n_before = 1; n_before <= loop->num_nodes; n_before++)
+       if (body[n_before - 1] == exit->src)
+         break;
+      scale_bbs_frequencies_int (body, n_before, freq_in, freq_h);
+      scale_bbs_frequencies_int (body + n_before, loop->num_nodes - n_before,
+                                0, 1);
+      free (body);
+    }
+
+  /* Number of executions of exit is not changed, thus we need to restore
+     the original value.  */
+  exit->count = exit_count;
 }
 
 /* Removes LOOP if it is empty.  Returns true if LOOP is removed.  CHANGED