[llvm] efc2f69 - [Scalar] Avoid repeated hash lookups (NFC) (#129825)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 5 00:44:53 PST 2025
Author: Kazu Hirata
Date: 2025-03-05T00:44:50-08:00
New Revision: efc2f6912dbe610d376000f03474de974d710e12
URL: https://github.com/llvm/llvm-project/commit/efc2f6912dbe610d376000f03474de974d710e12
DIFF: https://github.com/llvm/llvm-project/commit/efc2f6912dbe610d376000f03474de974d710e12.diff
LOG: [Scalar] Avoid repeated hash lookups (NFC) (#129825)
Added:
Modified:
llvm/lib/Transforms/Scalar/LICM.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 0ccbe6ec144c9..4bad19e6fb7be 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -766,8 +766,8 @@ class ControlFlowHoister {
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 @@ class ControlFlowHoister {
// 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) {
More information about the llvm-commits
mailing list