Skip to content

[IR] Use SmallSet with more inline elements in dropUnknownNonDebugMetadata (NFC) #98853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

@kazutakahirata kazutakahirata commented Jul 15, 2024

SmallSet here often ends up allocating memory via std::set inside
SmallSet because KnownIDs.size() goes up to 17 on an x86 host. This
patch switches to SmallSet<unsigned, 32> to avoid memory
allocations.

The increased inline elements here save 0.57% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.

SmallSet here often ends up allocating memory via std::set inside
SmallSet because KnownIDs.size() goes up to 17 on an x86 host.  This
patch switches to SmallDenseSet<unsigned, 32> to avoid memory
allocations.

The use of SmallDenseSet here saves 0.57% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.
@kazutakahirata kazutakahirata requested a review from nikic July 15, 2024 02:18
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2024

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

SmallSet here often ends up allocating memory via std::set inside
SmallSet because KnownIDs.size() goes up to 17 on an x86 host. This
patch switches to SmallDenseSet<unsigned, 32> to avoid memory
allocations.

The use of SmallDenseSet here saves 0.57% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.


Full diff: https://github.com/llvm/llvm-project/pull/98853.diff

1 Files Affected:

  • (modified) llvm/lib/IR/Metadata.cpp (+1-2)
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 5f42ce22f72fe..a1bae38b07ab6 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -20,7 +20,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -1590,7 +1589,7 @@ void Instruction::dropUnknownNonDebugMetadata(ArrayRef<unsigned> KnownIDs) {
   if (!Value::hasMetadata())
     return; // Nothing to remove!
 
-  SmallSet<unsigned, 4> KnownSet;
+  SmallDenseSet<unsigned, 32> KnownSet;
   KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
 
   // A DIAssignID attachment is debug metadata, don't drop it.

@kazutakahirata
Copy link
Contributor Author

Please take a look. Thanks!

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata changed the title [IR] Use SmallDenseSet in dropUnknownNonDebugMetadata (NFC) [IR] Use SmallSet with more inline elements in dropUnknownNonDebugMetadata (NFC) Jul 15, 2024
@kazutakahirata kazutakahirata merged commit a78b19d into llvm:main Jul 15, 2024
7 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_memory_alloc_57bp_dropUnknownNonDebugMetadata_SmallDenseSet branch July 15, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants