[Attributes] Avoid duplicate hasAttribute() query (NFC)
authorNikita Popov <npopov@redhat.com>
Mon, 9 Jan 2023 11:55:47 +0000 (12:55 +0100)
committerNikita Popov <npopov@redhat.com>
Mon, 9 Jan 2023 11:59:16 +0000 (12:59 +0100)
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().

llvm/lib/IR/Attributes.cpp

index 8bcb080..8c989c4 100644 (file)
@@ -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(