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

8264409: AArch64: generate better code for Vector API allTrue #3302

Closed
wants to merge 1 commit into from

Conversation

@nsjian
Copy link
Contributor

@nsjian nsjian commented Apr 1, 2021

In Vector API NEON implementation, we use a vector register to represent vector mask, where an element value of -1 is a true mask and an element value of 0 is a false mask. The allTrue() api is used to check whether all the elements of current mask are set.

Currently, the AArch64 NEON allTrue implementation looks like:

andr $tmp, T16B $src1, $src2\t# src2 is maskAllTrue
notr $tmp, T16B, $tmp
addv $tmp, T16B, $tmp
umov $dst, $tmp, B, 0
cmp $dst, 0
cset $dst

where $src2 is a preset all true (-1) constant. We can optimize it to the code sequence like below, to check whether all bits are set:

uminv $tmp, T16B, $src1
umov $dst, $tmp, B, 0
cmp $dst, 0xff
cset $dst

With this codegen improvement, we can see about 8%~70% performance uplift on different machines for Alibaba's Vector API bigdata benchmarks [1][2].

Tested with tier1 and vector api jtreg tests.

[1] https://github.com/openjdk/panama-vector/blob/vectorIntrinsics/test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/bigdata/BooleanArrayCheck.java#L61
[2] https://github.com/openjdk/panama-vector/blob/vectorIntrinsics/test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/bigdata/ValueRangeCheckAndCastL2I.java#L93


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8264409: AArch64: generate better code for Vector API allTrue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3302/head:pull/3302
$ git checkout pull/3302

Update a local copy of the PR:
$ git checkout pull/3302
$ git pull https://git.openjdk.java.net/jdk pull/3302/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3302

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3302.diff

In Vector API NEON implementation, we use a vector register to
represent vector mask, where an element value of -1 is a true mask and
an element value of 0 is a false mask. The allTrue() api is used to
check whether all the elements of current mask are set.

Currently, the AArch64 NEON allTrue implementation looks like:

  andr  $tmp, T16B $src1, $src2\t# src2 is maskAllTrue
  notr  $tmp, T16B, $tmp
  addv  $tmp, T16B, $tmp
  umov  $dst, $tmp, B, 0
  cmp   $dst, 0
  cset  $dst

where $src2 is a preset all true (-1) constant. We can optimize it to
the code sequence like below, to check whether all bits are set:

  uminv $tmp, T16B, $src1
  umov  $dst, $tmp, B, 0
  cmp   $dst, 0xff
  cset  $dst

With this codegen improvement, we can see about 8%~70% performance
uplift on different machines for Alibaba's Vector API bigdata
benchmarks [1][2].

Tested with tier1 and vector api jtreg tests.

[1] https://github.com/openjdk/panama-vector/blob/vectorIntrinsics/test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/bigdata/BooleanArrayCheck.java
[2] https://github.com/openjdk/panama-vector/blob/vectorIntrinsics/test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/bigdata/ValueRangeCheckAndCastL2I.java#L93
@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Apr 1, 2021

👋 Welcome back njian! 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 label Apr 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 1, 2021

@nsjian 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.

@mlbridge
Copy link

@mlbridge mlbridge bot commented Apr 1, 2021

Webrevs

@adinn
adinn approved these changes Apr 1, 2021
Copy link
Contributor

@adinn adinn left a comment

It's a clever trick to use uminv for this specific case.
The patch looks good to me.

@openjdk
Copy link

@openjdk openjdk bot commented Apr 1, 2021

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

8264409: AArch64: generate better code for Vector API allTrue

Reviewed-by: adinn, 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 18 new commits pushed to the master branch:

  • 66d9961: 8205502: Make exception message from AnnotationInvocationHandler more informative
  • 5e59d28: 8262046: Clean up parallel class loading code and comments
  • 04f24fe: 8264403: [macos]: App names containing '.' characters results in an error message when launching
  • b953386: 8264609: Number.{byteValue, shortValue} spec should use @implSpec
  • 5858399: 8264285: Clean the modification of ccstr JVM flags
  • 6e0da99: 8263448: CTW: fatal error: meet not symmetric
  • 328e951: 8169629: Annotations with lambda expressions cause AnnotationFormatError
  • c04a743: 8264557: Incorrect copyright year for test/micro/org/openjdk/bench/java/lang/MathBench.java after JDK-8264054
  • 4b19771: 8264150: CDS dumping code calls TRAPS functions in VM thread
  • 1dc75e9: 8264538: Rename SystemDictionary::parse_stream
  • ... and 8 more: https://git.openjdk.java.net/jdk/compare/39f0b27a127e65985df0899ff881dc99f313dd16...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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Apr 1, 2021
@pfustc
pfustc approved these changes Apr 2, 2021
Copy link
Member

@pfustc pfustc left a comment

Overall looks good to me. (not a reviewer)

"umov $dst, $tmp, B, 0\n\t"
"cmp $dst, 0\n\t"
"cset $dst" %}
"cmp $dst, 0xff\n\t"

This comment has been minimized.

@pfustc

pfustc Apr 2, 2021
Member

I think we should write "#0xff" here. But it looks that all other immediates in format field of aarch64_neon.ad lose the number sign as well.

This comment has been minimized.

@nsjian

nsjian Apr 2, 2021
Author Contributor

Thanks for the review, but I think both are ok.

@nsjian
Copy link
Contributor Author

@nsjian nsjian commented Apr 2, 2021

It's a clever trick to use uminv for this specific case.
The patch looks good to me.

Thank you for the review! @adinn

@nsjian
Copy link
Contributor Author

@nsjian nsjian commented Apr 2, 2021

/integrate

@openjdk openjdk bot closed this Apr 2, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Apr 2, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 2, 2021

@nsjian Since your change was applied there have been 20 commits pushed to the master branch:

  • 4793557: 8264502: (fc) FileDispatcherImpl.setDirect0 might return uninitialized variable on some platforms
  • da643cd: 8264526: javax/swing/text/html/parser/Parser/8078268/bug8078268.java timeout
  • 66d9961: 8205502: Make exception message from AnnotationInvocationHandler more informative
  • 5e59d28: 8262046: Clean up parallel class loading code and comments
  • 04f24fe: 8264403: [macos]: App names containing '.' characters results in an error message when launching
  • b953386: 8264609: Number.{byteValue, shortValue} spec should use @implSpec
  • 5858399: 8264285: Clean the modification of ccstr JVM flags
  • 6e0da99: 8263448: CTW: fatal error: meet not symmetric
  • 328e951: 8169629: Annotations with lambda expressions cause AnnotationFormatError
  • c04a743: 8264557: Incorrect copyright year for test/micro/org/openjdk/bench/java/lang/MathBench.java after JDK-8264054
  • ... and 10 more: https://git.openjdk.java.net/jdk/compare/39f0b27a127e65985df0899ff881dc99f313dd16...master

Your commit was automatically rebased without conflicts.

Pushed as commit 0935eaa.

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