diff mbox

Use direct computation to calculate fallthrough edge count.

Message ID CAO2gOZWkEtcyDNF41W3tsKVA1ckF4h59Q868qu9WpxziEQ0k2A@mail.gmail.com
State New
Headers show

Commit Message

Dehao Chen May 16, 2014, 5:24 p.m. UTC
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  <dehao@google.com>

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

Comments

Jan Hubicka May 16, 2014, 5:26 p.m. UTC | #1
> 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?

OK,
thanks!

Honza
> 
> Thanks,
> Dehao
> 
> gcc/ChangeLog:
> 2014-05-16  Dehao Chen  <dehao@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)
diff mbox

Patch

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)