Skip to content

Commit

Permalink
[IR] Optimize no-op removal from AttributeList (NFC)
Browse files Browse the repository at this point in the history
When removing an AttrBuilder from an index of an AttributeList,
directly return the original list if no attributes were actually
removed.
  • Loading branch information
nikic committed May 22, 2021
1 parent fd46ed3 commit 05738ff
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions llvm/lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,17 +1484,12 @@ AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index,
AttributeList
AttributeList::removeAttributes(LLVMContext &C, unsigned Index,
const AttrBuilder &AttrsToRemove) const {
if (!pImpl)
return {};

Index = attrIdxToArrayIdx(Index);
SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
if (Index >= AttrSets.size())
AttrSets.resize(Index + 1);

AttrSets[Index] = AttrSets[Index].removeAttributes(C, AttrsToRemove);

return getImpl(C, AttrSets);
AttributeSet Attrs = getAttributes(Index);
AttributeSet NewAttrs = Attrs.removeAttributes(C, AttrsToRemove);
// If nothing was removed, return the original list.
if (Attrs == NewAttrs)
return *this;
return setAttributes(C, Index, NewAttrs);
}

AttributeList AttributeList::removeAttributes(LLVMContext &C,
Expand Down

0 comments on commit 05738ff

Please sign in to comment.