[llvm] 05738ff - [IR] Optimize no-op removal from AttributeList (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat May 22 10:05:46 PDT 2021
Author: Nikita Popov
Date: 2021-05-22T19:03:27+02:00
New Revision: 05738ffcb87b76c6f166f965ba9b2db3257a4338
URL: https://github.com/llvm/llvm-project/commit/05738ffcb87b76c6f166f965ba9b2db3257a4338
DIFF: https://github.com/llvm/llvm-project/commit/05738ffcb87b76c6f166f965ba9b2db3257a4338.diff
LOG: [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.
Added:
Modified:
llvm/lib/IR/Attributes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 450543d54e0b..f63a65abc30b 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,
More information about the llvm-commits
mailing list