diff options
author | Kazu Hirata <kazu@google.com> | 2025-03-05 00:44:50 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-05 00:44:50 -0800 |
commit | efc2f6912dbe610d376000f03474de974d710e12 (patch) | |
tree | 5292c9496735961fc13c5730d8e5ed350af66194 | |
parent | f4878cb916127498e04819e810b4aefca65e7348 (diff) | |
download | llvm-efc2f6912dbe610d376000f03474de974d710e12.zip llvm-efc2f6912dbe610d376000f03474de974d710e12.tar.gz llvm-efc2f6912dbe610d376000f03474de974d710e12.tar.bz2 |
[Scalar] Avoid repeated hash lookups (NFC) (#129825)
-rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 0ccbe6e..4bad19e 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -766,8 +766,8 @@ public: if (!ControlFlowHoisting) return CurLoop->getLoopPreheader(); // If BB has already been hoisted, return that - if (HoistDestinationMap.count(BB)) - return HoistDestinationMap[BB]; + if (auto It = HoistDestinationMap.find(BB); It != HoistDestinationMap.end()) + return It->second; // Check if this block is conditional based on a pending branch auto HasBBAsSuccessor = @@ -800,11 +800,12 @@ public: // Create hoisted versions of blocks that currently don't have them auto CreateHoistedBlock = [&](BasicBlock *Orig) { - if (HoistDestinationMap.count(Orig)) - return HoistDestinationMap[Orig]; + auto [It, Inserted] = HoistDestinationMap.try_emplace(Orig); + if (!Inserted) + return It->second; BasicBlock *New = BasicBlock::Create(C, Orig->getName() + ".licm", Orig->getParent()); - HoistDestinationMap[Orig] = New; + It->second = New; DT->addNewBlock(New, HoistTarget); if (CurLoop->getParentLoop()) CurLoop->getParentLoop()->addBasicBlockToLoop(New, *LI); @@ -1531,14 +1532,11 @@ static Instruction *sinkThroughTriviallyReplaceablePHI( assert(isTriviallyReplaceablePHI(*TPN, *I) && "Expect only trivially replaceable PHI"); BasicBlock *ExitBlock = TPN->getParent(); - Instruction *New; - auto It = SunkCopies.find(ExitBlock); - if (It != SunkCopies.end()) - New = It->second; - else - New = SunkCopies[ExitBlock] = cloneInstructionInExitBlock( - *I, *ExitBlock, *TPN, LI, SafetyInfo, MSSAU); - return New; + auto [It, Inserted] = SunkCopies.try_emplace(ExitBlock); + if (Inserted) + It->second = cloneInstructionInExitBlock(*I, *ExitBlock, *TPN, LI, + SafetyInfo, MSSAU); + return It->second; } static bool canSplitPredecessors(PHINode *PN, LoopSafetyInfo *SafetyInfo) { |