diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 7c73c16db02c8..a063fb2ec3fe1 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -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; - CountValue = Func.getBBInfo(&BBI).Count.value_or(CountValue); + uint64_t CountValue = BBInfo->Count.value_or(CountValue); + uint64_t BFICountValue = 0; BBNum++; if (CountValue) diff --git a/llvm/test/Transforms/PGOProfile/unreachable_bb2.ll b/llvm/test/Transforms/PGOProfile/unreachable_bb2.ll new file mode 100644 index 0000000000000..a94f93dbe2ee1 --- /dev/null +++ b/llvm/test/Transforms/PGOProfile/unreachable_bb2.ll @@ -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