Skip to content

Commit 4d1221e

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 58bf78c commit 4d1221e

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
@@ -1972,11 +1972,9 @@ static void fixFuncEntryCount(PGOUseFunc &Func, LoopInfo &LI,
19721972
BranchProbabilityInfo &NBPI) {
19731973
Function &F = Func.getFunc();
19741974
BlockFrequencyInfo NBFI(F, NBPI, LI);
1975-
#ifndef NDEBUG
19761975
auto BFIEntryCount = F.getEntryCount();
1977-
assert(BFIEntryCount && (BFIEntryCount->getCount() > 0) &&
1978-
"Invalid BFI Entrycount");
1979-
#endif
1976+
if (!BFIEntryCount || BFIEntryCount->getCount() == 0)
1977+
return;
19801978
auto SumCount = APFloat::getZero(APFloat::IEEEdouble());
19811979
auto SumBFICount = APFloat::getZero(APFloat::IEEEdouble());
19821980
for (auto &BBI : F) {

0 commit comments

Comments
 (0)