This patch uses direct computation (instead of indirect minus
computation) to calculate fallthrough edge's count and frequency. This
is less error-prone when the profile is inconsistent (e.g. all succ
edge counts sums larger than bb count).

Bootstrapped and regression test on-going.

OK for trunk if test pass?

Thanks,
Dehao

gcc/ChangeLog:
2014-05-16  Dehao Chen  <de...@google.com>

        * cfghooks.c (make_forwarder_block): Use direct computation to
        get fall-through edge's count and frequency.

Index: gcc/cfghooks.c
===================================================================
--- gcc/cfghooks.c (revision 210518)
+++ gcc/cfghooks.c (working copy)
@@ -833,6 +833,9 @@ make_forwarder_block (basic_block bb, bool (*redir

   fallthru = split_block_after_labels (bb);
   dummy = fallthru->src;
+  dummy->count = 0;
+  dummy->frequency = 0;
+  fallthru->count = 0;
   bb = fallthru->dest;

   /* Redirect back edges we want to keep.  */
@@ -842,20 +845,13 @@ make_forwarder_block (basic_block bb, bool (*redir

       if (redirect_edge_p (e))
  {
+  dummy->frequency += EDGE_FREQUENCY (e);
+  dummy->count += e->count;
+  fallthru->count += e->count;
   ei_next (&ei);
   continue;
  }

-      dummy->frequency -= EDGE_FREQUENCY (e);
-      dummy->count -= e->count;
-      if (dummy->frequency < 0)
- dummy->frequency = 0;
-      if (dummy->count < 0)
- dummy->count = 0;
-      fallthru->count -= e->count;
-      if (fallthru->count < 0)
- fallthru->count = 0;
-
       e_src = e->src;
       jump = redirect_edge_and_branch_force (e, bb);
       if (jump != NULL)

Reply via email to