Skip to content

Conversation

@neliasso
Copy link

@neliasso neliasso commented May 20, 2021

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

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4136/head:pull/4136
$ git checkout pull/4136

Update a local copy of the PR:
$ git checkout pull/4136
$ git pull https://git.openjdk.java.net/jdk pull/4136/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4136

View PR using the GUI difftool:
$ git pr show -t 4136

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4136.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 20, 2021

👋 Welcome back neliasso! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented May 20, 2021

@neliasso The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label May 20, 2021
@neliasso neliasso marked this pull request as ready for review May 20, 2021 21:23
@openjdk openjdk bot added the rfr Pull request is ready for review label May 20, 2021
@mlbridge
Copy link

mlbridge bot commented May 20, 2021

Webrevs

const TypeInt* t2i = t2->is_int();
if ((t1i->_lo >= 0) &&
(t1i->_hi > 0) &&
(t1i->_hi <= max_power_of_2<jint>()) &&
Copy link
Member

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.

Copy link
Author

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()

Copy link
Member

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.

Copy link
Member

@cl4es cl4es May 20, 2021

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)

Copy link
Author

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!

Copy link
Member

@TobiHartmann TobiHartmann left a 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.

@openjdk
Copy link

openjdk bot commented May 21, 2021

@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:

8267332: xor value should handle bounded values

Reviewed-by: thartmann, redestad

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 master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 21, 2021
Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Looks good.

Copy link
Member

@cl4es cl4es left a comment

Choose a reason for hiding this comment

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

Looks good!

@neliasso
Copy link
Author

Thanks for the reviews Tobias and Claes!

@neliasso
Copy link
Author

/integrate

@openjdk openjdk bot closed this May 21, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 21, 2021
@openjdk
Copy link

openjdk bot commented May 21, 2021

@neliasso Pushed as commit 4ba7613.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants