Skip to content

[PGO] Don't unconditionally request BBInfo in verifyFuncBFI() #140804

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

Merged
merged 4 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,10 +2086,12 @@ static void verifyFuncBFI(PGOUseFunc &Func, LoopInfo &LI,

unsigned BBNum = 0, BBMisMatchNum = 0, NonZeroBBNum = 0;
for (auto &BBI : F) {
uint64_t CountValue = 0;
uint64_t BFICountValue = 0;
PGOUseBBInfo *BBInfo = Func.findBBInfo(&BBI);
if (!BBInfo)
continue;
Comment on lines +2090 to +2091
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we emit a warning in this case? Why is it ok to silently ignore here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an FDO-optimized build, hash mismatch errors are detected and logged (

std::string Msg =
IPE.message() + std::string(" ") + F.getName().str() +
std::string(" Hash = ") + std::to_string(FuncInfo.FunctionHash) +
std::string(" up to ") + std::to_string(MismatchedFuncSum) +
std::string(" count discarded");
Ctx.diagnose(
DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning));
).

Is it feasible to use similar mechanism to log the error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only unreachable basic blocks don't have a BBInfo, those shouldn't matter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, is it possible to assert that BB is unreachable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing DominatorTree wasn't (yet) computed in -O0 and he'd rather not compute it?


CountValue = Func.getBBInfo(&BBI).Count.value_or(CountValue);
uint64_t CountValue = Func.getBBInfo(&BBI).Count.value_or(CountValue);
uint64_t BFICountValue = 0;

BBNum++;
if (CountValue)
Expand Down
29 changes: 29 additions & 0 deletions llvm/test/Transforms/PGOProfile/unreachable_bb2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: split-file %s %t
; RUN: llvm-profdata merge %t/a.proftext -o %t/a.profdata
; RUN: opt < %t/a.ll -passes=pgo-instr-use -pgo-test-profile-file=%t/a.profdata -S | FileCheck %s

;--- a.ll

declare ptr @bar()

; CHECK: define ptr @foo
; Ensure the profile hash matches. If it doesn't we emit the "instr_prof_hash_mismatch" metadata.
; CHECK-NOT: instr_prof_hash_mismatch
define ptr @foo() {
entry:
ret ptr null

2:
ret ptr null
}

;--- a.proftext
# IR level Instrumentation Flag
:ir
foo
# Func Hash:
742261418966908927
# Num Counters:
1
# Counter Values:
1