From d4695485d892c190ac77468238de5e900e47bcaf Mon Sep 17 00:00:00 2001 From: Michael O'Farrell Date: Tue, 8 Oct 2024 10:41:11 -0700 Subject: [PATCH] [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. --- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index e6e474ed37606..23d3401617316 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -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) {