8389111: C2: Use BMI2 BZHI for variable int low-bit masks on x86 - #32048
8389111: C2: Use BMI2 BZHI for variable int low-bit masks on x86#32048aprilivy wants to merge 2 commits into
Conversation
|
👋 Welcome back aivy! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
Hi @sviswa7 and @jatin-bhateja, would either of you be willing to take a look at this? Thanks! |
|
The total number of required reviews for this PR has been set to 2 based on the presence of this label: |
Webrevs
|
|
Two questions:
|
Thanks!
|
|
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%) |
| // Generate a low-bits mask with BZHI when the shift count is known to be in | ||
| // [0, 31]. | ||
| instruct bzhiI_rReg_rReg_bounded(rRegI dst, rRegI src, immI_1 one, | ||
| immI_M1 minus_one, rFlagsReg cr) |
There was a problem hiding this comment.
Better to change to
instruct bzhiI_rReg_rReg_bounded(rRegI dst, rRegI src, immI_1 one, rRegI shift,
immI_M1 minus_one, rFlagsReg cr)
...
match(Set dst (AndI src (AddI (LShiftI one shift) minus_one)));
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