Skip to content

Commit

Permalink
[PGO] Gracefully handle zero entry-count
Browse files Browse the repository at this point in the history
With sampled instrumentation (#69535), profile counts can appear
corrupt.  In particular a function can have a 0 block count for its
entry, while later blocks are non zero.  This is only likely to happen
for colder functions, so it is reasonable to take any action that does
not crash.
  • Loading branch information
mofarrell committed Oct 11, 2024
1 parent 64bcb27 commit d469548
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,11 +1970,9 @@ static void fixFuncEntryCount(PGOUseFunc &Func, LoopInfo &LI,
BranchProbabilityInfo &NBPI) {
Function &F = Func.getFunc();
BlockFrequencyInfo NBFI(F, NBPI, LI);
#ifndef NDEBUG
auto BFIEntryCount = F.getEntryCount();
assert(BFIEntryCount && (BFIEntryCount->getCount() > 0) &&
"Invalid BFI Entrycount");
#endif
if (!BFIEntryCount || BFIEntryCount->getCount() == 0)
return;
auto SumCount = APFloat::getZero(APFloat::IEEEdouble());
auto SumBFICount = APFloat::getZero(APFloat::IEEEdouble());
for (auto &BBI : F) {
Expand Down

0 comments on commit d469548

Please sign in to comment.