-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[BOLT][AArch64] Check Last Element Instead of Returning nullptr in lookupStubFromGroup
#114015
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
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-bolt Author: Nicholas (liusy58) ChangesThe current implementation of Full diff: https://github.com/llvm/llvm-project/pull/114015.diff 1 Files Affected:
diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp
index 0b2d00300f46b9..77acd2decc9bd9 100644
--- a/bolt/lib/Passes/LongJmp.cpp
+++ b/bolt/lib/Passes/LongJmp.cpp
@@ -130,9 +130,9 @@ BinaryBasicBlock *LongJmpPass::lookupStubFromGroup(
const std::pair<uint64_t, BinaryBasicBlock *> &RHS) {
return LHS.first < RHS.first;
});
- if (Cand == Candidates.end())
- return nullptr;
- if (Cand != Candidates.begin()) {
+ if (Cand == Candidates.end()) {
+ Cand = std::prev(Cand);
+ } else if (Cand != Candidates.begin()) {
const StubTy *LeftCand = std::prev(Cand);
if (Cand->first - DotAddress > DotAddress - LeftCand->first)
Cand = LeftCand;
|
lookupStubFromGroup Should Check the Last Element Instead of Returning nullptr When lower_bound Reaches End Iteratornullptr in lookupStubFromGroup
nullptr in lookupStubFromGroupnullptr in lookupStubFromGroup
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.
Thanks for your patch! At a quick glance this seems to be a valid edge case.
It happens when all candidates (sorted stubs) are smaller than the input DotAddress?
In theory, there can be a pathological case where each DotAddress happens to be bigger during lookup, causing the creation of new stubs each time.
Have you encountered any such extremes? And can you come up with a test case?
|
Sharing some stats based on a follow-up investigation I did as part of issue #99848 Details: This caused a total of 388 cold stubs to be created, 121 down from 509 (which is just #96609, without #114015; see table here at section 3). The extra 3 stubs that were not created (ie the remainder of 121-118), were local cold stubs that happen to remain in the range of PCOffset, probably due to the overall reduction of stubs. |
ec99f37 to
5e5cb16
Compare
paschalis-mpeis
left a comment
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.
Thanks for adding the test. LGTM!
Please consider addressing the below nits.
The current implementation of `lookupStubFromGroup` is incorrect. The function is intended to find and return the closest stub using `lower_bound`, which identifies the first element in a sorted range that is not less than a specified value. However, if such an element is not found within `Candidates` and the list is not empty, the function returns `nullptr`. Instead, it should check whether the last element satisfies the condition.
paschalis-mpeis
left a comment
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.
Sorry, another nit I've missed.
Consider renaming your test file to something like long-jmp-one-stub.s
|
Okay, I have updated the file name. |
|
Thanks @liusy58 that is some fast action! Not sure if I'm missing something, I still see the file as |
|
Ok, I will fix it right away. |
|
Removing |
Are you sure? I thought testing like |
|
Let me try it! |
|
@paschalis-mpeis I have updated again! |
|
Great, thanks for all the changes! Give it a bit of time in case Meta has any comments. If not, you may merge by EOD tomorrow? |
|
Thank you! |
|
I might have messed up the commit, so I opened another PR. Sorry about that... |
|
Sorry, what was 'messed up' with this commit? I don't see an issue. |
|
@liusy58 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
The current implementation of
lookupStubFromGroupis incorrect. The function is intended to find and return the closest stub usinglower_bound, which identifies the first element in a sorted range that is not less than a specified value. However, if such an element is not found withinCandidatesand the list is not empty, the function returnsnullptr. Instead, it should check whether the last element satisfies the condition.