[llvm] fe1f6b4 - PeepholeOpt: Avoid double map lookup (#124531)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 30 06:00:02 PST 2025
Author: Matt Arsenault
Date: 2025-01-30T20:59:58+07:00
New Revision: fe1f6b4855ea5cb164524e137ecd891cf0734838
URL: https://github.com/llvm/llvm-project/commit/fe1f6b4855ea5cb164524e137ecd891cf0734838
DIFF: https://github.com/llvm/llvm-project/commit/fe1f6b4855ea5cb164524e137ecd891cf0734838.diff
LOG: PeepholeOpt: Avoid double map lookup (#124531)
Added:
Modified:
llvm/lib/CodeGen/PeepholeOptimizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
index bf450e3af0deee..a8a40cdb915ed5 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.
More information about the llvm-commits
mailing list