Skip to content

Commit 0454dd8

Browse files
authored
[StaleProfileMatching] Use only profile anchor size for similarity calculation (#126783)
We observed that the number of IR anchors is usually greater than the number of profile anchors, because IR anchors can be optimized away later and llvm-profgen might not generate profiles for cold callsites. This can cause missing function matches. I’m changing the similarity calculation to use only the profile anchor size. In another point of view, It also makes sense to reuse as many profile anchors as possible regardless of the new functions in the IR.
1 parent 32c8754 commit 0454dd8

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,8 @@ bool SampleProfileMatcher::functionMatchesProfileHelper(
790790
longestCommonSequence(FilteredIRAnchorsList, FilteredProfileAnchorList,
791791
false /* Match unused functions */);
792792

793-
Similarity =
794-
static_cast<float>(MatchedAnchors.size()) * 2 /
795-
(FilteredIRAnchorsList.size() + FilteredProfileAnchorList.size());
793+
Similarity = static_cast<float>(MatchedAnchors.size()) /
794+
FilteredProfileAnchorList.size();
796795

797796
LLVM_DEBUG(dbgs() << "The similarity between " << IRFunc.getName()
798797
<< "(IR) and " << ProfFunc << "(profile) is "

llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-renaming.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
; REQUIRES: x86_64-linux
22
; REQUIRES: asserts
3-
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile -report-profile-staleness -persist-profile-staleness -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl -pass-remarks=inline --min-call-count-for-cg-matching=0 --min-func-count-for-cg-matching=0 2>&1 | FileCheck %s
3+
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile -report-profile-staleness -persist-profile-staleness -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl -pass-remarks=inline --min-call-count-for-cg-matching=0 --min-func-count-for-cg-matching=0 --func-profile-similarity-threshold=70 2>&1 | FileCheck %s
44
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl --min-call-count-for-cg-matching=10 --min-func-count-for-cg-matching=10 2>&1 | FileCheck %s --check-prefix=TINY-FUNC
55

66
; Verify find new IR functions.
77
; CHECK: Function new_block_only is not in profile or profile symbol list.
88
; CHECK: Function new_foo is not in profile or profile symbol list.
99

1010
; CHECK: Run stale profile matching for main
11-
; CHECK: The similarity between new_foo(IR) and foo(profile) is 0.86
11+
; CHECK: The similarity between new_foo(IR) and foo(profile) is 0.75
1212
; CHECK: Function:new_foo matches profile:foo
1313
; CHECK: Run stale profile matching for cold_func
1414
; CHECK: The checksums for new_block_only(IR) and block_only(Profile) match.

0 commit comments

Comments
 (0)