Skip to content

Commit 3339632

Browse files
[Utils] Avoid repeated hash lookups (NFC) (#130709)
1 parent 8c2714e commit 3339632

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

llvm/lib/Transforms/Utils/LCSSA.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ formLCSSAForInstructionsImpl(SmallVectorImpl<Instruction *> &Worklist,
9999
BasicBlock *InstBB = I->getParent();
100100
Loop *L = LI.getLoopFor(InstBB);
101101
assert(L && "Instruction belongs to a BB that's not part of a loop");
102-
if (!LoopExitBlocks.count(L))
103-
L->getExitBlocks(LoopExitBlocks[L]);
104-
assert(LoopExitBlocks.count(L));
105-
const SmallVectorImpl<BasicBlock *> &ExitBlocks = LoopExitBlocks[L];
102+
auto [It, Inserted] = LoopExitBlocks.try_emplace(L);
103+
if (Inserted)
104+
L->getExitBlocks(It->second);
105+
const SmallVectorImpl<BasicBlock *> &ExitBlocks = It->second;
106106

107107
if (ExitBlocks.empty())
108108
continue;
@@ -389,9 +389,10 @@ static bool formLCSSAImpl(Loop &L, const DominatorTree &DT, const LoopInfo *LI,
389389
}
390390
#endif
391391

392-
if (!LoopExitBlocks.count(&L))
393-
L.getExitBlocks(LoopExitBlocks[&L]);
394-
const SmallVectorImpl<BasicBlock *> &ExitBlocks = LoopExitBlocks[&L];
392+
auto [It, Inserted] = LoopExitBlocks.try_emplace(&L);
393+
if (Inserted)
394+
L.getExitBlocks(It->second);
395+
const SmallVectorImpl<BasicBlock *> &ExitBlocks = It->second;
395396
if (ExitBlocks.empty())
396397
return false;
397398

0 commit comments

Comments
 (0)