[llvm] fd46ed3 - [IR] Optimize no-op removal from AttributeSet (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat May 22 09:55:37 PDT 2021


Author: Nikita Popov
Date: 2021-05-22T18:55:25+02:00
New Revision: fd46ed3f397d6cf41bc6c5a04ab2089f585afe44

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

LOG: [IR] Optimize no-op removal from AttributeSet (NFC)

When removing an AttrBuilder from an AttributeSet, first check
whether there is any overlap. If nothing is being removed, we can
directly return the original set.

Added: 
    

Modified: 
    llvm/lib/IR/Attributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index adf8e6df6ce1..450543d54e0b 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -781,8 +781,12 @@ AttributeSet AttributeSet::removeAttribute(LLVMContext &C,
 }
 
 AttributeSet AttributeSet::removeAttributes(LLVMContext &C,
-                                              const AttrBuilder &Attrs) const {
+                                            const AttrBuilder &Attrs) const {
   AttrBuilder B(*this);
+  // If there is nothing to remove, directly return the original set.
+  if (!B.overlaps(Attrs))
+    return *this;
+
   B.remove(Attrs);
   return get(C, B);
 }


        


More information about the llvm-commits mailing list