aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Attributes.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-05-22 15:03:29 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-05-22 19:03:27 +0200
commit05738ffcb87b76c6f166f965ba9b2db3257a4338 (patch)
tree5f219cb90468cb876ca7a0242c67e6e8c6522494 /llvm/lib/IR/Attributes.cpp
parentfd46ed3f397d6cf41bc6c5a04ab2089f585afe44 (diff)
downloadllvm-05738ffcb87b76c6f166f965ba9b2db3257a4338.zip
llvm-05738ffcb87b76c6f166f965ba9b2db3257a4338.tar.gz
llvm-05738ffcb87b76c6f166f965ba9b2db3257a4338.tar.bz2
[IR] Optimize no-op removal from AttributeList (NFC)
When removing an AttrBuilder from an index of an AttributeList, directly return the original list if no attributes were actually removed.
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r--llvm/lib/IR/Attributes.cpp17
1 files changed, 6 insertions, 11 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 450543d..f63a65a 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -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,