Hi,

the issue in PR 49786 has been well summarized in comment #12.
Basically, the multiplication we do when updating counts of edges
overflows.  I looked at how this was handled previously in IPA-CP and
the following should be an equivalent solution.

This patch fixes the LTO profiled bootstrap and I have tested it by
doing a usual non-LTO and non-profiled bootstrap and testsuite
(without any issues) run as well as running the testsuite on the
compiler produced by the LTO profiled bootstrap.  I compared the
second set of testsuite results with both the results obtained from a
revision before the IPA-CP submission and the current normal bootstrap
ones and it seemed fine (although there were a few dump scan
failures).  (All of the above was done on x86_64-linux.)

So, OK for trunk?

Thanks,

Martin


2011-07-25  Martin Jambor  <mjam...@suse.cz>

        PR bootstrap/49786
        * ipa-cp.c (update_profiling_info): Avoid overflow when updating
        counts.
        (update_specialized_profile): Likewise.

Index: src/gcc/ipa-cp.c
===================================================================
--- src.orig/gcc/ipa-cp.c
+++ src/gcc/ipa-cp.c
@@ -1877,7 +1877,6 @@ dump_profile_updates (struct cgraph_node
             cgraph_node_name (cs->callee), (HOST_WIDE_INT) cs->count);
 }
 
-
 /* After a specialized NEW_NODE version of ORIG_NODE has been created, update
    their profile information to reflect this.  */
 
@@ -1923,12 +1922,14 @@ update_profiling_info (struct cgraph_nod
 
   for (cs = new_node->callees; cs ; cs = cs->next_callee)
     if (cs->frequency)
-      cs->count = cs->count * new_sum / orig_node_count;
+      cs->count = cs->count * (new_sum * REG_BR_PROB_BASE
+                              / orig_node_count) / REG_BR_PROB_BASE;
     else
       cs->count = 0;
 
   for (cs = orig_node->callees; cs ; cs = cs->next_callee)
-    cs->count = cs->count * remainder / orig_node_count;
+    cs->count = cs->count * (remainder * REG_BR_PROB_BASE
+                            / orig_node_count) / REG_BR_PROB_BASE;
 
   if (dump_file)
     dump_profile_updates (orig_node, new_node);
@@ -1966,7 +1967,8 @@ update_specialized_profile (struct cgrap
 
   for (cs = orig_node->callees; cs ; cs = cs->next_callee)
     {
-      gcov_type dec = cs->count * redirected_sum / orig_node_count;
+      gcov_type dec = cs->count * (redirected_sum * REG_BR_PROB_BASE
+                                  / orig_node_count) / REG_BR_PROB_BASE;
       if (dec < cs->count)
        cs->count -= dec;
       else

Reply via email to