The early inliner compares a raw call-site count with scaled target counts.
This can reject a hot target when the AutoFDO scale is large. Scale the
call-site estimate and existing target counts before combining them with
recovered inlined-target counts. Calculate the target total only when
building a histogram.
For example, with a scale of 100, a call count of 10 and a target count
of 8 were compared as 10 and 800. Scale both to compare 1000 and 800.
Regression tested on aarch64-linux-gnu with no new regressions.
gcc/ChangeLog:
* auto-profile.cc (afdo_indirect_call): Calculate the total when
building
the histogram.
(afdo_vpt_for_early_inline): Scale the call and target counts.
Signed-off-by: Kugan Vivekanandarajah <[email protected]>
---
gcc/auto-profile.cc | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 9b9ab5f4d9a..a70bdd28c45 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -3306,17 +3306,12 @@ afdo_indirect_call (gcall *stmt, const icall_target_map
&map,
return false;
}
- gcov_type total = 0;
icall_target_map::const_iterator max_iter = map.end ();
for (icall_target_map::const_iterator iter = map.begin ();
iter != map.end (); ++iter)
- {
- total += iter->second;
- if (max_iter == map.end () || max_iter->second < iter->second)
- max_iter = iter;
- }
- total *= afdo_count_scale;
+ if (max_iter == map.end () || max_iter->second < iter->second)
+ max_iter = iter;
struct cgraph_node *direct_call = cgraph_node::get_for_asmname (
get_identifier (afdo_string_table->get_symbol_name (max_iter->first)));
if (direct_call == NULL)
@@ -3331,6 +3326,11 @@ afdo_indirect_call (gcall *stmt, const icall_target_map
&map,
if (!transform)
{
+ gcov_type total = 0;
+ for (const auto &target : map)
+ total += target.second;
+ total *= afdo_count_scale;
+
if (!direct_call->profile_id)
{
if (dump_file)
@@ -4802,7 +4802,9 @@ afdo_vpt_for_early_inline (cgraph_node *node)
bb_count = MAX (bb_count, info.count);
}
autofdo::afdo_source_profile->get_count_info (e->call_stmt, &info, node);
- info.count = bb_count;
+ info.count = bb_count * autofdo::afdo_count_scale;
+ for (auto &target : info.targets)
+ target.second *= autofdo::afdo_count_scale;
if (!autofdo::afdo_source_profile->update_inlined_ind_target
(e->call_stmt, &info, node))
continue;
--
2.34.1