[llvm] [Analysis] Fix BFI verify accessing deleted blocks (PR #190780)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 7 05:02:01 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Alexis Engelke (aengelke)
<details>
<summary>Changes</summary>
The BFI verifier should ignore basic blocks that got deleted (=number is
still allocated but there is no corresponding block in the function)
since the analysis was first created.
Fixup of #<!-- -->190669.
---
Full diff: https://github.com/llvm/llvm-project/pull/190780.diff
2 Files Affected:
- (modified) llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h (+4-1)
- (added) llvm/test/Transforms/CodeGenPrepare/X86/verify-bfi-updates.ll (+20)
``````````diff
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 09379056f9600..cc2404a0249e7 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1670,7 +1670,8 @@ template <class BT>
void BlockFrequencyInfoImpl<BT>::verifyMatch(
BlockFrequencyInfoImpl<BT> &Other) const {
bool Match = true;
- // Gather blocks for numbers so that we can print names.
+ // Gather blocks for numbers so that we can print names and determine whether
+ // they still exist.
SmallVector<const BlockT *> Blocks;
Blocks.resize(GraphTraits<const FunctionT *>::getMaxNumber(F));
for (const auto &BB : *F)
@@ -1678,6 +1679,8 @@ void BlockFrequencyInfoImpl<BT>::verifyMatch(
size_t MinSize = std::min(Nodes.size(), Other.Nodes.size());
for (size_t i = 0; i < MinSize; ++i) {
+ if (!Blocks[i])
+ continue; // Block got deleted in the mean time, ignore.
if (Nodes[i].isValid() != Other.Nodes[i].isValid()) {
Match = false;
dbgs() << "Block " << bfi_detail::getBlockName(Blocks[i])
diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/verify-bfi-updates.ll b/llvm/test/Transforms/CodeGenPrepare/X86/verify-bfi-updates.ll
new file mode 100644
index 0000000000000..13193d12cade4
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/X86/verify-bfi-updates.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes='require<profile-summary>,function(codegenprepare)' -cgp-verify-bfi-updates -S < %s | FileCheck %s
+
+target triple = "x86_64--"
+
+define void @a() {
+; CHECK-LABEL: define void @a() {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: ret void
+;
+entry:
+ %cmp = icmp ne i16 ptrtoint (ptr @a to i16), 0
+ br i1 %cmp, label %land.rhs, label %land.end
+
+land.rhs:
+ br label %land.end
+
+land.end:
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/190780
More information about the llvm-commits
mailing list