Skip to content

Commit fe1f6b4

Browse files
authored
PeepholeOpt: Avoid double map lookup (#124531)
1 parent 83ca720 commit fe1f6b4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

llvm/lib/CodeGen/PeepholeOptimizer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,11 @@ bool PeepholeOptimizer::findNextSource(RegSubRegPair RegSubReg,
10351035
return false;
10361036

10371037
// Insert the Def -> Use entry for the recently found source.
1038-
ValueTrackerResult CurSrcRes = RewriteMap.lookup(CurSrcPair);
1039-
if (CurSrcRes.isValid()) {
1038+
auto [InsertPt, WasInserted] = RewriteMap.try_emplace(CurSrcPair, Res);
1039+
1040+
if (!WasInserted) {
1041+
const ValueTrackerResult &CurSrcRes = InsertPt->second;
1042+
10401043
assert(CurSrcRes == Res && "ValueTrackerResult found must match");
10411044
// An existent entry with multiple sources is a PHI cycle we must avoid.
10421045
// Otherwise it's an entry with a valid next source we already found.
@@ -1047,7 +1050,6 @@ bool PeepholeOptimizer::findNextSource(RegSubRegPair RegSubReg,
10471050
}
10481051
break;
10491052
}
1050-
RewriteMap.insert(std::make_pair(CurSrcPair, Res));
10511053

10521054
// ValueTrackerResult usually have one source unless it's the result from
10531055
// a PHI instruction. Add the found PHI edges to be looked up further.

0 commit comments

Comments
 (0)