https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77445
--- Comment #12 from Jan Hubicka <hubicka at gcc dot gnu.org> --- Created attachment 40526 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40526&action=edit Patch I am testing The profile is quite inconsistent since thread1. The problem is that duplicate_thread_path does if (total_count) { scale_bbs_frequencies_gcov_type (region, n_region, total_count - entry_count, total_count); scale_bbs_frequencies_gcov_type (region_copy, n_region, entry_count, total_count); } else { scale_bbs_frequencies_int (region, n_region, total_freq - entry_freq, total_freq); scale_bbs_frequencies_int (region_copy, n_region, entry_freq, total_freq); } This is wrong when the duplicated path have extra entries that are not duplicated which happens in the testcase. The attached patch fixes it. It is still not 100% correct as the outgoing probabilities of the original path should be updated based on the path being copied out, but I am not sure it is worth the trouble (and risk of roundoff errors). I will think a bit more about this tomorrow.