-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8303278: Imprecise bottom type of ExtractB/UB #13070
Conversation
This is a trivial patch, which fixes the bottom type of ExtractB/UB nodes. ExtractNode can be generated by Vector API Vector.lane(int), which gets the lane element at the given index. A more precise type of range can help to optimize out unnecessary type conversion in some cases. Below shows a typical case used ExtractBNode ``` public static byte byteLt16() { ByteVector vecb = ByteVector.broadcast(ByteVector.SPECIES_128, 1); return vecb.lane(1); } ``` In this case, c2 constructs IR graph like: ExtractB ConI(24) | __| | / | LShiftI __| | / RShiftI which generates AArch64 code: movi v16.16b, #0x1 smov x11, v16.b[1] sxtb w0, w11 with this patch, this shift pair can be optimized out by RShiftI's identity [1]. The code is optimized to: movi v16.16b, #0x1 smov x0, v16.b[1] [TEST] Full jtreg passed except 4 files on x86: jdk/incubator/vector/Byte128VectorTests.java jdk/incubator/vector/Byte256VectorTests.java jdk/incubator/vector/Byte512VectorTests.java jdk/incubator/vector/Byte64VectorTests.java They are caused by a known issue on x86 [2]. [1] https://github.com/openjdk/jdk/blob/742bc041eaba1ff9beb7f5b6d896e4f382b030ea/src/hotspot/share/opto/mulnode.cpp#L1052 [2] https://bugs.openjdk.org/browse/JDK-8303508 Change-Id: Ibea9aeacb41b4d1c5b2621c7a97494429394b599
👋 Welcome back eliu! A progress list of the required criteria for merging this PR into |
@theRealELiu The following label will be automatically applied to this pull request:
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. |
Webrevs
|
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 to me too.
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.
This triggers failures in testing:
jdk/incubator/vector/Byte64VectorTests.java
java.lang.Exception: failures: 1
at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:95)
at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:53)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:125)
at java.base/java.lang.Thread.run(Thread.java:1623)
I think this should be caused by https://bugs.openjdk.org/browse/JDK-8303508. The removed narrowing exposed this issue on x86, that the generated code of ExtractB perhaps does not handle sign-bit correctly. TBH I'm not familiar with x86 instructions... @jatin-bhateja Could you help to take a look at this bug? |
Yes x86 does not handle signed extension correctly. jdk/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp Line 2247 in bbca7c3
|
Currently C2 folds following IR sequence
Because ideal type of ExtractS is TypeInt::SHORT hence entire chain of conversion operations are folded by compiler during idealizations. There are two ways to address this issue:-
I agree with @merykitty that 2) solution looks more robust since it will enforce accurate semantics of ExtractS IR. |
Change-Id: I40cce803da09bae31cd74b86bf93607a08219545
@TobiHartmann Could you help to take a look? |
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.
Sure, I'll re-run testing.
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. All tests passed.
@theRealELiu 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 112 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 |
/integrate |
Going to push as commit ac898e9.
Your commit was automatically rebased without conflicts. |
@theRealELiu Pushed as commit ac898e9. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This is a trivial patch, which fixes the bottom type of ExtractB/UB nodes.
ExtractNode can be generated by Vector API Vector.lane(int), which gets the lane element at the given index. A more precise type of range can help to optimize out unnecessary type conversion in some cases.
Below shows a typical case used ExtractBNode
In this case, c2 constructs IR graph like:
which generates AArch64 code:
movi v16.16b, #0x1
smov x11, v16.b[1]
sxtb w0, w11
with this patch, this shift pair can be optimized out by RShiftI's identity [1]. The code is optimized to:
movi v16.16b, #0x1
smov x0, v16.b[1]
[TEST]
Full jtreg passed except 4 files on x86:
jdk/incubator/vector/Byte128VectorTests.java
jdk/incubator/vector/Byte256VectorTests.java
jdk/incubator/vector/Byte512VectorTests.java
jdk/incubator/vector/Byte64VectorTests.java
They are caused by a known issue on x86 [2].
[1]
jdk/src/hotspot/share/opto/mulnode.cpp
Line 1052 in 742bc04
[2] https://bugs.openjdk.org/browse/JDK-8303508
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/13070/head:pull/13070
$ git checkout pull/13070
Update a local copy of the PR:
$ git checkout pull/13070
$ git pull https://git.openjdk.org/jdk.git pull/13070/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 13070
View PR using the GUI difftool:
$ git pr show -t 13070
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13070.diff
Webrev
Link to Webrev Comment