-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm-profgen] Add --sample-period to estimate absolute counts #99826
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// RUN: llvm-profgen --format=text --perfscript=%S/Inputs/cmov_3.perfscript --binary=%S/Inputs/cmov_3.perfbin --output=%t --skip-symbolization --perf-event=br_inst_retired.near_taken:upp --sample-period=1000003 | ||
// RUN: FileCheck %s --input-file %t --check-prefix=CHECK-RAW-PROFILE | ||
// RUN: llvm-profgen --format=text --perfscript=%S/Inputs/cmov_3.perfscript --binary=%S/Inputs/cmov_3.perfbin --output=%t --perf-event=br_inst_retired.near_taken:upp --sample-period=1000003 | ||
// RUN: FileCheck %s --input-file %t --check-prefix=CHECK | ||
|
||
// RUN: llvm-profgen --format=text --perfscript=%S/Inputs/cmov_3.perfscript --binary=%S/Inputs/cmov_3.perfbin --output=%t --skip-symbolization --perf-event=br_misp_retired.all_branches:upp --leading-ip-only --sample-period=1000003 | ||
// RUN: FileCheck %s --input-file %t --check-prefix=UNPRED-RAW-PROFILE | ||
// RUN: llvm-profgen --format=text --perfscript=%S/Inputs/cmov_3.perfscript --binary=%S/Inputs/cmov_3.perfbin --output=%t --perf-event=br_misp_retired.all_branches:upp --leading-ip-only --sample-period=1000003 | ||
// RUN: FileCheck %s --input-file %t --check-prefix=UNPRED | ||
|
||
// Check that we can use perf event filtering to generate multiple types of | ||
// source-level profiles from a single perf profile. In this case, we generate | ||
// a typical execution frequency profile using br_inst_retired.near_taken LBRs, | ||
// and a branch mispredict profile using br_misp_retired.all_branches sample | ||
// IPs. | ||
|
||
// Check that we can use --sample-period to compute LBR and IP-based profiles | ||
// which have comparable and absolute magnitudes. For example, in this case the | ||
// branch of interest (at source line offset 4) is in a loop body which is | ||
// executed ~20M times in total, and it's mispredicted about 9M times, yielding | ||
// a mispredict rate of roughly 0.45. | ||
|
||
// The source example below is based on perfKernelCpp/cmov_3, except a | ||
// misleading builtin is used to persuade the compiler not to use cmov, which | ||
// induces branch mispredicts. | ||
|
||
// CHECK: sel_arr:652547082:0 | ||
// CHECK: 3.1: 20225766 | ||
// CHECK: 3.2: 20225766 | ||
// CHECK: 4: 19838670 | ||
// CHECK: 5: 20225766 | ||
|
||
// UNPRED: sel_arr:18000054:0 | ||
// UNPRED: 3.1: 0 | ||
// UNPRED: 3.2: 0 | ||
// UNPRED: 4: 9000027 | ||
// UNPRED: 5: 0 | ||
|
||
// CHECK-RAW-PROFILE: 3 | ||
// CHECK-RAW-PROFILE-NEXT: 2f0-2fa:9774174 | ||
// CHECK-RAW-PROFILE-NEXT: 2f0-310:10064496 | ||
// CHECK-RAW-PROFILE-NEXT: 2ff-310:10161270 | ||
|
||
// UNPRED-RAW-PROFILE: 1 | ||
// UNPRED-RAW-PROFILE-NEXT: 2fa-2fa:9000027 | ||
|
||
// original code: | ||
// icx -fprofile-sample-generate lit.c | ||
#include <stdlib.h> | ||
|
||
#define N 20000 | ||
#define ITERS 10000 | ||
|
||
static int *m_s1, *m_s2, *m_s3, *m_dst; | ||
|
||
void init(void) { | ||
m_s1 = malloc(sizeof(int)*N); | ||
m_s2 = malloc(sizeof(int)*N); | ||
m_s3 = malloc(sizeof(int)*N); | ||
m_dst = malloc(sizeof(int)*N); | ||
srand(42); | ||
|
||
for (int i = 0; i < N; i++) { | ||
m_s1[i] = rand() % N; | ||
m_s2[i] = 0; | ||
m_s3[i] = 1; | ||
} | ||
} | ||
|
||
void __attribute__((noinline)) sel_arr(int *dst, int *s1, int *s2, int *s3) { | ||
#pragma nounroll | ||
#pragma clang loop vectorize(disable) interleave(disable) | ||
for (int i = 0; i < N; i++) { | ||
int *p = __builtin_expect((s1[i] < 10035), 0) ? &s2[i] : &s3[i]; | ||
dst[i] = *p; | ||
} | ||
} | ||
|
||
int main(void) { | ||
init(); | ||
for(int i=0; i<ITERS; ++i) | ||
sel_arr(m_dst, m_s1, m_s2, m_s3); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be confusing -- having default value 1 implies we always assume a sample period of 1.