[llvm] [IR] Reduce memory usage in metadata use tracking (NFC) (PR #221866)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 20:58:07 PDT 2026
MaskRay wrote:
dropRef() in the latest revision is still O(N).
I've put up #227186 as a draft for reference, not to compete with this PR ("Squash and merge" uses the submitter's account as the author where every other author is Co-authored-by). I'd suggest adopting its `dropRef` design here; please take whatever is useful (`replaceAllUsesWith`, reverse is in findRef).
It also makes the std::reverse in replaceAllUsesWith unnecessary, since a drop from the front costs the same as a drop from the back. The index is freed at 16 entries and rebuilt past 32, so it can't thrash.
On a function with 50,000 assignments to one local (assignment tracking drains the alloca's dbg_assign uses oldest first), same base:
```
main (DenseMap) 9.1 s
#227186 9.3 s
plain SmallVector 10.5 s
this PR (v3) 21.2 s
```
#227186 also adds a unit test for lists that cross the index threshold. Only asserts catch a stale index entry, and they only trip if the changed reference is looked up again right away, because a later swap in dropRef repairs the entry. I checked it against five index-bookkeeping bugs (a missing index erase or store in addRef, dropRef or moveRef), and it catches all five; the existing tests catch none. Feel free to take it as is.
https://github.com/llvm/llvm-project/pull/221866
More information about the llvm-commits
mailing list