https://gcc.gnu.org/g:79d9ff28c2da0fde4aae0c034d7d39ef27558c14
commit r16-3582-g79d9ff28c2da0fde4aae0c034d7d39ef27558c14 Author: Jan Hubicka <[email protected]> Date: Thu Sep 4 17:29:07 2025 +0200 Fix ICE with auto-fdo and -fpartial-profiling With -fpartial-profling we ICE building perlbench and gcc from spec2k17 since afdo_annotate_cfg applies knowlede about zero profiles too early. This patch moves it after the early exit when profile is 0 everywhere and also fixes formatting issue in the next block. gcc/ChangeLog: * auto-profile.cc (afdo_annotate_cfg): Apply zero_bbs after early exit for missing profile; fix formating Diff: --- gcc/auto-profile.cc | 76 ++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc index 7ff952632c35..ce607a68d2ee 100644 --- a/gcc/auto-profile.cc +++ b/gcc/auto-profile.cc @@ -3875,22 +3875,6 @@ afdo_annotate_cfg (void) set_bb_annotated (bb, &annotated_bb); } } - /* We try to preserve static profile for BBs with 0 - afdo samples, but if even static profile agrees with 0, - consider it final so propagation works better. */ - for (basic_block bb : zero_bbs) - if (!bb->count.nonzero_p ()) - { - update_count_by_afdo_count (&bb->count, 0); - set_bb_annotated (bb, &annotated_bb); - if (dump_file) - { - fprintf (dump_file, " Annotating bb %i with count ", bb->index); - bb->count.dump (dump_file); - fprintf (dump_file, - " (has 0 count in both static and afdo profile)\n"); - } - } /* Exit without clobbering static profile if there was no non-zero count. */ if (!profile_found) @@ -3926,31 +3910,47 @@ afdo_annotate_cfg (void) free_dominance_info (CDI_POST_DOMINATORS); return; } + /* We try to preserve static profile for BBs with 0 + afdo samples, but if even static profile agrees with 0, + consider it final so propagation works better. */ + for (basic_block bb : zero_bbs) + if (!bb->count.nonzero_p ()) + { + update_count_by_afdo_count (&bb->count, 0); + set_bb_annotated (bb, &annotated_bb); + if (dump_file) + { + fprintf (dump_file, " Annotating bb %i with count ", bb->index); + bb->count.dump (dump_file); + fprintf (dump_file, + " (has 0 count in both static and afdo profile)\n"); + } + } /* Update profile. */ if (head_count > 0) - { - update_count_by_afdo_count (&ENTRY_BLOCK_PTR_FOR_FN (cfun)->count, - head_count); - set_bb_annotated (ENTRY_BLOCK_PTR_FOR_FN (cfun), &annotated_bb); - if (!is_bb_annotated (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb, annotated_bb) - || ENTRY_BLOCK_PTR_FOR_FN (cfun)->count - > ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->count) - { - ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->count - = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; - set_bb_annotated (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb, - &annotated_bb); - } - if (!is_bb_annotated (EXIT_BLOCK_PTR_FOR_FN (cfun), annotated_bb) - || ENTRY_BLOCK_PTR_FOR_FN (cfun)->count - > EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb->count) - { - EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb->count - = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; - set_bb_annotated (EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb, &annotated_bb); - } - } + { + update_count_by_afdo_count (&ENTRY_BLOCK_PTR_FOR_FN (cfun)->count, + head_count); + set_bb_annotated (ENTRY_BLOCK_PTR_FOR_FN (cfun), &annotated_bb); + if (!is_bb_annotated (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb, annotated_bb) + || ENTRY_BLOCK_PTR_FOR_FN (cfun)->count + > ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->count) + { + ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->count + = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; + set_bb_annotated (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb, + &annotated_bb); + } + if (!is_bb_annotated (EXIT_BLOCK_PTR_FOR_FN (cfun), annotated_bb) + || ENTRY_BLOCK_PTR_FOR_FN (cfun)->count + > EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb->count) + { + EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb->count + = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; + set_bb_annotated (EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb, &annotated_bb); + } + } /* Calculate, propagate count and probability information on CFG. */ afdo_calculate_branch_prob (&annotated_bb);
