Skip to content

[StaleProfileMatching] Use only profile anchor size for similarity calculation #126783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace sampleprof;
#define DEBUG_TYPE "sample-profile-matcher"

static cl::opt<unsigned> FuncProfileSimilarityThreshold(
"func-profile-similarity-threshold", cl::Hidden, cl::init(80),
"func-profile-similarity-threshold", cl::Hidden, cl::init(70),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any explanation for the change in threshold? in addition to the change in how it's calculated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just from my observation, may not be accurate. I observed that there were many false negatives(we missed the good match). Recalling that it's under the LCS frame, the matching scope is narrowed, it's very likely to have a good match. So I feel overall threshold is a bit too high, so try to lower it a bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 10% drop meaningful, is 70% final? If so, it's okay to include it here, otherwise the tuning can be done separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 10% drop meaningful, is 70% final? If so, it's okay to include it here, otherwise the tuning can be done separately.

I see, sounds good to tune separately.

cl::desc("Consider a profile matches a function if the similarity of their "
"callee sequences is above the specified percentile."));

Expand Down Expand Up @@ -790,9 +790,8 @@ bool SampleProfileMatcher::functionMatchesProfileHelper(
longestCommonSequence(FilteredIRAnchorsList, FilteredProfileAnchorList,
false /* Match unused functions */);

Similarity =
static_cast<float>(MatchedAnchors.size()) * 2 /
(FilteredIRAnchorsList.size() + FilteredProfileAnchorList.size());
Similarity = static_cast<float>(MatchedAnchors.size()) /
FilteredProfileAnchorList.size();

LLVM_DEBUG(dbgs() << "The similarity between " << IRFunc.getName()
<< "(IR) and " << ProfFunc << "(profile) is "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
; CHECK: Function new_foo is not in profile or profile symbol list.

; CHECK: Run stale profile matching for main
; CHECK: The similarity between new_foo(IR) and foo(profile) is 0.86
; CHECK: The similarity between new_foo(IR) and foo(profile) is 0.75
; CHECK: Function:new_foo matches profile:foo
; CHECK: Run stale profile matching for cold_func
; CHECK: The checksums for new_block_only(IR) and block_only(Profile) match.
Expand Down