Skip to content
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

8305324: C2: Wrong execution of vectorizing Interger.reverseBytes #13406

Closed
wants to merge 6 commits into from

Conversation

quadhier
Copy link
Contributor

@quadhier quadhier commented Apr 10, 2023

This patch should fix JDK-8305324.

SuperWord::compute_vector_element_type() implemented in jdk/src/hotspot/share/opto/superword.cpp propagates backward a narrower integer type when the upper bits of the value are not needed. However, Integer.reverseBytes() depends on higher-order bits of an integer and should be prevented from being narrowed and vectorized. Instead, it needs to be treated like Math.abs() (which is represented by Op_AbsI in the following code).

if (same_type) {
// In any Java arithmetic operation, operands of small integer types
// (boolean, byte, char & short) should be promoted to int first. As
// vector elements of small types don't have upper bits of int, for
// RShiftI or AbsI operations, the compiler has to know the precise
// signedness info of the 1st operand. These operations shouldn't be
// vectorized if the signedness info is imprecise.
const Type* vt = vtn;
int op = in->Opcode();
if (VectorNode::is_shift_opcode(op) || op == Op_AbsI) {
Node* load = in->in(1);

I have tested this patch for tier 1-3 on x86-64.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8305324: C2: Wrong execution of vectorizing Interger.reverseBytes

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/13406/head:pull/13406
$ git checkout pull/13406

Update a local copy of the PR:
$ git checkout pull/13406
$ git pull https://git.openjdk.org/jdk.git pull/13406/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13406

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13406.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 10, 2023

👋 Welcome back quadhier! 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 openjdk bot added the rfr Pull request is ready for review label Apr 10, 2023
@openjdk
Copy link

openjdk bot commented Apr 10, 2023

@quadhier 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 Apr 10, 2023
@mlbridge
Copy link

mlbridge bot commented Apr 10, 2023

Webrevs

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good.

@openjdk
Copy link

openjdk bot commented Apr 10, 2023

⚠️ @quadhier the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout fix-8305324
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Apr 10, 2023

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

8305324: C2: Wrong execution of vectorizing Interger.reverseBytes

Reviewed-by: kvn, pli

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 26 new commits pushed to the master branch:

  • b9bdbe9: 8305524: AArch64: Fix arraycopy issue on SVE caused by matching rule vmask_gen_sub
  • 82e8b03: 8305203: Simplify trimming operation in Region::Ideal
  • 27cf638: 8300912: Update java/nio/MappedByteBuffer/PmemTest.java to run on x86_64 only
  • 42fa000: 8305484: Compiler::init_c1_runtime unnecessarily uses an Arena that lives for the lifetime of the process
  • 475e9a7: 8305809: (fs) Review obsolete Linux kernel dependency on os.version (Unix kernel 2.6.39)
  • 1de772c: 8294806: jpackaged-app ignores splash screen from jar file
  • d9db906: 8305368: G1 remset chunk claiming may use relaxed memory ordering
  • c789d24: 8305370: Inconsistent use of for_young_only_phase parameter in G1 predictions
  • c6d7cf6: 8305663: Wrong iteration order of pause array in g1MMUTracker
  • ce4b995: 8305761: Resolve multiple definition of 'jvm' when statically linking with JDK native libraries
  • ... and 16 more: https://git.openjdk.org/jdk/compare/0d45a524b3d29fd57a4d468d7b5af0f588db7409...master

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vnkozlov, @pfustc) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 10, 2023
Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

One comment. We are not using bug id in test names mostly now. Please rename it to something meaningful and place test into compiler/vectorization/ or compiler/loopopts/superword/ directory.

@quadhier
Copy link
Contributor Author

One comment. We are not using bug id in test names mostly now. Please rename it to something meaningful and place test into compiler/vectorization/ or compiler/loopopts/superword/ directory.

Thanks for your review. I'll rename it.

@quadhier
Copy link
Contributor Author

/reviewers 2

@openjdk
Copy link

openjdk bot commented Apr 11, 2023

@quadhier
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 11, 2023
// Decide if an operation on integer requires information
// of its higher order bits/bytes
bool VectorNode::requires_higher_order_bits_of_integer(int opc) {
if (is_shift_opcode(opc) && opc != Op_LShiftI) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking Op_LShiftI here will change behavior for Short s = LShiftI(LoadB) case and similar. May be it is okay and previous code worked because we did not vectorize due to different sizes of destination and Load.

Copy link
Contributor Author

@quadhier quadhier Apr 11, 2023

Choose a reason for hiding this comment

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

Thanks for your review. Yes, I see. AFAICS, the if-condition calling this function wants to check whether higher order bits are needed. So I distill the condition content into a function. The Op_LShiftI is excluded since it doesn't need such info. Do I miss something? Or should the if-condition have checked more than what I thought?

Copy link
Contributor

Choose a reason for hiding this comment

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

What I am trying to say is that before this change vt will be set to velt_type(load) even if in is LShiftI node. With your changes vt will stay == vtn if in is LShiftI node. velt_type(load) could be different from vtn and as result your change may introduce difference in code generation in other than ReverseBytesI cases.
This needs to be tested to see if number of generated vectors is not reduced for such cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Now that I'm not a hundred per cent sure if number of generated vectors is reduced, I'd better revert some changes. I don't want to make this new function's name misleading (as Op_LShiftI doesn't require higher bits info), so I'd rather remove this function. Thanks for your review!

BTW, I notice that you added this if condition at about 2012 in jdk8u, do you remember why you test is_shift in the if condition instead of something like is_rshift or so?

          if (same_type) {
            // For right shifts of small integer types (bool, byte, char, short)
            // we need precise information about sign-ness. Only Load nodes have
            // this information because Store nodes are the same for signed and
            // unsigned values. And any arithmetic operation after a load may
            // expand a value to signed Int so such right shifts can't be used
            // because vector elements do not have upper bits of Int.
            const Type* vt = vtn;
            if (VectorNode::is_shift(in)) {
              Node* load = in->in(1);
              if (load->is_Load() && in_bb(load) && (velt_type(load)->basic_type() == T_INT)) {
                vt = velt_type(load);
              } else if (in->Opcode() != Op_LShiftI) {
                // Widen type to Int to avoid creation of right shift vector
                // (align + data_size(s1) check in stmts_can_pack() will fail).
                // Note, left shifts work regardless type.
                vt = TypeInt::INT;
              }
            }

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, I notice that you added this if condition at about 2012 in jdk8u, do you remember why you test is_shift in the if condition instead of something like is_rshift or so?

At that time we had only 3 shift Int vector operations: LShiftI, RShiftI, URShiftI. It did not make sense to have separate function only for right shift. For loads all operations work since we take type from load. For not loads we left with only RShiftI and URShiftI after excluding LShiftI.

Note, I am not against executing this code only for right shifts but it needs to be tested. And as separate changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your detailed explanations! It helps a lot!

BTW, could you sponsor me? :P

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good.

Copy link
Member

@pfustc pfustc left a comment

Choose a reason for hiding this comment

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

That's ok for me. We can refine the code later if the op list needs to be further extended.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 12, 2023
@quadhier
Copy link
Contributor Author

Thanks a bunch for your reviews! @vnkozlov @pfustc.

@quadhier
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 12, 2023
@openjdk
Copy link

openjdk bot commented Apr 12, 2023

@quadhier
Your change (at version 26fe323) is now ready to be sponsored by a Committer.

@vnkozlov
Copy link
Contributor

This needs to be retested (at least tier1-3) before integration.

@quadhier
Copy link
Contributor Author

This needs to be retested (at least tier1-3) before integration.

It contains a if condition change and a comment change. I have tested the if condition change for tier1-3 on x86-64 at the beginning. Could we just wait the github workflow to finsh? Or Do I need to test locally again? (I only have x86 linux PC and it may cost a long time.)

@quadhier
Copy link
Contributor Author

This is my local test result of release build on Ubuntu 22.04 x86_64:

$ make test TEST=tier1
==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR   
   jtreg:test/hotspot/jtreg:tier1                     2251  2251     0     0   
   jtreg:test/jdk:tier1                               2328  2328     0     0   
   jtreg:test/langtools:tier1                         4373  4373     0     0   
   jtreg:test/jaxp:tier1                                 0     0     0     0   
   jtreg:test/lib-test:tier1                            28    28     0     0   
==============================
TEST SUCCESS

$ make test TEST=tier2
==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR   
   jtreg:test/hotspot/jtreg:tier2                      722   722     0     0   
   jtreg:test/jdk:tier2                               4050  4050     0     0   
   jtreg:test/langtools:tier2                           11    11     0     0   
   jtreg:test/jaxp:tier2                               470   470     0     0   
==============================
TEST SUCCESS

$ make test TEST=tier3
==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR   
   jtreg:test/hotspot/jtreg:tier3                      227   227     0     0   
   jtreg:test/jdk:tier3                               1307  1307     0     0   
   jtreg:test/langtools:tier3                            0     0     0     0   
   jtreg:test/jaxp:tier3                                 0     0     0     0   
==============================
TEST SUCCESS

@vnkozlov
Copy link
Contributor

Thank you for testing. I submitted our internal testing too. After it complete I will sponsor changes.

@quadhier
Copy link
Contributor Author

Okay, thanks a lot.

@vnkozlov
Copy link
Contributor

My testing passed.

@vnkozlov
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 12, 2023

Going to push as commit 19380d7.
Since your change was applied there have been 29 commits pushed to the master branch:

  • 87017b5: 8295859: Update Manual Test Groups
  • 99a9dbc: 8305783: x86_64: Optimize AbsI and AbsL
  • d8af7a6: 8304725: AsyncGetCallTrace can cause SIGBUS on M1
  • b9bdbe9: 8305524: AArch64: Fix arraycopy issue on SVE caused by matching rule vmask_gen_sub
  • 82e8b03: 8305203: Simplify trimming operation in Region::Ideal
  • 27cf638: 8300912: Update java/nio/MappedByteBuffer/PmemTest.java to run on x86_64 only
  • 42fa000: 8305484: Compiler::init_c1_runtime unnecessarily uses an Arena that lives for the lifetime of the process
  • 475e9a7: 8305809: (fs) Review obsolete Linux kernel dependency on os.version (Unix kernel 2.6.39)
  • 1de772c: 8294806: jpackaged-app ignores splash screen from jar file
  • d9db906: 8305368: G1 remset chunk claiming may use relaxed memory ordering
  • ... and 19 more: https://git.openjdk.org/jdk/compare/0d45a524b3d29fd57a4d468d7b5af0f588db7409...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 12, 2023
@openjdk openjdk bot closed this Apr 12, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Apr 12, 2023
@openjdk
Copy link

openjdk bot commented Apr 12, 2023

@vnkozlov @quadhier Pushed as commit 19380d7.

💡 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
3 participants