Hi, In symbol merging, ipa_merge_profiles() can encounter functions where the entry block has an initialized but zero profile count. When such counts are used as denominators in apply_scale(), it triggers an assertion failure in profile-count.h:1192 (gcc_checking_assert(den.m_val)).
This patch adds nonzero_p checks before attempting to scale profile
counts, preventing division by zero.
This issue shows up randomly with AutoFDO (including profile bootstrap).
Tested with bootstrap and regression testing. Also tested with some
large applications where this first showed up.
gcc/ChangeLog:
* ipa-utils.cc (ipa_merge_profiles): Add nonzero_p() checks
for srcden and dstden before using them as denominators in
apply_scale to prevent ICE.
This is hitting quite a few times including in:
during IPA pass: modref
lto1: internal compiler error: in apply_scale, at profile-count.h:1192
0x2230c13 internal_error(char const*, ...)
/var/jenkins/workspace/GCC_oss-main/gcc/diagnostic-global-context.cc:787
0x899ebf fancy_abort(char const*, int, char const*)
/var/jenkins/workspace/GCC_oss-main/gcc/diagnostics/context.cc:1812
0x98620f profile_count::apply_scale(profile_count, profile_count) const
/var/jenkins/workspace/GCC_oss-main/gcc/profile-count.h:1192
0xd190cb ipa_merge_profiles(cgraph_node*, cgraph_node*, bool)
/var/jenkins/workspace/GCC_oss-main/gcc/ipa-utils.cc:637
0x8f303b lto_symtab_merge_symbols_1
/var/jenkins/workspace/GCC_oss-main/gcc/lto/lto-symtab.cc:934
0x8f303b lto_symtab_merge_symbols()
/var/jenkins/workspace/GCC_oss-main/gcc/lto/lto-symtab.cc:996
0x9027d7 read_cgraph_and_symbols(unsigned int, char const**)
/var/jenkins/workspace/GCC_oss-main/gcc/lto/lto-common.cc:3003
0x8dce9f lto_main()
/var/jenkins/workspace/GCC_oss-main/gcc/lto/lto.cc:663
<http://lto.cc:663/>
Bootstrapped and regression tested on aavch64-linux-gnu with no new
regressions. Is this OK?
Thanks,
Kugan
0001-AutoFDO-Fix-ICE-in-ipa_merge_profiles-when-entry-blo.patch
Description: 0001-AutoFDO-Fix-ICE-in-ipa_merge_profiles-when-entry-blo.patch
