Commit eb081fd0 by Jan Hubicka Committed by Jan Hubicka

ipa-utils.c (ipa_merge_profiles): Be sure that all type transtions of counters are done same way.

	* ipa-utils.c (ipa_merge_profiles): Be sure that all type transtions
	of counters are done same way.

From-SVN: r278809
parent 2e7fd867
2019-11-28 Jan Hubicka <hubicka@ucw.cz> 2019-11-28 Jan Hubicka <hubicka@ucw.cz>
* ipa-utils.c (ipa_merge_profiles): Be sure that all type transtions
of counters are done same way.
2019-11-28 Jan Hubicka <hubicka@ucw.cz>
* ipa-cp.c (update_profiling_info): Fix scaling. * ipa-cp.c (update_profiling_info): Fix scaling.
2019-11-28 Richard Biener <rguenther@suse.de> 2019-11-28 Richard Biener <rguenther@suse.de>
...@@ -398,6 +398,7 @@ ipa_merge_profiles (struct cgraph_node *dst, ...@@ -398,6 +398,7 @@ ipa_merge_profiles (struct cgraph_node *dst,
tree oldsrcdecl = src->decl; tree oldsrcdecl = src->decl;
struct function *srccfun, *dstcfun; struct function *srccfun, *dstcfun;
bool match = true; bool match = true;
bool copy_counts = false;
if (!src->definition if (!src->definition
|| !dst->definition) || !dst->definition)
...@@ -429,10 +430,26 @@ ipa_merge_profiles (struct cgraph_node *dst, ...@@ -429,10 +430,26 @@ ipa_merge_profiles (struct cgraph_node *dst,
} }
profile_count orig_count = dst->count; profile_count orig_count = dst->count;
if (dst->count.initialized_p () && dst->count.ipa () == dst->count) /* Either sum the profiles if both are IPA and not global0, or
dst->count += src->count.ipa (); pick more informative one (that is nonzero IPA if other is
else uninitialized, guessed or global0). */
dst->count = src->count.ipa ();
if ((dst->count.ipa ().nonzero_p ()
|| src->count.ipa ().nonzero_p ())
&& dst->count.ipa ().initialized_p ()
&& src->count.ipa ().initialized_p ())
dst->count = dst->count.ipa () + src->count.ipa ();
else if (dst->count.ipa ().initialized_p ())
;
else if (src->count.ipa ().initialized_p ())
{
copy_counts = true;
dst->count = src->count.ipa ();
}
/* If no updating needed return early. */
if (dst->count == orig_count)
return;
/* First handle functions with no gimple body. */ /* First handle functions with no gimple body. */
if (dst->thunk.thunk_p || dst->alias if (dst->thunk.thunk_p || dst->alias
...@@ -544,6 +561,16 @@ ipa_merge_profiles (struct cgraph_node *dst, ...@@ -544,6 +561,16 @@ ipa_merge_profiles (struct cgraph_node *dst,
struct cgraph_edge *e, *e2; struct cgraph_edge *e, *e2;
basic_block srcbb, dstbb; basic_block srcbb, dstbb;
/* Function and global profile may be out of sync. First scale it same
way as fixup_cfg would. */
profile_count srcnum = src->count;
profile_count srcden = ENTRY_BLOCK_PTR_FOR_FN (srccfun)->count;
bool srcscale = srcnum.initialized_p () && !(srcnum == srcden);
profile_count dstnum = orig_count;
profile_count dstden = ENTRY_BLOCK_PTR_FOR_FN (dstcfun)->count;
bool dstscale = !copy_counts
&& dstnum.initialized_p () && !(dstnum == dstden);
/* TODO: merge also statement histograms. */ /* TODO: merge also statement histograms. */
FOR_ALL_BB_FN (srcbb, srccfun) FOR_ALL_BB_FN (srcbb, srccfun)
{ {
...@@ -551,15 +578,15 @@ ipa_merge_profiles (struct cgraph_node *dst, ...@@ -551,15 +578,15 @@ ipa_merge_profiles (struct cgraph_node *dst,
dstbb = BASIC_BLOCK_FOR_FN (dstcfun, srcbb->index); dstbb = BASIC_BLOCK_FOR_FN (dstcfun, srcbb->index);
/* Either sum the profiles if both are IPA and not global0, or profile_count srccount = srcbb->count;
pick more informative one (that is nonzero IPA if other is if (srcscale)
uninitialized, guessed or global0). */ srccount = srccount.apply_scale (srcnum, srcden);
if (!dstbb->count.ipa ().initialized_p () if (dstscale)
|| (dstbb->count.ipa () == profile_count::zero () dstbb->count = dstbb->count.apply_scale (dstnum, dstden);
&& (srcbb->count.ipa ().initialized_p ()
&& !(srcbb->count.ipa () == profile_count::zero ())))) if (copy_counts)
{ {
dstbb->count = srcbb->count; dstbb->count = srccount;
for (i = 0; i < EDGE_COUNT (srcbb->succs); i++) for (i = 0; i < EDGE_COUNT (srcbb->succs); i++)
{ {
edge srce = EDGE_SUCC (srcbb, i); edge srce = EDGE_SUCC (srcbb, i);
...@@ -568,18 +595,21 @@ ipa_merge_profiles (struct cgraph_node *dst, ...@@ -568,18 +595,21 @@ ipa_merge_profiles (struct cgraph_node *dst,
dste->probability = srce->probability; dste->probability = srce->probability;
} }
} }
else if (srcbb->count.ipa ().initialized_p () else
&& !(srcbb->count.ipa () == profile_count::zero ()))
{ {
for (i = 0; i < EDGE_COUNT (srcbb->succs); i++) for (i = 0; i < EDGE_COUNT (srcbb->succs); i++)
{ {
edge srce = EDGE_SUCC (srcbb, i); edge srce = EDGE_SUCC (srcbb, i);
edge dste = EDGE_SUCC (dstbb, i); edge dste = EDGE_SUCC (dstbb, i);
dste->probability = dste->probability =
dste->probability * dstbb->count.probability_in (dstbb->count + srcbb->count) dste->probability * dstbb->count.ipa ().probability_in
+ srce->probability * srcbb->count.probability_in (dstbb->count + srcbb->count); (dstbb->count.ipa ()
+ srccount.ipa ())
+ srce->probability * srcbb->count.ipa ().probability_in
(dstbb->count.ipa ()
+ srccount.ipa ());
} }
dstbb->count += srcbb->count; dstbb->count = dstbb->count.ipa () + srccount.ipa ();
} }
} }
push_cfun (dstcfun); push_cfun (dstcfun);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment