[llvm] 3339632 - [Utils] Avoid repeated hash lookups (NFC) (#130709)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 11 07:34:17 PDT 2025
Author: Kazu Hirata
Date: 2025-03-11T07:34:14-07:00
New Revision: 3339632e9c68ff71071b5ad72b33f7a8ac5658f6
URL: https://github.com/llvm/llvm-project/commit/3339632e9c68ff71071b5ad72b33f7a8ac5658f6
DIFF: https://github.com/llvm/llvm-project/commit/3339632e9c68ff71071b5ad72b33f7a8ac5658f6.diff
LOG: [Utils] Avoid repeated hash lookups (NFC) (#130709)
Added:
Modified:
llvm/lib/Transforms/Utils/LCSSA.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/LCSSA.cpp b/llvm/lib/Transforms/Utils/LCSSA.cpp
index d76a0c2e4ce75..c3c3cdf50a985 100644
--- a/llvm/lib/Transforms/Utils/LCSSA.cpp
+++ b/llvm/lib/Transforms/Utils/LCSSA.cpp
@@ -99,10 +99,10 @@ formLCSSAForInstructionsImpl(SmallVectorImpl<Instruction *> &Worklist,
BasicBlock *InstBB = I->getParent();
Loop *L = LI.getLoopFor(InstBB);
assert(L && "Instruction belongs to a BB that's not part of a loop");
- if (!LoopExitBlocks.count(L))
- L->getExitBlocks(LoopExitBlocks[L]);
- assert(LoopExitBlocks.count(L));
- const SmallVectorImpl<BasicBlock *> &ExitBlocks = LoopExitBlocks[L];
+ auto [It, Inserted] = LoopExitBlocks.try_emplace(L);
+ if (Inserted)
+ L->getExitBlocks(It->second);
+ const SmallVectorImpl<BasicBlock *> &ExitBlocks = It->second;
if (ExitBlocks.empty())
continue;
@@ -389,9 +389,10 @@ static bool formLCSSAImpl(Loop &L, const DominatorTree &DT, const LoopInfo *LI,
}
#endif
- if (!LoopExitBlocks.count(&L))
- L.getExitBlocks(LoopExitBlocks[&L]);
- const SmallVectorImpl<BasicBlock *> &ExitBlocks = LoopExitBlocks[&L];
+ auto [It, Inserted] = LoopExitBlocks.try_emplace(&L);
+ if (Inserted)
+ L.getExitBlocks(It->second);
+ const SmallVectorImpl<BasicBlock *> &ExitBlocks = It->second;
if (ExitBlocks.empty())
return false;
More information about the llvm-commits
mailing list