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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Jinjie Huang  (Jinjie-Huang)

<details>
<summary>Changes</summary>

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().


---
Full diff: https://github.com/llvm/llvm-project/pull/169627.diff


1 Files Affected:

- (modified) bolt/lib/Profile/DataAggregator.cpp (+1) 


``````````diff
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) ||

``````````

</details>


https://github.com/llvm/llvm-project/pull/169627


More information about the llvm-commits mailing list