[llvm] 5ab017a - [PGO] Don't unconditionally request BBInfo in verifyFuncBFI() (#140804)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 27 09:47:11 PDT 2025
Author: Arthur Eubanks
Date: 2025-05-27T09:47:08-07:00
New Revision: 5ab017a30f31f704fe6981a927ac64be139faa33
URL: https://github.com/llvm/llvm-project/commit/5ab017a30f31f704fe6981a927ac64be139faa33
DIFF: https://github.com/llvm/llvm-project/commit/5ab017a30f31f704fe6981a927ac64be139faa33.diff
LOG: [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.
Added:
llvm/test/Transforms/PGOProfile/unreachable_bb2.ll
Modified:
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Removed:
################################################################################
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
More information about the llvm-commits
mailing list