Skip to content

Commit e97a4cd

Browse files
[Scalar] Avoid repeated hash lookups (NFC) (#132330)
1 parent 67a631b commit e97a4cd

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,11 +1182,12 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
11821182
for (unsigned i = 0; i < NumPHIValues; i++) {
11831183
Value *InVal = PN->getIncomingValue(i);
11841184
BasicBlock *InBB = PN->getIncomingBlock(i);
1185-
if (!BlockToValue.count(InBB))
1186-
BlockToValue[InBB] = getBaseForInput(InVal, InBB->getTerminator());
1185+
auto [It, Inserted] = BlockToValue.try_emplace(InBB);
1186+
if (Inserted)
1187+
It->second = getBaseForInput(InVal, InBB->getTerminator());
11871188
else {
11881189
#ifndef NDEBUG
1189-
Value *OldBase = BlockToValue[InBB];
1190+
Value *OldBase = It->second;
11901191
Value *Base = getBaseForInput(InVal, nullptr);
11911192

11921193
// We can't use `stripPointerCasts` instead of this function because
@@ -1206,7 +1207,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
12061207
"findBaseOrBDV should be pure!");
12071208
#endif
12081209
}
1209-
Value *Base = BlockToValue[InBB];
1210+
Value *Base = It->second;
12101211
BasePHI->setIncomingValue(i, Base);
12111212
}
12121213
} else if (SelectInst *BaseSI =
@@ -1545,9 +1546,10 @@ static void CreateGCRelocates(ArrayRef<Value *> LiveVariables,
15451546
Value *LiveIdx = Builder.getInt32(i);
15461547

15471548
Type *Ty = LiveVariables[i]->getType();
1548-
if (!TypeToDeclMap.count(Ty))
1549-
TypeToDeclMap[Ty] = getGCRelocateDecl(Ty);
1550-
Function *GCRelocateDecl = TypeToDeclMap[Ty];
1549+
auto [It, Inserted] = TypeToDeclMap.try_emplace(Ty);
1550+
if (Inserted)
1551+
It->second = getGCRelocateDecl(Ty);
1552+
Function *GCRelocateDecl = It->second;
15511553

15521554
// only specify a debug name if we can give a useful one
15531555
CallInst *Reloc = Builder.CreateCall(
@@ -2378,9 +2380,9 @@ findRematerializationCandidates(PointerToBaseTy PointerToBase,
23782380

23792381
// Handle the scenario where the RootOfChain is not equal to the
23802382
// Base Value, but they are essentially the same phi values.
2381-
if (RootOfChain != PointerToBase[Derived]) {
2383+
if (Value *BaseVal = PointerToBase[Derived]; RootOfChain != BaseVal) {
23822384
PHINode *OrigRootPhi = dyn_cast<PHINode>(RootOfChain);
2383-
PHINode *AlternateRootPhi = dyn_cast<PHINode>(PointerToBase[Derived]);
2385+
PHINode *AlternateRootPhi = dyn_cast<PHINode>(BaseVal);
23842386
if (!OrigRootPhi || !AlternateRootPhi)
23852387
continue;
23862388
// PHI nodes that have the same incoming values, and belonging to the same

0 commit comments

Comments
 (0)