[llvm] [LTO] Sort DefinedGlobals in LTO cache key (PR #210025)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 03:35:31 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
Sort the DefindeGlobals by GUID when computing the LTO cache key, to avoid making the cache key dependent on the insertion order. This fixes large compile-time regressions in rust incremental builds.
Alternatively one could make collectDefinedGVSummariesPerModule() work on the sortedRange(), but as that is also used in other places, it probably makes sense to sort locally.
The issue was introduced in 760bb06cb3cd98832f1e4e7a4eaebd98b66d2bdd.
---
Full diff: https://github.com/llvm/llvm-project/pull/210025.diff
1 Files Affected:
- (modified) llvm/lib/LTO/LTO.cpp (+4-1)
``````````diff
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index b0fd1d77a2d66..4863ab2973948 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -306,7 +306,10 @@ std::string llvm::computeLTOCacheKey(
// Include the hash for the linkage type to reflect internalization and weak
// resolution, and collect any used type identifier resolutions.
- for (auto &GS : DefinedGlobals) {
+ SmallVector<std::pair<GlobalValue::GUID, GlobalValueSummary *>>
+ SortedDefinedGlobals(DefinedGlobals.begin(), DefinedGlobals.end());
+ llvm::sort(SortedDefinedGlobals, llvm::less_first());
+ for (auto &GS : SortedDefinedGlobals) {
GlobalValue::LinkageTypes Linkage = GS.second->linkage();
Hasher.update(
ArrayRef<uint8_t>((const uint8_t *)&Linkage, sizeof(Linkage)));
``````````
</details>
https://github.com/llvm/llvm-project/pull/210025
More information about the llvm-commits
mailing list