Skip to content

Conversation

@reinrich
Copy link
Member

@reinrich reinrich commented Oct 24, 2025

With this change c2 will allocate spill slots for vectors with sp offsets aligned to the size of the vectors. Maximum alignment is StackAlignmentInBytes.

It also updates comments that have never been changed to describe how register allocation works for sizes larger than 64 bit.

The change helps to produce better spill code on AARCH64 and PPC64 where an additional add instruction is emitted if the offset of a vector un-/spill is not aligned.

The change is rather a cleanup than an optimization. In most cases the sp offsets will already be properly aligned.
Only with incoming stack arguments unaligned offsets can be generated. But also then alignment padding is only added if vector registers larger than 64 bit are used.

So the costs are effectively zero. Especially because extra padding won't enlarge the frame since only virtual registers are allocated which are mapped to the caller frame (see pad0 in the diagram)

There's a risk though that with the extra virtual registers allocated for pad0 the limit of registers a RegMask can represent is reached (occurs with excessive spilling). If this happens the compilation would fail. It could be retried with smaller alignment for vector spilling though. I havn't implemented it as I thought the risk is negligible.

Note that the sp offset of the accesses should be aligned rather than the effective address. So it could even be argued that the maximum alignment could be higher than StackAlignmentInBytes.

Testing with fastdebug builds on AARCH64 and PPC64:

hotspot_vector_1
hotspot_vector_2
jdk_vector
jdk_vector_sanity

The change passed our CI testing:

Tier 1-4 of hotspot and jdk. All of langtools and jaxp. Renaissance Suite and SAP specific tests.
Testing was done on the main platforms and also on Linux/PPC64le and AIX.

C2 compilation of jdk.internal.vm.vector.VectorSupport::rearrangeOp has unaligned spill offsets. It is covered by the following tests:

compiler/vectorapi/VectorRearrangeTest.java
jdk/incubator/vector/Byte128VectorLoadStoreTests.java
jdk/incubator/vector/Double256VectorLoadStoreTests.java
jdk/incubator/vector/Float128VectorTests.java
jdk/incubator/vector/Long256VectorLoadStoreTests.java
jdk/incubator/vector/Short128VectorLoadStoreTests.java
jdk/incubator/vector/Vector64ConversionTests.java


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-8370473: C2: Better Aligment of Vector Spill Slots (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27969

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

Using diff file

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

@reinrich reinrich changed the title Align matcher new sp for vector spilling 8370473: C2: Better Aligment of Vector Spill Slots Oct 24, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 24, 2025

👋 Welcome back rrich! 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
Copy link

openjdk bot commented Oct 24, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Oct 24, 2025
@openjdk
Copy link

openjdk bot commented Oct 24, 2025

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

@reinrich reinrich force-pushed the align_matcher_new_sp_for_vector_spilling branch from 5d3c383 to 38a25e1 Compare October 24, 2025 15:55
@reinrich reinrich force-pushed the align_matcher_new_sp_for_vector_spilling branch from 38a25e1 to ef7ba14 Compare October 29, 2025 09:00
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

Development

Successfully merging this pull request may close these issues.

1 participant