[llvm] [MemDep] Optimize SortNonLocalDepInfoCache sorting strategy for large caches with few unsorted entries (PR #143107)
Qiu Chaofan via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 8 23:04:11 PDT 2025
================
@@ -991,33 +994,19 @@ MemDepResult MemoryDependenceResults::getNonLocalInfoForBlock(
static void
SortNonLocalDepInfoCache(MemoryDependenceResults::NonLocalDepInfo &Cache,
unsigned NumSortedEntries) {
- switch (Cache.size() - NumSortedEntries) {
- case 0:
- // done, no new entries.
- break;
- case 2: {
- // Two new entries, insert the last one into place.
- NonLocalDepEntry Val = Cache.back();
- Cache.pop_back();
- MemoryDependenceResults::NonLocalDepInfo::iterator Entry =
- std::upper_bound(Cache.begin(), Cache.end() - 1, Val);
- Cache.insert(Entry, Val);
- [[fallthrough]];
- }
- case 1:
- // One new entry, Just insert the new value at the appropriate position.
- if (Cache.size() != 1) {
+
+ auto s = Cache.size() - NumSortedEntries;
+ if (s < log2(Cache.size()) * ln2) {
----------------
ecnelises wrote:
Why not use `log(Cache.size())` directly? Or, at least, Compiler automatically folds `log(2)`, no need to define a constant.
https://github.com/llvm/llvm-project/pull/143107
More information about the llvm-commits
mailing list