From 84895d28940b46040028e8736adbd83dc2d77b23 Mon Sep 17 00:00:00 2001 From: hubicka Date: Mon, 6 Nov 2017 13:45:41 +0000 Subject: [PATCH] PR bootstrap/82832 * ipa-inline-transform.c (update_noncloned_frequencies): Always scale. (inline_transform): Likewise. * predict.c (counts_to_freqs): Remove useless conditional. * profile-count.h (profile_count::apply_scale): Move sanity check. * tree-inline.c (copy_bb): Always scale. (copy_cfg_body): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254452 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 11 +++++++++++ gcc/ipa-inline-transform.c | 27 +++++++++++++++++++-------- gcc/predict.c | 3 +-- gcc/profile-count.h | 2 +- gcc/tree-inline.c | 31 +++++++++++++++++++++++++------ 5 files changed, 57 insertions(+), 17 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b21c5fce2ad..26afa77f726 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2017-11-06 Jan Hubicka + + PR bootstrap/82832 + * ipa-inline-transform.c (update_noncloned_frequencies): Always + scale. + (inline_transform): Likewise. + * predict.c (counts_to_freqs): Remove useless conditional. + * profile-count.h (profile_count::apply_scale): Move sanity check. + * tree-inline.c (copy_bb): Always scale. + (copy_cfg_body): Likewise. + 2017-11-06 Christophe Lyon PR target/67591 diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c index 886e8edd473..e367df7df0e 100644 --- a/gcc/ipa-inline-transform.c +++ b/gcc/ipa-inline-transform.c @@ -59,7 +59,18 @@ update_noncloned_frequencies (struct cgraph_node *node, profile_count den) { struct cgraph_edge *e; - bool scale = (num == profile_count::zero () || den > 0); + + /* We always must scale to be sure counters end up compatible. + If den is zero, just force it nonzero and hope for reasonable + approximation. + When num is forced nonzero, also update den, so we do not scale profile + to 0. */ + if (!(num == den) + && !(den.force_nonzero () == den)) + { + den = den.force_nonzero (); + num = num.force_nonzero (); + } /* We do not want to ignore high loop nest after freq drops to 0. */ if (!freq_scale) @@ -71,19 +82,16 @@ update_noncloned_frequencies (struct cgraph_node *node, e->frequency = CGRAPH_FREQ_MAX; if (!e->inline_failed) update_noncloned_frequencies (e->callee, freq_scale, num, den); - if (scale) - e->count = e->count.apply_scale (num, den); + e->count = e->count.apply_scale (num, den); } for (e = node->indirect_calls; e; e = e->next_callee) { e->frequency = e->frequency * (gcov_type) freq_scale / CGRAPH_FREQ_BASE; if (e->frequency > CGRAPH_FREQ_MAX) e->frequency = CGRAPH_FREQ_MAX; - if (scale) - e->count = e->count.apply_scale (num, den); + e->count = e->count.apply_scale (num, den); } - if (scale) - node->count = node->count.apply_scale (num, den); + node->count = node->count.apply_scale (num, den); } /* We removed or are going to remove the last call to NODE. @@ -692,7 +700,10 @@ inline_transform (struct cgraph_node *node) basic_block bb; FOR_ALL_BB_FN (bb, cfun) - bb->count = bb->count.apply_scale (num, den); + if (num == profile_count::zero ()) + bb->count = bb->count.global0 (); + else + bb->count = bb->count.apply_scale (num, den); ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count; } todo = optimize_inline_calls (current_function_decl); diff --git a/gcc/predict.c b/gcc/predict.c index cf42ccbd903..0fd2b72e135 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -3324,8 +3324,7 @@ counts_to_freqs (void) basic_block bb; FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb) - if (!(bb->count < true_count_max)) - true_count_max = true_count_max.max (bb->count); + true_count_max = true_count_max.max (bb->count); cfun->cfg->count_max = true_count_max; diff --git a/gcc/profile-count.h b/gcc/profile-count.h index d793d11c830..f16bbcb2b9f 100644 --- a/gcc/profile-count.h +++ b/gcc/profile-count.h @@ -949,9 +949,9 @@ public: return num; if (!initialized_p () || !num.initialized_p () || !den.initialized_p ()) return profile_count::uninitialized (); - gcc_checking_assert (den.m_val); if (num == den) return *this; + gcc_checking_assert (den.m_val); profile_count ret; uint64_t val; diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 040799c778c..7ef107247b5 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1770,8 +1770,18 @@ copy_bb (copy_body_data *id, basic_block bb, basic_block copy_basic_block; tree decl; basic_block prev; - bool scale = !num.initialized_p () - || (den.nonzero_p () || num == profile_count::zero ()); + + /* We always must scale to be sure counters end up compatible. + If den is zero, just force it nonzero and hope for reasonable + approximation. + When num is forced nonzero, also update den, so we do not scale profile + to 0. */ + if (!(num == den) + && !(den.force_nonzero () == den)) + { + den = den.force_nonzero (); + num = num.force_nonzero (); + } /* Search for previous copied basic block. */ prev = bb->prev_bb; @@ -1781,10 +1791,7 @@ copy_bb (copy_body_data *id, basic_block bb, /* create_basic_block() will append every new block to basic_block_info automatically. */ copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux); - if (scale) - copy_basic_block->count = bb->count.apply_scale (num, den); - else if (num.initialized_p ()) - copy_basic_block->count = bb->count; + copy_basic_block->count = bb->count.apply_scale (num, den); copy_gsi = gsi_start_bb (copy_basic_block); @@ -2691,6 +2698,18 @@ copy_cfg_body (copy_body_data * id, profile_count, profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count; profile_count num = entry_block_map->count; + /* We always must scale to be sure counters end up compatible. + If den is zero, just force it nonzero and hope for reasonable + approximation. + When num is forced nonzero, also update den, so we do not scale profile + to 0. */ + if (!(num == den) + && !(den.force_nonzero () == den)) + { + den = den.force_nonzero (); + num = num.force_nonzero (); + } + cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl); /* Register specific tree functions. */ -- 2.11.4.GIT