You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C2 currently lowers variable int low-bit masks of the form:
value & ((1 << bits) - 1)
to a five-instruction sequence on x86. This change adds a BMI2 matcher rule that uses BZHI, reducing it to three instructions.
The shift count is explicitly masked with 31 because Java shift distances wrap modulo 32, while BZHI treats counts greater than or equal to 32 differently.
A scalar JMH throughput benchmark on a Ryzen 9 9950X3D improved from approximately 0.199 ns/op to 0.185 ns/op (6.9%).
Testing:
HotSpot release and fastdebug builds
compiler/intrinsics/bmi: 26/26 tests passed
Verified generated assembly with UseBMI2Instructions enabled and disabled
👋 Welcome back aivy! 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.
@aprilivy 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.
The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot-compiler. This can be overridden with the /reviewers command.
This should also work with long, right? Is there a specific reason why this change is int only?
Would it make sense to only emit the and instruction if necessary?
Thanks!
Yes, the analogous long rule is semantically valid, using a count mask of 63. I prototyped it, but it regressed the scalar benchmark on my system, so I left it out rather than include a rule without a demonstrated improvement. It could be investigated separately though.
Yes. The andl 31 is required for an unrestricted count to preserve shift semantics, but it can be omitted when C2 proves that the count is already in [0, 31]. I’ll investigate adding a range-guarded form for that case.
I’ve now added the bounded-count form discussed above. When C2 proves the count is within [0, 31], it selects a BZHI rule without the extra mask, unrestricted counts retain the andl 31 fallback. I also added IR coverage for both paths. The bounded benchmark improved from 0.207 to 0.197 ns/op (~4.8%)
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
hotspot-compilerhotspot-compiler-dev@openjdk.orgrfrPull request is ready for review
2 participants
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.
C2 currently lowers variable
intlow-bit masks of the form:to a five-instruction sequence on x86. This change adds a BMI2 matcher rule that uses
BZHI, reducing it to three instructions.The shift count is explicitly masked with
31because Java shift distances wrap modulo 32, whileBZHItreats counts greater than or equal to 32 differently.A scalar JMH throughput benchmark on a Ryzen 9 9950X3D improved from approximately 0.199 ns/op to 0.185 ns/op (6.9%).
Testing:
compiler/intrinsics/bmi: 26/26 tests passedUseBMI2Instructionsenabled and disabledProgress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/32048/head:pull/32048$ git checkout pull/32048Update a local copy of the PR:
$ git checkout pull/32048$ git pull https://git.openjdk.org/jdk.git pull/32048/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 32048View PR using the GUI difftool:
$ git pr show -t 32048Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/32048.diff
Using Webrev
Link to Webrev Comment