[llvm] [SampleProfileMatcher] Fix backward matching of non-anchor locations (PR #190118)
Grigory Pastukhov via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 6 09:44:26 PDT 2026
================
@@ -234,10 +234,12 @@ SampleProfileMatcher::longestCommonSequence(const AnchorList &AnchorList1,
void SampleProfileMatcher::matchNonCallsiteLocs(
const LocToLocMap &MatchedAnchors, const AnchorMap &IRAnchors,
LocToLocMap &IRToProfileLocationMap) {
- auto InsertMatching = [&](const LineLocation &From, const LineLocation &To) {
+ auto UpdateMatching = [&](const LineLocation &From, const LineLocation &To) {
// Skip the unchanged location mapping to save memory.
if (From != To)
- IRToProfileLocationMap.insert({From, To});
+ IRToProfileLocationMap.insert_or_assign(From, To);
+ else
+ IRToProfileLocationMap.erase(From);
----------------
grigorypas wrote:
But IRToProfileLocationMap is only modified through UpdateMatching lambda. Wouldn't the following code prevent inserting or changing to (5, 5) and (7, 7)?
```cpp
auto UpdateMatching = [&](const LineLocation &From, const LineLocation &To) {
// Skip the unchanged location mapping to save memory.
if (From != To)
IRToProfileLocationMap.insert_or_assign(From, To);
};
```
I think, `erase` is redundant.
https://github.com/llvm/llvm-project/pull/190118
More information about the llvm-commits
mailing list