diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c24c0a5f343c473e02fc44265cc4b82fa0a392e8..5ab422c917ab7b11df27045a5fa99ec440800a87 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-11-17 Jan Hubicka <hubicka@ucw.cz> + + * tree-tailcall.c (eliminate_tail_call): Be more careful about not + disturbin profile of entry block. + 2017-11-17 Jan Hubicka <hubicka@ucw.cz> * ipa-fnsummary.c (estimate_node_size_and_time): Be more tolerant for diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c index 0e637147e8c57f7ee95f5769fe2c65e0d9162c74..212519cdfd7236f6b3c258937ed02613f53d191d 100644 --- a/gcc/tree-tailcall.c +++ b/gcc/tree-tailcall.c @@ -889,10 +889,18 @@ eliminate_tail_call (struct tailcall *t) /* Number of executions of function has reduced by the tailcall. */ e = single_succ_edge (gsi_bb (t->call_gsi)); - decrease_profile (EXIT_BLOCK_PTR_FOR_FN (cfun), e->count ()); - decrease_profile (ENTRY_BLOCK_PTR_FOR_FN (cfun), e->count ()); + + profile_count count = e->count (); + + /* When profile is inconsistent and the recursion edge is more frequent + than number of executions of functions, scale it down, so we do not end + up with 0 executions of entry block. */ + if (count >= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count) + count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.apply_scale (7, 8); + decrease_profile (EXIT_BLOCK_PTR_FOR_FN (cfun), count); + decrease_profile (ENTRY_BLOCK_PTR_FOR_FN (cfun), count); if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) - decrease_profile (e->dest, e->count ()); + decrease_profile (e->dest, count); /* Replace the call by a jump to the start of function. */ e = redirect_edge_and_branch (single_succ_edge (gsi_bb (t->call_gsi)),