Skip to content

Commit efc2f69

Browse files
[Scalar] Avoid repeated hash lookups (NFC) (#129825)
1 parent f4878cb commit efc2f69

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ class ControlFlowHoister {
766766
if (!ControlFlowHoisting)
767767
return CurLoop->getLoopPreheader();
768768
// If BB has already been hoisted, return that
769-
if (HoistDestinationMap.count(BB))
770-
return HoistDestinationMap[BB];
769+
if (auto It = HoistDestinationMap.find(BB); It != HoistDestinationMap.end())
770+
return It->second;
771771

772772
// Check if this block is conditional based on a pending branch
773773
auto HasBBAsSuccessor =
@@ -800,11 +800,12 @@ class ControlFlowHoister {
800800

801801
// Create hoisted versions of blocks that currently don't have them
802802
auto CreateHoistedBlock = [&](BasicBlock *Orig) {
803-
if (HoistDestinationMap.count(Orig))
804-
return HoistDestinationMap[Orig];
803+
auto [It, Inserted] = HoistDestinationMap.try_emplace(Orig);
804+
if (!Inserted)
805+
return It->second;
805806
BasicBlock *New =
806807
BasicBlock::Create(C, Orig->getName() + ".licm", Orig->getParent());
807-
HoistDestinationMap[Orig] = New;
808+
It->second = New;
808809
DT->addNewBlock(New, HoistTarget);
809810
if (CurLoop->getParentLoop())
810811
CurLoop->getParentLoop()->addBasicBlockToLoop(New, *LI);
@@ -1531,14 +1532,11 @@ static Instruction *sinkThroughTriviallyReplaceablePHI(
15311532
assert(isTriviallyReplaceablePHI(*TPN, *I) &&
15321533
"Expect only trivially replaceable PHI");
15331534
BasicBlock *ExitBlock = TPN->getParent();
1534-
Instruction *New;
1535-
auto It = SunkCopies.find(ExitBlock);
1536-
if (It != SunkCopies.end())
1537-
New = It->second;
1538-
else
1539-
New = SunkCopies[ExitBlock] = cloneInstructionInExitBlock(
1540-
*I, *ExitBlock, *TPN, LI, SafetyInfo, MSSAU);
1541-
return New;
1535+
auto [It, Inserted] = SunkCopies.try_emplace(ExitBlock);
1536+
if (Inserted)
1537+
It->second = cloneInstructionInExitBlock(*I, *ExitBlock, *TPN, LI,
1538+
SafetyInfo, MSSAU);
1539+
return It->second;
15421540
}
15431541

15441542
static bool canSplitPredecessors(PHINode *PN, LoopSafetyInfo *SafetyInfo) {

0 commit comments

Comments
 (0)