[llvm-branch-commits] [llvm] PeepholeOpt: Avoid double map lookup (PR #124531)
Kazu Hirata via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 27 22:16:15 PST 2025
================
@@ -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) {
+ ValueTrackerResult CurSrcRes = InsertPt->second;
----------------
kazutakahirata wrote:
You might want to make this const reference because you are not modifying `ValueTrackerResult` within this `if` block. Note that `ValueTrackerResult` contains a `SmallVector<RegSubRegPair, 2>`, so it's not completely cheap to copy.
```suggestion
const ValueTrackerResult &CurSrcRes = InsertPt->second;
```
https://github.com/llvm/llvm-project/pull/124531
More information about the llvm-branch-commits
mailing list