Skip to content

[JumpThreading] Use SmallPtrSet (NFC) #95674

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 Jun 15, 2024

The use of SmallPtrSet here saves 0.66% of heap allocations during
the compilation of a large preprocessed file, namely
X86ISelLowering.cpp, for the X86 target.

The use of SmallDenseSet here saves 0.58% of heap allocations during
the compilation of a large preprocessed file, namely
X86ISelLowering.cpp, for the X86 target.
@llvmbot
Copy link
Member

llvmbot commented Jun 15, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

The use of SmallDenseSet here saves 0.58% of heap allocations during
the compilation of a large preprocessed file, namely
X86ISelLowering.cpp, for the X86 target.


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

2 Files Affected:

  • (modified) llvm/include/llvm/Transforms/Scalar/JumpThreading.h (+2-2)
  • (modified) llvm/lib/Transforms/Scalar/JumpThreading.cpp (+1-1)
diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
index 65d43775bdc1d..1bf79fdcb697e 100644
--- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
+++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
@@ -130,13 +130,13 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
   bool computeValueKnownInPredecessorsImpl(
       Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result,
       jumpthreading::ConstantPreference Preference,
-      DenseSet<Value *> &RecursionSet, Instruction *CxtI = nullptr);
+      SmallDenseSet<Value *> &RecursionSet, Instruction *CxtI = nullptr);
   bool
   computeValueKnownInPredecessors(Value *V, BasicBlock *BB,
                                   jumpthreading::PredValueInfo &Result,
                                   jumpthreading::ConstantPreference Preference,
                                   Instruction *CxtI = nullptr) {
-    DenseSet<Value *> RecursionSet;
+    SmallDenseSet<Value *> RecursionSet;
     return computeValueKnownInPredecessorsImpl(V, BB, Result, Preference,
                                                RecursionSet, CxtI);
   }
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index b9583836aea06..a4a04d5d16d4a 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -558,7 +558,7 @@ static Constant *getKnownConstant(Value *Val, ConstantPreference Preference) {
 /// This returns true if there were any known values.
 bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
     Value *V, BasicBlock *BB, PredValueInfo &Result,
-    ConstantPreference Preference, DenseSet<Value *> &RecursionSet,
+    ConstantPreference Preference, SmallDenseSet<Value *> &RecursionSet,
     Instruction *CxtI) {
   const DataLayout &DL = BB->getModule()->getDataLayout();
 

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

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.

Actually, it would be even better to switch this to SmallPtrSet.

@kazutakahirata kazutakahirata changed the title [JumpThreading] Use SmallDenseSet (NFC) [JumpThreading] Use SmallPtrSet (NFC) Jun 15, 2024
@kazutakahirata
Copy link
Contributor Author

Actually, it would be even better to switch this to SmallPtrSet.

Thanks! SmallPtrSet saves a little more allocations.

@kazutakahirata kazutakahirata merged commit f05b15b into llvm:main Jun 15, 2024
4 of 7 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_memory_alloc_59bp_JumpThreading branch June 15, 2024 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants