-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8267332: xor value should handle bounded values #4136
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
|
👋 Welcome back neliasso! A progress list of the required criteria for merging this PR into |
Webrevs
|
src/hotspot/share/opto/addnode.cpp
Outdated
| const TypeInt* t2i = t2->is_int(); | ||
| if ((t1i->_lo >= 0) && | ||
| (t1i->_hi > 0) && | ||
| (t1i->_hi <= max_power_of_2<jint>()) && |
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 think you could use <= std::numeric_limits<T>::max() as the upper bound condition, and use (jint)(next_power_of_2((uint)t1i->_hi) - 1) to produce the mask in an overflow-conscious way.
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.
max_power_of_2() is less than std::numeric_limits::max().
But I noticed I got the bounds wrong - is should be strictly less:
t1i->_hi < max_power_of_2()
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.
Right, that's why I widened to an uint (since next_power_of_2((uint)jint::max()) is well-defined) then cast back to a jint after subtracting 1.
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.
Another way of expressing the same in an overflow-conscious way (without type conversion) is round_down_power_of_2(t1i->_hi) + (round_down_power_of_2(t1i->_hi) - 1)
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 agree - that is a much better solution! Thanks Claes!
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.
Very nice. I've added some minor comments to the test.
|
@neliasso This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
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.
Looks good.
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.
Looks good!
|
Thanks for the reviews Tobias and Claes! |
|
/integrate |
In the discussion of #3938 a limitation in C2 was found. C2 fails to eliminate obvious bound checks for indexes that are masked with xor.
The Xor for two values that have a lower bound of zero or more, the resulting lower bound is zero.
The Xor for two values that have a upperbound above zero, the resulting upper bound is the max of the next_power_of_2-1.
Test supplied.
Please review,
Best regards,
Nils Eliasson
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4136/head:pull/4136$ git checkout pull/4136Update a local copy of the PR:
$ git checkout pull/4136$ git pull https://git.openjdk.java.net/jdk pull/4136/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4136View PR using the GUI difftool:
$ git pr show -t 4136Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4136.diff