[llvm] [BOLT] Discard BB profiles with a hash of 0 in yaml from a Post-BAT binary (PR #169627)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 26 02:08:13 PST 2025


https://github.com/Jinjie-Huang created https://github.com/llvm/llvm-project/pull/169627

When generating the YAML profile from a Post-BAT binary, the [writer](https://github.com/llvm/llvm-project/blame/main/bolt/lib/Profile/DataAggregator.cpp#L2340) seems to unconditionally trust and use the BBHashMap from the BAT table. However, it appears that in some scenarios, a recorded basic block (BB) hash within this map is 0. 

 When infer-stale-profile is enabled, profile.yaml generated this way may trigger an assertion failure [here](https://github.com/llvm/llvm-project/blob/main/bolt/lib/Profile/StaleProfileMatching.cpp#L629) and crash. So this patch tries to drop the BB profiles  with a hash of 0 in writeBATYAML().


>From 7d7c947aff7b210a93025ee317e88f68564ed7e9 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Wed, 26 Nov 2025 17:05:56 +0800
Subject: [PATCH] discard BB profiles with a hash of 0

---
 bolt/lib/Profile/DataAggregator.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index 6b969011df589..dcda502a6912d 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -2417,6 +2417,7 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
       // Skip printing if there's no profile data
       llvm::erase_if(
           YamlBF.Blocks, [](const yaml::bolt::BinaryBasicBlockProfile &YamlBB) {
+            if ((size_t)YamlBB.Hash == 0) return true;
             auto HasCount = [](const auto &SI) { return SI.Count; };
             bool HasAnyCount = YamlBB.ExecCount ||
                                llvm::any_of(YamlBB.Successors, HasCount) ||



More information about the llvm-commits mailing list