[LTO] Sort DefinedGlobals in LTO cache key#210025
Conversation
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 760bb06.
|
@llvm/pr-subscribers-lto Author: Nikita Popov (nikic) ChangesSort 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 760bb06. Full diff: https://github.com/llvm/llvm-project/pull/210025.diff 1 Files Affected:
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)));
|
nocchijiang
left a comment
There was a problem hiding this comment.
Could we add a regression test for this? Otherwise LGTM. The failed Linux check looks unrelated.
|
I added a test that fails before the change and passes after. It's not quite representative of what happens in Rust (which does not use linkonce_odr), but demonstrates the general issue at least. |
| // 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 *>> |
There was a problem hiding this comment.
Add a comment above this about why it is needed.
|
/cherry-pick 90e31c4 |
|
/pull-request #210274 |
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 760bb06. (cherry picked from commit 90e31c4)
Update to LLVM 23 Changes in this PR (apart from the LLVM update): * Updated cov-map tests due to minor ordering changes introduced in llvm/llvm-project@5931034. The affected tests are limited to LLVM >= 23 now. * Set `LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN=OFF`, which restores the previous unversioned naming of the LLVM dylib on Darwin. I expect we'll want to change this for consistency with Linux, but given the amount of trouble Darwin dylibs have caused in the past, I'm not trying to do it in this PR. * Distribute the llvm-project/libc subproject, which is now a build dependency of LLVM. * Pull in f128 Windows ABI changes from #158778. These need to land in sync with the LLVM update (as ABI of libcalls is controlled by LLVM, not our ABI lowering). * Disable RISCV backend on dist-i686-mingw, because the build OOMs on a large generated file. This is a temporary measure until host tools are removed by rust-lang/compiler-team#1020. * The llvm-project fork includes a new downstream patch for mingw: rust-lang/llvm-project@b89cd8e It works around mingw having broken TLS prior to GCC 16. (We're currently on GCC 14.) Issues: * [x] llvm/llvm-project#209512 * [x] llvm/llvm-project#209714 * [x] llvm/llvm-project#209718 * [x] rust-lang/stdarch#2190 (synced in #159517) * [x] llvm/llvm-project#210025 * [x] #159391 * [x] EnzymeAD/Enzyme#2951 * [x] #159301 * [x] llvm/llvm-project#210300
Update to LLVM 23 Changes in this PR (apart from the LLVM update): * Updated cov-map tests due to minor ordering changes introduced in llvm/llvm-project@5931034. The affected tests are limited to LLVM >= 23 now. * Set `LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN=OFF`, which restores the previous unversioned naming of the LLVM dylib on Darwin. I expect we'll want to change this for consistency with Linux, but given the amount of trouble Darwin dylibs have caused in the past, I'm not trying to do it in this PR. * Distribute the llvm-project/libc subproject, which is now a build dependency of LLVM. * Pull in f128 Windows ABI changes from #158778. These need to land in sync with the LLVM update (as ABI of libcalls is controlled by LLVM, not our ABI lowering). * Disable RISCV backend on dist-i686-mingw, because the build OOMs on a large generated file. This is a temporary measure until host tools are removed by rust-lang/compiler-team#1020. * The llvm-project fork includes a new downstream patch for mingw: rust-lang/llvm-project@b89cd8e It works around mingw having broken TLS prior to GCC 16. (We're currently on GCC 14.) Issues: * [x] llvm/llvm-project#209512 * [x] llvm/llvm-project#209714 * [x] llvm/llvm-project#209718 * [x] rust-lang/stdarch#2190 (synced in #159517) * [x] llvm/llvm-project#210025 * [x] #159391 * [x] EnzymeAD/Enzyme#2951 * [x] #159301 * [x] llvm/llvm-project#210300
Update to LLVM 23 Changes in this PR (apart from the LLVM update): * Updated cov-map tests due to minor ordering changes introduced in llvm/llvm-project@5931034. The affected tests are limited to LLVM >= 23 now. * Set `LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN=OFF`, which restores the previous unversioned naming of the LLVM dylib on Darwin. I expect we'll want to change this for consistency with Linux, but given the amount of trouble Darwin dylibs have caused in the past, I'm not trying to do it in this PR. * Distribute the llvm-project/libc subproject, which is now a build dependency of LLVM. * Pull in f128 Windows ABI changes from #158778. These need to land in sync with the LLVM update (as ABI of libcalls is controlled by LLVM, not our ABI lowering). * Disable RISCV backend on dist-i686-mingw, because the build OOMs on a large generated file. This is a temporary measure until host tools are removed by rust-lang/compiler-team#1020. * The llvm-project fork includes a new downstream patch for mingw: rust-lang/llvm-project@b89cd8e It works around mingw having broken TLS prior to GCC 16. (We're currently on GCC 14.) Issues: * [x] llvm/llvm-project#209512 * [x] llvm/llvm-project#209714 * [x] llvm/llvm-project#209718 * [x] rust-lang/stdarch#2190 (synced in #159517) * [x] llvm/llvm-project#210025 * [x] #159391 * [x] EnzymeAD/Enzyme#2951 * [x] #159301 * [x] llvm/llvm-project#210300
Update to LLVM 23 Changes in this PR (apart from the LLVM update): * Updated cov-map tests due to minor ordering changes introduced in llvm/llvm-project@5931034. The affected tests are limited to LLVM >= 23 now. * Set `LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN=OFF`, which restores the previous unversioned naming of the LLVM dylib on Darwin. I expect we'll want to change this for consistency with Linux, but given the amount of trouble Darwin dylibs have caused in the past, I'm not trying to do it in this PR. * Distribute the llvm-project/libc subproject, which is now a build dependency of LLVM. * Pull in f128 Windows ABI changes from #158778. These need to land in sync with the LLVM update (as ABI of libcalls is controlled by LLVM, not our ABI lowering). * Disable RISCV backend on dist-i686-mingw, because the build OOMs on a large generated file. This is a temporary measure until host tools are removed by rust-lang/compiler-team#1020. * The llvm-project fork includes a new downstream patch for mingw: rust-lang/llvm-project@b89cd8e It works around mingw having broken TLS prior to GCC 16. (We're currently on GCC 14.) Issues: * [x] llvm/llvm-project#209512 * [x] llvm/llvm-project#209714 * [x] llvm/llvm-project#209718 * [x] rust-lang/stdarch#2190 (synced in #159517) * [x] llvm/llvm-project#210025 * [x] #159391 * [x] EnzymeAD/Enzyme#2951 * [x] #159301 * [x] llvm/llvm-project#210300
Update to LLVM 23 Changes in this PR (apart from the LLVM update): * Updated cov-map tests due to minor ordering changes introduced in llvm/llvm-project@5931034. The affected tests are limited to LLVM >= 23 now. * Set `LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN=OFF`, which restores the previous unversioned naming of the LLVM dylib on Darwin. I expect we'll want to change this for consistency with Linux, but given the amount of trouble Darwin dylibs have caused in the past, I'm not trying to do it in this PR. * Distribute the llvm-project/libc subproject, which is now a build dependency of LLVM. * Pull in f128 Windows ABI changes from #158778. These need to land in sync with the LLVM update (as ABI of libcalls is controlled by LLVM, not our ABI lowering). * Disable RISCV backend on dist-i686-mingw, because the build OOMs on a large generated file. This is a temporary measure until host tools are removed by rust-lang/compiler-team#1020. * The llvm-project fork includes a new downstream patch for mingw: rust-lang/llvm-project@b89cd8e It works around mingw having broken TLS prior to GCC 16. (We're currently on GCC 14.) Issues: * [x] llvm/llvm-project#209512 * [x] llvm/llvm-project#209714 * [x] llvm/llvm-project#209718 * [x] rust-lang/stdarch#2190 (synced in #159517) * [x] llvm/llvm-project#210025 * [x] #159391 * [x] EnzymeAD/Enzyme#2951 * [x] #159301 * [x] llvm/llvm-project#210300
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 760bb06.