AutoFDO: Prevent entry block count from becoming zero after profile adjustment
Fixes AutoFDO profile adjustment to prevent the entry block count from being zeroed, avoiding LTO ICEs.
When adjusting profiles for AutoFDO, the entry block’s count could incorrectly be scaled to zero while other basic blocks retained non-zero counts. This discrepancy, particularly during LTO’s IPA passes, led to an internal compiler error (in apply_scale). This commit modifies afdo_adjust_guessed_profile to set the entry block count to half of the scaled sample count instead of zero, resolving the issue.
In Details
The afdo_adjust_guessed_profile function in GCC's AutoFDO tooling is responsible for reconciling profile data from different sources. When scale_bbs is invoked, it can scale the entry basic block's count to zero, which conflicts with AFDO counts in inner basic blocks. This led to an ICE in profile-count.h:1192 during ipa_merge_profiles at LTO time. The fix ensures the entry block count is set to a fraction of the scaled sample, maintaining a non-zero value that aligns better with subsequent profile merging and verification steps.
- AutoFDO
- Automatic Feedback-Directed Optimization, a technique that uses runtime profile data to guide compiler optimizations.
- LTO
- Link-Time Optimization, a compilation strategy where optimization is performed at link time, allowing analysis across multiple translation units.
- IPA
- Inter-procedural Analysis, a compiler optimization technique that analyzes code across function boundaries.
- basic block
- A contiguous sequence of code within a function in which control enters only at the beginning and leaves only at the end.
- entry block
- The first basic block in a function, representing the point where execution begins.
- profile annotation
- The process of adding or adjusting profile count information to basic blocks and code paths.