Skip to content

Commit 5ab017a

Browse files
authored
[PGO] Don't unconditionally request BBInfo in verifyFuncBFI() (#140804)
This breaks in the case where there are unreachable blocks after an entry block with no successors, which don't have a `BBInfo`, causing crashes. `BBInfo` doesn't exist for unreachable blocks, see https://reviews.llvm.org/D27280. Fixes #135828.
1 parent eb79e34 commit 5ab017a

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,10 +2086,12 @@ static void verifyFuncBFI(PGOUseFunc &Func, LoopInfo &LI,
20862086

20872087
unsigned BBNum = 0, BBMisMatchNum = 0, NonZeroBBNum = 0;
20882088
for (auto &BBI : F) {
2089-
uint64_t CountValue = 0;
2090-
uint64_t BFICountValue = 0;
2089+
PGOUseBBInfo *BBInfo = Func.findBBInfo(&BBI);
2090+
if (!BBInfo)
2091+
continue;
20912092

2092-
CountValue = Func.getBBInfo(&BBI).Count.value_or(CountValue);
2093+
uint64_t CountValue = BBInfo->Count.value_or(CountValue);
2094+
uint64_t BFICountValue = 0;
20932095

20942096
BBNum++;
20952097
if (CountValue)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: split-file %s %t
2+
; RUN: llvm-profdata merge %t/a.proftext -o %t/a.profdata
3+
; RUN: opt < %t/a.ll -passes=pgo-instr-use -pgo-test-profile-file=%t/a.profdata -S | FileCheck %s
4+
5+
;--- a.ll
6+
7+
declare ptr @bar()
8+
9+
; CHECK: define ptr @foo
10+
; Ensure the profile hash matches. If it doesn't we emit the "instr_prof_hash_mismatch" metadata.
11+
; CHECK-NOT: instr_prof_hash_mismatch
12+
define ptr @foo() {
13+
entry:
14+
ret ptr null
15+
16+
2:
17+
ret ptr null
18+
}
19+
20+
;--- a.proftext
21+
# IR level Instrumentation Flag
22+
:ir
23+
foo
24+
# Func Hash:
25+
742261418966908927
26+
# Num Counters:
27+
1
28+
# Counter Values:
29+
1

0 commit comments

Comments
 (0)