[llvm] [PGO] Gracefully handle zero entry-count in `fixFuncEntryCount` (PR #112029)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 10:57:42 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Michael O'Farrell (mofarrell)

<details>
<summary>Changes</summary>

With sampled instrumentation (#<!-- -->69535), profile counts may appear corrupt and `fixFuncEntryCount` may assert.  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.  Here we simply bail from fixing the entry count.

---
Full diff: https://github.com/llvm/llvm-project/pull/112029.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+2-4) 


``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index e6e474ed376069..23d34016173165 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) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/112029


More information about the llvm-commits mailing list