[llvm] [PGO] Gracefully handle zero entry-count in `fixFuncEntryCount` (PR #112029)
Michael O'Farrell via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 15:06:20 PDT 2024
https://github.com/mofarrell updated https://github.com/llvm/llvm-project/pull/112029
>From 4d1221eb68b11c5fbad13fdaf396585ebb324101 Mon Sep 17 00:00:00 2001
From: Michael O'Farrell <micpof at gmail.com>
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 dbe908bb5e72f3..8e72cc367574ab 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1972,11 +1972,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) {
More information about the llvm-commits
mailing list