Skip to content
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

[IR] Use SmallDenseSet (NFC) #79556

Conversation

kazutakahirata
Copy link
Contributor

The use of SmallDenseSet saves 0.39% of heap allocations during the
compilation of a large preprocessed file, namely X86ISelLowering.cpp,
for the X86 target. During the experiment, WL.size() was 2 or less
99.9% of the time. The inline size of 4 should accommodate up to 2
entries at the 3/4 occupancy rate.

The use of SmallDenseSet saves 0.39% of heap allocations during the
compilation of a large preprocessed file, namely X86ISelLowering.cpp,
for the X86 target.  During the experiment, WL.size() was 2 or less
99.9% of the time.  The inline size of 4 should accommodate up to 2
entries at the 3/4 occupancy rate.
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 26, 2024

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

The use of SmallDenseSet saves 0.39% of heap allocations during the
compilation of a large preprocessed file, namely X86ISelLowering.cpp,
for the X86 target. During the experiment, WL.size() was 2 or less
99.9% of the time. The inline size of 4 should accommodate up to 2
entries at the 3/4 occupancy rate.


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

1 Files Affected:

  • (modified) llvm/lib/IR/Instruction.cpp (+1-3)
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index f9a38e48166c9a..904ce17fb0e7c9 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -1167,9 +1167,7 @@ void Instruction::copyMetadata(const Instruction &SrcInst,
   if (!SrcInst.hasMetadata())
     return;
 
-  DenseSet<unsigned> WLS;
-  for (unsigned M : WL)
-    WLS.insert(M);
+  SmallDenseSet<unsigned, 4> WLS(WL.begin(), WL.end());
 
   // Otherwise, enumerate and copy over metadata from the old instruction to the
   // new one.

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 merged commit c9790f8 into llvm:main Jan 27, 2024
4 of 5 checks passed
@kazutakahirata kazutakahirata deleted the pr_cleanup_memory_alloc_39bp_Instruction branch January 27, 2024 01:18
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.

None yet

3 participants