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

8288294: [vector] Add Identity/Ideal transformations for vector logic operations #9211

Closed
wants to merge 2 commits into from

Conversation

XiaohongGong
Copy link

@XiaohongGong XiaohongGong commented Jun 20, 2022

This patch adds the following transformations for vector logic operations such as "AndV, OrV, XorV", incuding:

  (AndV v (Replicate m1))   => v
  (AndV v (Replicate zero)) => Replicate zero
  (AndV v v)                => v

  (OrV v (Replicate m1))    => Replicate m1
  (OrV v (Replicate zero))  => v
  (OrV v v)                 => v

  (XorV v v)                => Replicate zero

where "m1" is the integer constant -1, together with the same optimizations for vector mask operations like "AndVMask, OrVMask, XorVMask".


Progress

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

Issue

  • JDK-8288294: [vector] Add Identity/Ideal transformations for vector logic operations

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9211

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 20, 2022

👋 Welcome back xgong! 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 Jun 20, 2022
@openjdk
Copy link

openjdk bot commented Jun 20, 2022

@XiaohongGong 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 Jun 20, 2022
@mlbridge
Copy link

mlbridge bot commented Jun 20, 2022

Webrevs

@XiaohongGong
Copy link
Author

Hi, could anyone please help to take a look at this simple patch? Thanks a lot for your time!

}
// (AndV (Replicate zero) src) => (Replicate zero)
// (AndVMask (MaskAll zero) src) => (MaskAll zero)
if (VectorNode::is_all_zeros_vector(in(1))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you expect it to be in(1) instead of in(2) as in previous case? Do we create inputs in such order based on mask value?
At least add comment explaining it.

Copy link
Author

Choose a reason for hiding this comment

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

We also have the case that the all zeros vector is in(2) in the followed codes. Please see line 1817. The main reason to do the different handle is the consideration for the predicated vector operations in Vector API.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is what confuses me. The comment there says: masked operation requires the unmasked lanes to save the same values in the first operand.

I'm interpreting it as mask should be in(2):
https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/aarch64_sve.ad#L379

But here you check in(1).

Copy link
Author

Choose a reason for hiding this comment

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

The comment means: for masked operations, the result of non-masked lanes should be from in(1), and the masked lanes are from the operation results.
For "AndV" with zero, the results is zero. So if in(1) is all zeros vector which is the expected result, no matter whether the AndV is masked or not, the result is right (i.e. for masked AndV, the non-masked lanes should be from in(1), and the masked lanes should be from the operation result which is also in(1)). But if the all zeros vector is in(2), this transformation will the results not right for masked AndV. That's why I added !is_predicated_vector() limit for the second case while not for the first one.

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment means: for masked operations, the result of non-masked lanes should be from in(1), and the masked lanes are from the operation results.

Okay, I got it finally. Thank you for explanation.

}
// (OrV src (Replicate zero)) => src
// (OrVMask src (MaskAll zero)) => src
if (VectorNode::is_all_zeros_vector(in(2))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The same question as for AndVNode.

Copy link
Author

Choose a reason for hiding this comment

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

The same as AndVNode.

Comment on lines +1867 to +1869
// (XorV src src) => (Replicate zero)
// (XorVMask src src) => (MaskAll zero)
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this? Is Replicate asm instruction faster than XorV? I understand it may help reduce registers pressure.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for looking at this patch! I think the main benefit is "(Replicate zero)" is loop invariant which could be hoist outside of the loop.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay

@vnkozlov
Copy link
Contributor

@jatin-bhateja can you look on this. It is shared code and x86 is also affected.

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.

Tobias already ran testing and results are good.

@openjdk
Copy link

openjdk bot commented Jun 30, 2022

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

8288294: [vector] Add Identity/Ideal transformations for vector logic operations

Reviewed-by: kvn, jbhateja

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 Pull request is ready to be integrated label Jun 30, 2022
@jatin-bhateja
Copy link
Member

jatin-bhateja commented Jun 30, 2022

We can also handle following vector constant folding cases :-
AndV (Replicate Const1) (Replicate Const2) => Replicate (Con1 And Con2)
OrV (Replicate Const1) (Replicate Const2) => Replicate (Con1 Or Con2 )

@jatin-bhateja
Copy link
Member

Other than above patch looks good to me.

@XiaohongGong
Copy link
Author

Thanks so much for the advice @jatin-bhateja ! I basically agree with this idea! It seems the similar optimization can also be applied to other binary arithmetic vector operations like add, sub, mul, div, shift ? So do you think it's better we create another patch special to handle the constant folding for such vector nodes? We'd better find a better way to handle this while not add the same transformation for each node. WDYT?

@XiaohongGong
Copy link
Author

Tobias already ran testing and results are good.

Thanks for the review and testing @vnkozlov !

@jatin-bhateja
Copy link
Member

jatin-bhateja commented Jun 30, 2022

Thanks so much for the advice @jatin-bhateja ! I basically agree with this idea! It seems the similar optimization can also be applied to other binary arithmetic vector operations like add, sub, mul, div, shift ? So do you think it's better we create another patch special to handle the constant folding for such vector nodes? We'd better find a better way to handle this while not add the same transformation for each node. WDYT?

Agree, addressing it in subsequent PR along with other operations should be ok. Thanks.

LGTM.

@XiaohongGong
Copy link
Author

Thanks for the reivew @jatin-bhateja !

@XiaohongGong
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 1, 2022

Going to push as commit 124c63c.
Since your change was applied there have been 4 commits pushed to the master branch:

  • 918068a: Merge
  • c20b3aa: 8289278: Suspend/ResumeAllVirtualThreads need both can_suspend and can_support_virtual_threads
  • 00d06d4: 8289440: Remove vmTestbase/nsk/monitoring/MemoryPoolMBean/isCollectionUsageThresholdExceeded/isexceeded003 from ProblemList.txt
  • feb223a: 8288707: javax/swing/JToolBar/4529206/bug4529206.java: setFloating does not work correctly

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 1, 2022
@openjdk openjdk bot closed this Jul 1, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 1, 2022
@openjdk
Copy link

openjdk bot commented Jul 1, 2022

@XiaohongGong Pushed as commit 124c63c.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@XiaohongGong XiaohongGong deleted the JDK-8288294 branch July 1, 2022 01:20
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
Development

Successfully merging this pull request may close these issues.

3 participants