Skip to content

8388193: [lworld] C2's ClearArray keeps zero fill value alive in register#2641

Draft
TobiHartmann wants to merge 2 commits into
openjdk:lworldfrom
TobiHartmann:JDK-8388193
Draft

8388193: [lworld] C2's ClearArray keeps zero fill value alive in register#2641
TobiHartmann wants to merge 2 commits into
openjdk:lworldfrom
TobiHartmann:JDK-8388193

Conversation

@TobiHartmann

@TobiHartmann TobiHartmann commented Jul 14, 2026

Copy link
Copy Markdown
Member

Valhalla extended ClearArrayNode with a value input to support nonzero initialization of flattened/null-restricted arrays. Ordinary array clears still supplied a ConL(0) and on x86 the matcher treated that value as an input constrained to RAX. This extended the live range causing increasing spills and a performance regression with the DaCapo23-biojava-large benchmark.

The zero-fill rules now match immL0, only use RAX as a local temporary and materialize zero in MacroAssembler::clear_mem like mainline code does. The fix also renames word_copy_only to requires_word_fill, improved comments and predicates and fixes some of the outdated opto assembly printing.

With this fix, we are back to baseline performance (from 47 ms/op to 35 ms/op).

Thanks,
Tobias



Progress

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

Issue

  • JDK-8388193: [lworld] C2's ClearArray keeps zero fill value alive in register (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2641

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2641.diff

@bridgekeeper

bridgekeeper Bot commented Jul 14, 2026

Copy link
Copy Markdown

👋 Welcome back thartmann! A progress list of the required criteria for merging this PR into lworld 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 commented Jul 14, 2026

Copy link
Copy Markdown

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

@chhagedorn chhagedorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix looks good, thanks! And good clean-ups, I have some small comments following up on that.


// clear memory of size 'cnt' qwords, starting at 'base' using XMM/YMM/ZMM registers
// Fill memory with 'val', for 'cnt' qwords starting at 'base', using XMM/YMM/ZMM registers.
void MacroAssembler::xmm_clear_mem(Register base, Register cnt, Register val, XMMRegister xtmp, KRegister mask) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also update xmm_clear_mem to xmm_fill_mem?

We should also do these comment updates in the header file.

// cnt - number of qwords (8-byte words).
// base - start address, qword aligned.
Label L_zero_64_bytes, L_loop, L_sloop, L_tail, L_end;
Label L_fill_64_bytes, L_loop, L_sloop, L_tail, L_end;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are still some references in the .ad file to L_zero_64_bytes that should also be updated to L_fill_64_bytes.

Comment thread src/hotspot/cpu/x86/x86.ad Outdated
$$emit$$"# L_loop:\t# 64-byte LOOP\n\t"
$$emit$$"vmovdqu ymm0,(rax)\n\t"
$$emit$$"vmovdqu ymm0,0x20(rax)\n\t"
$$emit$$"vmovdqu $tmp,(rax)\n\t"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are some other hardcoded uses of ymm0, for example in rep_stos_evex(). Do they also need to be updated to $tmp?

@TobiHartmann

Copy link
Copy Markdown
Member Author

Thanks for your thorough review Christian! I did another pass over all the affected code. I renamed "zero" and "clear" to "fill" where appropriate, replaced hardcoded registers in the opto assembly printing by the correct placeholders and also fixed some of the other comments. Your comments should be all addressed now.

@chhagedorn chhagedorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks for the update!

@TobiHartmann

Copy link
Copy Markdown
Member Author

Thanks for the review Christian!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants