[llvm] [ADT] Speed up FoldingSet with linear probing and Algorithm R deletion (PR #218190)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 23 13:05:13 PDT 2026


MaskRay wrote:

> > > @MaskRay @kazutakahirata Maybe summarize all 3 approaches on discourse? I find it difficult to keep track of 3 competing PRs...
> > 
> > 
> > I'll do that. Thanks!
> 
> @kuhar Posted https://discourse.llvm.org/t/rfc-modernizing-llvms-foldingset-open-addressing-with-swiss-table-and-algorithm-r/91637. Thanks!

Thanks:) I think we will need consolidate on one. I do recommend this one #218190...

- Occupancy via the null bucket pointer rather than a Used bitmap. A bucket pointer has a free sentinel, so the bitmap and its usedWords/setUsed/unsetUsed/forEachUsed helpers aren't needed. (Same reasoning I applied in the RFC thread; I use the bitmap in DenseMap only because integer keys have no spare sentinel.)
- RemoveNode returns in O(1) for a node that was never inserted. `SelectionDAG::RemoveNodeFromCSEMaps` takes that path for every deleted node that isn't CSE'd.
- `ComputeHash()` reserves the sentinel itself rather than a local sanitizeHash at one call site. IDHash is part of the `FoldingSetTrait::Equals` contract and SDVTListNode caches its own copy (SelectionDAG.h:120), so sanitising at one consumer makes the two disagree for one hash value.

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


More information about the llvm-commits mailing list