-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Add missing UnrolledLoopStatement
to PGO region count calculator.
#3524
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 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
This file contains 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
This file contains 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 @@ | ||
// Test PGO instrumentation and profile use for front-end-unrolled loops. | ||
|
||
// REQUIRES: PGO_RT | ||
|
||
// RUN: %ldc -fprofile-instr-generate=%t.profraw -run %s | ||
// RUN: %profdata merge %t.profraw -o %t.profdata | ||
// RUN: %ldc -c -output-ll -of=%t2.ll -fprofile-instr-use=%t.profdata %s | ||
// RUN: FileCheck %allow-deprecated-dag-overlap %s -check-prefix=PROFUSE < %t2.ll | ||
|
||
alias AliasSeq(TList...) = TList; | ||
|
||
void main() { | ||
foreach (i; 0..400) | ||
foofoofoo(i); | ||
} | ||
|
||
// PROFUSE-LABEL: define void @foofoofoo( | ||
// PROFUSE-SAME: !prof ![[FUNCENTRY:[0-9]+]] | ||
extern(C) void foofoofoo(int i) | ||
{ | ||
alias R = AliasSeq!(char, int); | ||
foreach (j, r; R) | ||
{ | ||
if (i + 125*j > 200) | ||
continue; | ||
|
||
if (i + 125*j > 150) | ||
break; | ||
|
||
if (i-j == 0) | ||
goto function_exit; | ||
} | ||
/* The loop will be unrolled to: | ||
{ | ||
// Here: i in [0..399] = 400 counts | ||
// PROFUSE: br {{.*}} !prof ![[IF1_1:[0-9]+]] | ||
if (i + 0 > 200) | ||
continue; // [201..399] = 199 counts | ||
|
||
// [0..200] = 201 counts | ||
// PROFUSE: br {{.*}} !prof ![[IF1_2:[0-9]+]] | ||
if (i + 0 > 150) | ||
break; // [151..200] = 50 counts | ||
|
||
// [0..150] = 151 counts | ||
// PROFUSE: br {{.*}} !prof ![[IF1_3:[0-9]+]] | ||
if (i-0 == 0) | ||
goto function_exit; | ||
} | ||
{ | ||
// [1..150] U [201..399] = 150+199 = 349 counts | ||
// PROFUSE: br {{.*}} !prof ![[IF2_1:[0-9]+]] | ||
if (i + 125 > 200) | ||
continue; // [76..150] U [201..399] = 75+199 = 274 counts | ||
|
||
// [1..75] = 75 counts | ||
// PROFUSE: br {{.*}} !prof ![[IF2_2:[0-9]+]] | ||
if (i + 125 > 150) | ||
break; // [26..75] = 50 counts | ||
|
||
// [1..25] = 25 counts | ||
// PROFUSE: br {{.*}} !prof ![[IF2_3:[0-9]+]] | ||
if (i-1 == 0) | ||
goto function_exit; | ||
} | ||
*/ | ||
|
||
// [2..400] = 398 counts | ||
// PROFUSE: br {{.*}} !prof ![[IFEXIT:[0-9]+]] | ||
if (i) {} // always true | ||
|
||
// 400 counts | ||
function_exit: | ||
} | ||
|
||
// PROFUSE-DAG: ![[FUNCENTRY]] = !{!"function_entry_count", i64 400} | ||
// PROFUSE-DAG: ![[IF1_1]] = !{!"branch_weights", i32 200, i32 202} | ||
// PROFUSE-DAG: ![[IF1_2]] = !{!"branch_weights", i32 51, i32 152} | ||
// PROFUSE-DAG: ![[IF1_3]] = !{!"branch_weights", i32 2, i32 151} | ||
// PROFUSE-DAG: ![[IF2_1]] = !{!"branch_weights", i32 275, i32 76} | ||
// PROFUSE-DAG: ![[IF2_2]] = !{!"branch_weights", i32 51, i32 26} | ||
// PROFUSE-DAG: ![[IF2_3]] = !{!"branch_weights", i32 2, i32 25} | ||
// PROFUSE-DAG: ![[IFEXIT]] = !{!"branch_weights", i32 399, i32 1} | ||
|
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.
Does it make sense to do something in addition or other than
assert
so that detection is explicit in release mode builds that end users will use?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.
I'm not sure. The error may not be user-actionable, and things may also just work without change needed. Would you suggest a warning saying that "Statement on line x is not supported by PGO" ?
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.
(note that this is the same for
CaseRangeStatement
)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.
Something like that. Perhaps requesting that an issue be filed for the purpose of improving LDC. This might make more sense if similar things are already being done elsewhere in the code base.
This rationale is that it might be difficult to catch these cases in the context of LDC development, and instead they'd be more likely to occur when running against user code. Do you think this is the case? If not, then such a message is not needed.
The other part is that PGO computation should proceed reasonably even if the assert condition arises. Ie. Not crash. I didn't try to review the code from this angle.
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.
Mind if I disregard this? We have many asserts in the codebase where we don't really report it to the user. (I think it is not very valuable for the user, to be honest) I do agree that the assert is not very likely to catch things during development, but it might when people use the beta build or latest-ci to have asserts enabled.
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.
I don't mind. It was a suggestion for your consideration, nothing else. And it makes complete sense to be consistent with similar cases in the LDC code base.