diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2025-01-30 20:59:58 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-30 20:59:58 +0700 |
commit | fe1f6b4855ea5cb164524e137ecd891cf0734838 (patch) | |
tree | 01143d69230e830db44ffd5b2ad6c075f78b7cf2 | |
parent | 83ca720ef280256ffb0424947e4221e95b314a09 (diff) | |
download | llvm-fe1f6b4855ea5cb164524e137ecd891cf0734838.zip llvm-fe1f6b4855ea5cb164524e137ecd891cf0734838.tar.gz llvm-fe1f6b4855ea5cb164524e137ecd891cf0734838.tar.bz2 |
PeepholeOpt: Avoid double map lookup (#124531)
-rw-r--r-- | llvm/lib/CodeGen/PeepholeOptimizer.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp index bf450e3..a8a40cd 100644 --- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp +++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp @@ -1035,8 +1035,11 @@ bool PeepholeOptimizer::findNextSource(RegSubRegPair RegSubReg, return false; // Insert the Def -> Use entry for the recently found source. - ValueTrackerResult CurSrcRes = RewriteMap.lookup(CurSrcPair); - if (CurSrcRes.isValid()) { + auto [InsertPt, WasInserted] = RewriteMap.try_emplace(CurSrcPair, Res); + + if (!WasInserted) { + const ValueTrackerResult &CurSrcRes = InsertPt->second; + assert(CurSrcRes == Res && "ValueTrackerResult found must match"); // An existent entry with multiple sources is a PHI cycle we must avoid. // Otherwise it's an entry with a valid next source we already found. @@ -1047,7 +1050,6 @@ bool PeepholeOptimizer::findNextSource(RegSubRegPair RegSubReg, } break; } - RewriteMap.insert(std::make_pair(CurSrcPair, Res)); // ValueTrackerResult usually have one source unless it's the result from // a PHI instruction. Add the found PHI edges to be looked up further. |