-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PGO] Ensure non-zero entry-count after populateCounters
#112029
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-llvm-transforms Author: Michael O'Farrell (mofarrell) ChangesWith sampled instrumentation (#69535), profile counts may appear corrupt and Full diff: https://github.com/llvm/llvm-project/pull/112029.diff 1 Files Affected:
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) {
|
@llvm/pr-subscribers-pgo Author: Michael O'Farrell (mofarrell) ChangesWith sampled instrumentation (#69535), profile counts may appear corrupt and Full diff: https://github.com/llvm/llvm-project/pull/112029.diff 1 Files Affected:
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) {
|
d469548
to
4d1221e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Changes makes sense to me
- Please provide a test if possible
4494a6d
to
4536acd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beyond the point fix here, I'm wondering if we want to consider profile inference to smooth the counts for sampled IRPGO just like HW sample PGO. @xur-llvm wdyt?
4536acd
to
abfdcb6
Compare
fixFuncEntryCount
populateCounters
Changed the fix to guarantee the function entry count is non zero after |
With sampled instrumentation (llvm#69535), profile counts can appear corrupt. In particular a function can have a 0 block counts for all its blocks, while having some non-zero counters for select instrumentation. This is only possible for colder functions, and a reasonable modification to ensure the entry is non-zero (required by `fixFuncEntryCounts`) is to set the counter to one. This is only likely to happen for colder functions, so it is reasonable to take any action that does not crash.
This crashed before making fixFuncEntryCount gracefully handle zero counts.
abfdcb6
to
86e0a1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks.
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.