Hi, This patch fixes scaling in update_profiling_info. My understanding is that there is orig_node and new_node which have some counts that comes from cloning but real distribution of execution counts is determined by counting callers to new clone. This is new_sum. We thus want to scale orig_node to orig_node->count-new_sum and new_node to new_sum.
Code seems to miss initialization of new_sum and updating of indirect calls. Also i do not see why new_node->count and orig_node->count are same (because orig_node can be updated multiple times) and thus I added code to save original new_node->count so scaling can be done properly. proiflebootstrapped/regtested x86_64. Martin, I would like you to take a look on this. Honza * ipa-cp.c (update_profiling_info): Fix scaling. Index: ipa-cp.c =================================================================== --- ipa-cp.c (revision 278778) +++ ipa-cp.c (working copy) @@ -4091,6 +4091,7 @@ update_profiling_info (struct cgraph_nod struct caller_statistics stats; profile_count new_sum, orig_sum; profile_count remainder, orig_node_count = orig_node->count; + profile_count orig_new_node_count = new_node->count; if (!(orig_node_count.ipa () > profile_count::zero ())) return; @@ -4128,15 +4129,20 @@ update_profiling_info (struct cgraph_nod remainder = orig_node_count.combine_with_ipa_count (orig_node_count.ipa () - new_sum.ipa ()); new_sum = orig_node_count.combine_with_ipa_count (new_sum); + new_node->count = new_sum; orig_node->count = remainder; - profile_count::adjust_for_ipa_scaling (&new_sum, &orig_node_count); + profile_count::adjust_for_ipa_scaling (&new_sum, &orig_new_node_count); for (cs = new_node->callees; cs; cs = cs->next_callee) - cs->count = cs->count.apply_scale (new_sum, orig_node_count); + cs->count = cs->count.apply_scale (new_sum, orig_new_node_count); + for (cs = new_node->indirect_calls; cs; cs = cs->next_callee) + cs->count = cs->count.apply_scale (new_sum, orig_new_node_count); profile_count::adjust_for_ipa_scaling (&remainder, &orig_node_count); for (cs = orig_node->callees; cs; cs = cs->next_callee) cs->count = cs->count.apply_scale (remainder, orig_node_count); + for (cs = orig_node->indirect_calls; cs; cs = cs->next_callee) + cs->count = cs->count.apply_scale (remainder, orig_node_count); if (dump_file) dump_profile_updates (orig_node, new_node);