[llvm] 6900ebe - Attributor: Avoid double map lookup in updateAttrMap (#182666)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 1 06:29:51 PDT 2026


Author: Matt Arsenault
Date: 2026-05-01T14:29:46+01:00
New Revision: 6900ebe0ff52507e63bfa9a225c6b4da015fac0b

URL: https://github.com/llvm/llvm-project/commit/6900ebe0ff52507e63bfa9a225c6b4da015fac0b
DIFF: https://github.com/llvm/llvm-project/commit/6900ebe0ff52507e63bfa9a225c6b4da015fac0b.diff

LOG: Attributor: Avoid double map lookup in updateAttrMap (#182666)

This will leave behind the map entry in the unchanged case,
but this seems to not matter. Could erase the newly inserted
entry if that happens, but that also doesn't seem to make a
difference.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/Attributor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 25ba118f6c3df..994c094c520ba 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1207,13 +1207,11 @@ Attributor::updateAttrMap(const IRPosition &IRP, ArrayRef<DescTy> AttrDescs,
     break;
   };
 
-  AttributeList AL;
+  AttributeList AL = IRP.getAttrList();
   Value *AttrListAnchor = IRP.getAttrListAnchor();
-  auto It = AttrsMap.find(AttrListAnchor);
-  if (It == AttrsMap.end())
-    AL = IRP.getAttrList();
-  else
-    AL = It->getSecond();
+  auto [Iter, Inserted] = AttrsMap.insert({AttrListAnchor, AL});
+  if (!Inserted)
+    AL = Iter->second;
 
   LLVMContext &Ctx = IRP.getAnchorValue().getContext();
   auto AttrIdx = IRP.getAttrIdx();
@@ -1231,8 +1229,9 @@ Attributor::updateAttrMap(const IRPosition &IRP, ArrayRef<DescTy> AttrDescs,
 
   AL = AL.removeAttributesAtIndex(Ctx, AttrIdx, AM);
   AL = AL.addAttributesAtIndex(Ctx, AttrIdx, AB);
-  AttrsMap[AttrListAnchor] = AL;
-  return ChangeStatus::CHANGED;
+
+  Iter->second = AL;
+  return HasChanged;
 }
 
 bool Attributor::hasAttr(const IRPosition &IRP,


        


More information about the llvm-commits mailing list