[llvm] [IR] Reduce memory usage in metadata use tracking (NFC) (PR #221866)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 20 23:07:54 PDT 2026


kazutakahirata wrote:

Good point that `IndexMap` with `UseMap.erase` still shifts elements on front/middle removals.

You've expressed two competing concerns -- complexity associated with tombstone tracking and hazard associated with the `SmallVector`-only approach. Fundamentally, we can only pick two of the following three properties:
- **No tombstones** (`UseMap` is always packed; readers never skip dead `Ref == nullptr` slots)
- **Insertion order preserved directly by the array** (no `uint64_t NextIndex` + `llvm::sort`)
- **$O(1)$ amortized `dropRef` from arbitrary positions** (including oldest-first / index 0)

Which of the corresponding options do you prefer we go with?

- **Option A (No tombstones + Array order): Plain `SmallVector<UseEntry, 4>`** (dropping `IndexMap`, matching https://github.com/llvm/llvm-project/commit/cc9389b7a537e16ad23ea7057b06d62b3e41b085 + its unit tests). Now that #223303 exempted `ConstantData` and `replaceAllUsesWith` reverses `UseMap` to pop from the back in $O(1)$, 98.15% of nodes on `SLPVectorizer.cpp` have $\le 16$ uses and plain `SmallVector` is both simplest and fastest in practice.
- **Option B (Array order + $O(1)$ `dropRef`): `SmallVector<UseEntry, 4>` + local `IndexMap` (`> 16` entries) with tombstones**. When `IndexMap` is active, `dropRef` marks `Entry->Ref = nullptr` in $O(1)$ instead of shifting, and compacts when `IndexMap->size() * 2 < UseMap.size()`.
- **Option C (No tombstones + $O(1)$ `dropRef`): Inline `SmallVector` for small lists, switching to `DenseMap` + `NextIndex` / `llvm::sort` when exceeding 16 entries.**

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


More information about the llvm-commits mailing list