[GlobalISel] Avoid repeated hash lookups (NFC) (#129653)
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index d01de29..b85239e 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -252,8 +252,8 @@
}
int IRTranslator::getOrCreateFrameIndex(const AllocaInst &AI) {
- auto MapEntry = FrameIndices.find(&AI);
- if (MapEntry != FrameIndices.end())
+ auto [MapEntry, Inserted] = FrameIndices.try_emplace(&AI);
+ if (!Inserted)
return MapEntry->second;
uint64_t ElementSize = DL->getTypeAllocSize(AI.getAllocatedType());
@@ -263,7 +263,7 @@
// Always allocate at least one byte.
Size = std::max<uint64_t>(Size, 1u);
- int &FI = FrameIndices[&AI];
+ int &FI = MapEntry->second;
FI = MF->getFrameInfo().CreateStackObject(Size, AI.getAlign(), false, &AI);
return FI;
}