[llvm] 9afb636 - [Attributes] Avoid duplicate hasAttribute() query (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 03:59:24 PST 2023


Author: Nikita Popov
Date: 2023-01-09T12:59:16+01:00
New Revision: 9afb6360fcbb5c94f37f6c1328bfa76ca8e20021

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

LOG: [Attributes] Avoid duplicate hasAttribute() query (NFC)

removeAttribute() already performs a hasAttribute() check, so no
need to also do it in the caller. Instead check whether the
attribute set was changed.

This makes the implementations in line with removeAttributesAtIndex().

Added: 
    

Modified: 
    llvm/lib/IR/Attributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 8bcb0808ef7c..8c989c464551 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1380,18 +1380,20 @@ AttributeList
 AttributeList::removeAttributeAtIndex(LLVMContext &C, unsigned Index,
                                       Attribute::AttrKind Kind) const {
   AttributeSet Attrs = getAttributes(Index);
-  if (!Attrs.hasAttribute(Kind))
+  AttributeSet NewAttrs = Attrs.removeAttribute(C, Kind);
+  if (Attrs == NewAttrs)
     return *this;
-  return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
+  return setAttributesAtIndex(C, Index, NewAttrs);
 }
 
 AttributeList AttributeList::removeAttributeAtIndex(LLVMContext &C,
                                                     unsigned Index,
                                                     StringRef Kind) const {
   AttributeSet Attrs = getAttributes(Index);
-  if (!Attrs.hasAttribute(Kind))
+  AttributeSet NewAttrs = Attrs.removeAttribute(C, Kind);
+  if (Attrs == NewAttrs)
     return *this;
-  return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
+  return setAttributesAtIndex(C, Index, NewAttrs);
 }
 
 AttributeList AttributeList::removeAttributesAtIndex(


        


More information about the llvm-commits mailing list