[llvm] [ADT] Remove zombie-instance handling from SmallDenseMapStorage (NFC) (PR #228925)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 13:54:50 PDT 2026


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/228925

>From 425df7319a250b3064f6c521c0453bd30aba927b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 4 Oct 2026 09:54:12 -0700
Subject: [PATCH 1/2] [ADT] Remove zombie-instance handling from
 SmallDenseMapStorage (NFC)

This patch removes the redundant storage.Large.NumBuckets == 0 check
and the two dead stores to the field from SmallDenseMapStorage.

SmallDenseMapStorage used to have a zombie state:

    !Small && storage.Large.NumBuckets == 0

in grow() so that ~DenseMapBase(), which calls deallocateBuckets(),
could safely destruct the moved-from temporary DenseMapBase instance.

With #228802, grow() directly uses StorageT for the temporary storage,
so SmallDenseMapStorage no longer enters the zombie state.

Assisted-by: Antigravity
---
 llvm/include/llvm/ADT/DenseMap.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 92eae370e0219..f25358dd79744 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -462,15 +462,12 @@ class SmallDenseMapStorage {
   }
 
   void deallocateBuckets() {
-    // Fast path in case storage.Large.NumBuckets == 0, just like destroyAll.
-    // This path is used to destruct zombie instances after moves.
-    if (Small || storage.Large.NumBuckets == 0)
+    if (Small)
       return;
 
     deallocate_buffer(storage.Large.Buckets,
                       allocBytes<BucketT>(storage.Large.NumBuckets),
                       allocAlign<BucketT>());
-    storage.Large.NumBuckets = 0;
   }
 
   bool allocateBuckets(unsigned Num) {
@@ -513,7 +510,6 @@ class SmallDenseMapStorage {
     Small = false;
     NumEntries = Other.NumEntries;
     storage.Large = Other.storage.Large;
-    Other.storage.Large.NumBuckets = 0;
     return true;
   }
 };

>From 47f2547937bcc733c14c79a6950489388fc1cfbe Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 4 Oct 2026 13:41:12 -0700
Subject: [PATCH 2/2] Address comments.

---
 llvm/include/llvm/ADT/DenseMap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index f25358dd79744..6d25ce578a620 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -286,7 +286,7 @@ template <typename BucketT> class DenseMapStorage {
   }
 
   bool maybeMoveFast(DenseMapStorage &&Other) {
-    swap(Other);
+    *this = Other;
     return true;
   }
 };



More information about the llvm-commits mailing list