[llvm] 9c52422 - [IR] Avoid linear scan in MDNode::intersect() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 10:39:16 PDT 2020


Author: Nikita Popov
Date: 2020-05-28T19:38:46+02:00
New Revision: 9c52422cd83137a55e9d198bf123982c040b2e99

URL: https://github.com/llvm/llvm-project/commit/9c52422cd83137a55e9d198bf123982c040b2e99
DIFF: https://github.com/llvm/llvm-project/commit/9c52422cd83137a55e9d198bf123982c040b2e99.diff

LOG: [IR] Avoid linear scan in MDNode::intersect() (NFC)

00940fb8544767ba5217922c4ba96677aabe9eb3 changed this code to
construct a set for the B metadata. However, it still performs a
linear is_contained query, rather than making use of the set
structure.

Added: 
    

Modified: 
    llvm/lib/IR/Metadata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index cdd544040f52..ce89009e86eb 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -914,7 +914,7 @@ MDNode *MDNode::intersect(MDNode *A, MDNode *B) {
 
   SmallSetVector<Metadata *, 4> MDs(A->op_begin(), A->op_end());
   SmallPtrSet<Metadata *, 4> BSet(B->op_begin(), B->op_end());
-  MDs.remove_if([&](Metadata *MD) { return !is_contained(BSet, MD); });
+  MDs.remove_if([&](Metadata *MD) { return !BSet.count(MD); });
 
   // FIXME: This preserves long-standing behaviour, but is it really the right
   // behaviour?  Or was that an unintended side-effect of node uniquing?


        


More information about the llvm-commits mailing list