Skip to content

Commit d469548

Browse files
committed
[PGO] Gracefully handle zero entry-count
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.
1 parent 64bcb27 commit d469548

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,11 +1970,9 @@ static void fixFuncEntryCount(PGOUseFunc &Func, LoopInfo &LI,
19701970
BranchProbabilityInfo &NBPI) {
19711971
Function &F = Func.getFunc();
19721972
BlockFrequencyInfo NBFI(F, NBPI, LI);
1973-
#ifndef NDEBUG
19741973
auto BFIEntryCount = F.getEntryCount();
1975-
assert(BFIEntryCount && (BFIEntryCount->getCount() > 0) &&
1976-
"Invalid BFI Entrycount");
1977-
#endif
1974+
if (!BFIEntryCount || BFIEntryCount->getCount() == 0)
1975+
return;
19781976
auto SumCount = APFloat::getZero(APFloat::IEEEdouble());
19791977
auto SumBFICount = APFloat::getZero(APFloat::IEEEdouble());
19801978
for (auto &BBI : F) {

0 commit comments

Comments
 (0)