-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8318562: Computational test more than 2x slower when AVX instructions are used #16701
Conversation
👋 Welcome back sviswanathan! A progress list of the required criteria for merging this PR into |
/label hotspot-compiler |
@sviswa7 |
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.
@sviswa7 thank you for finding the cause! I will test it locally.
I confirmed that this change solved performance issue on machines I tested (old Broadwell and Cascade Lake CPUs). |
@vnkozlov Thanks a lot! |
Hi @sviswa7 , Thanks for addressing this. For SSE versions of cvtsi2sd, Bits (MAXVL-1:64) of the corresponding destination register remain unchanged. For AVX NDS version i.e. vcvtsi2sd, Bits (127:64) of the XMM register destination are copied from the corresponding bits in the first source operand. Bits (MAXVL-1:128) of the destination register are zeroed. Since all the computation in backend initially happens in logical register and only at retirement backend copies the logical register to architectural register, thus from micro architectural standpoint both the cases will result in emission of extra micro-op, in first case for merging and in second case for copying. Which is why we inject vzeroupper to save merging penalties b/w AVX2/AVX512 and SSE transitions. Your fix of adding a prior zeroing idiom to break the copying dependency looks ok to me otherwise. |
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.
For cvtss2sd
and cvtsd2ss
, can we use vcvtss2sd(dst, src, src)
. This removes the redundant xor
on newer machines.
Another solution is to have an inallocatable register that is known to be not stalled. A zero vector register also helps in object creation and calculations that need zeroes in general. However, this fix looks fine to me.
Thanks a lot.
@@ -11089,7 +11089,7 @@ instruct convF2D_reg_mem(regD dst, memory src) | |||
instruct convD2F_reg_reg(regF dst, regD src) | |||
%{ | |||
match(Set dst (ConvD2F src)); | |||
|
|||
effect(TEMP dst); |
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.
You don't need TEMP dst
, if dst
is an alias of src
then a destructive xor
is not emitted.
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.
Without TEMP annotation dst and src may be aliased if src live range does not survives beyond this instruction.
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 had checked before submitting the PR, the cvt xmm0, xmm0, xmm0 form was slower than xorps xmm1, xmm1 followed by cvt xmm1, xmm1, xmm0.
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.
My tier1-4,xcomp,stress passed.
@sviswa7 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 31 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Thanks a lot for the reviews @vnkozlov @jatin-bhateja @merykitty. |
/integrate |
Going to push as commit 0881f2b.
Your commit was automatically rebased without conflicts. |
@sviswa7 You mean |
/backport jdk21u |
@sviswa7 the backport was successfully created on the branch sviswa7-backport-0881f2b0 in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:
|
/backport jdk17u-dev |
@sviswa7 Could not automatically backport
Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.
Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title |
This PR fixes the perf regression seen on AVX for floating point conversions.
In AVX the cvt instructions have three operands cvtxx dst, src1, src2. Where src2 is the one being converted. The dst gets the lower bits as the converted value and upper bits (up to 128) from src1.
The C2 jit uses the cvtxx dst, dst, src2 flavor. Here the problem was due to uninitialized upper bits of the dst XMM register.
Doing an xor dst, dst before the conversion instruction fixes the perf regression.
Perf before the patch on UseAVX=3 platform:
ComputePI.compute_pi_dbl_flt avgt 5 471.875 ± 0.400 ns/op
ComputePI.compute_pi_flt_dbl avgt 5 1877.174 ± 0.557 ns/op
ComputePI.compute_pi_int_dbl avgt 5 655.222 ± 28.082 ns/op
ComputePI.compute_pi_int_flt avgt 5 737.178 ± 0.077 ns/op
ComputePI.compute_pi_long_dbl avgt 5 767.364 ± 0.027 ns/op
ComputePI.compute_pi_long_flt avgt 5 587.854 ± 10.068 ns/op
Perf after the patch on UseAVX=3 platform:
Benchmark Mode Cnt Score Error Units
ComputePI.compute_pi_dbl_flt avgt 5 468.328 ± 0.141 ns/op
ComputePI.compute_pi_flt_dbl avgt 5 435.430 ± 0.259 ns/op
ComputePI.compute_pi_int_dbl avgt 5 424.088 ± 0.050 ns/op
ComputePI.compute_pi_int_flt avgt 5 417.345 ± 0.207 ns/op
ComputePI.compute_pi_long_dbl avgt 5 425.751 ± 0.006 ns/op
ComputePI.compute_pi_long_flt avgt 5 430.199 ± 0.736 ns/op
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16701/head:pull/16701
$ git checkout pull/16701
Update a local copy of the PR:
$ git checkout pull/16701
$ git pull https://git.openjdk.org/jdk.git pull/16701/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16701
View PR using the GUI difftool:
$ git pr show -t 16701
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16701.diff
Webrev
Link to Webrev Comment