Skip to content

8388926: RISC-V: Skip redundant zext.w in set_narrow_klass when bit 31 is clear#32038

Open
zifeihan wants to merge 1 commit into
openjdk:masterfrom
zifeihan:JDK-8388926
Open

8388926: RISC-V: Skip redundant zext.w in set_narrow_klass when bit 31 is clear#32038
zifeihan wants to merge 1 commit into
openjdk:masterfrom
zifeihan:JDK-8388926

Conversation

@zifeihan

@zifeihan zifeihan commented Jul 24, 2026

Copy link
Copy Markdown
Member

Hi, please consider.
MacroAssembler::set_narrow_klass uses li32 (lui + addiw) to materialize a narrow klass constant into a register. Since addiw sign-extends the 32-bit result to 64 bits, the function previously emitted a zext.w unconditionally to clear the upper 32 bits. However, sign extension only corrupts the upper bits when bit 31 of the narrow klass value is set (i.e., (int32_t)nk < 0). When bit 31 is clear, addiw naturally produces a correctly zero-extended result, making zext.w redundant.

Correctness Testing

  • Run tier1-tier3 test with release on SG2044

Assembly log verification

The command to print the Assembly log is as follows:
./java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:CompileCommand=compileonly,java.util.HashMap::putVal -version > assembly.log
We can observe that after the optimization, the instruction .insn 4, 0x080888bb has been successfully eliminated, this is a Zba extension instruction. After decoding, it is add.uw a7, a7, zero, which is equivalent to zext.w a7, a7

without this patch:

Compiled method (c2) 775   22             java.util.HashMap::putVal (300 bytes)
...
  0x0000003f8d09409e:   addiw	s2,zero,981
  0x0000003f8d0940a2:   slli	s2,s2,0x2a
  0x0000003f8d0940a4:   addi	s2,s2,1
  0x0000003f8d0940a6:   lui	a7,0x0                      ;   {metadata('java/util/LinkedHashMap')}
  0x0000003f8d0940aa:   addiw	a7,a7,2034 # 0x00000000000007f2
  0x0000003f8d0940ae:   .insn	4, 0x080888bb
  0x0000003f8d0940b2:   slli	a4,t2,0x3                   ;*aaload {reexecute=0 rethrow=0 return_oop=0}
                                                            ; - java.util.HashMap::putVal@40 (line 662)
  0x0000003f8d0940b6:   lui	a5,0x0                      ;   {metadata('java/util/HashMap')}
  0x0000003f8d0940ba:   addiw	a5,a5,973 # 0x00000000000003cd
  0x0000003f8d0940be:   .insn	4, 0x080787bb
  0x0000003f8d0940c2:   ld	t3,8(sp)
  0x0000003f8d0940c4:   addiw	s3,zero,985
  0x0000003f8d0940c8:   slli	s3,s3,0x2a
  0x0000003f8d0940ca:   addi	s3,s3,1
  0x0000003f8d0940cc:   ld	a2,16(sp)
  0x0000003f8d0940ce:   li	t4,1
  0x0000003f8d0940d0:   srli	a1,t3,0x3                   ;*putfield key {reexecute=0 rethrow=0 return_oop=0}

with this patch:

Compiled method (c2) 775   22             java.util.HashMap::putVal (300 bytes)
...
  0x0000003fa1093e1e:   addiw	s2,zero,981
  0x0000003fa1093e22:   slli	s2,s2,0x2a
  0x0000003fa1093e24:   addi	s2,s2,1
  0x0000003fa1093e26:   lui	a7,0x0                      ;   {metadata('java/util/LinkedHashMap')}
  0x0000003fa1093e2a:   addiw	a7,a7,2034 # 0x00000000000007f2
  0x0000003fa1093e2e:   slli	a4,t2,0x3                   ;*aaload {reexecute=0 rethrow=0 return_oop=0}
                                                            ; - java.util.HashMap::putVal@40 (line 662)
  0x0000003fa1093e32:   lui	a5,0x0                      ;   {metadata('java/util/HashMap')}
  0x0000003fa1093e36:   addiw	a5,a5,973 # 0x00000000000003cd
  0x0000003fa1093e3a:   ld	t3,8(sp)
  0x0000003fa1093e3c:   addiw	s3,zero,985
  0x0000003fa1093e40:   slli	s3,s3,0x2a
  0x0000003fa1093e42:   addi	s3,s3,1
  0x0000003fa1093e44:   ld	a2,16(sp)
  0x0000003fa1093e46:   li	t4,1
  0x0000003fa1093e48:   srli	a1,t3,0x3                   ;*putfield key {reexecute=0 rethrow=0 return_oop=0}

Performance Test:

specjbb2015 without this patch:

RUN RESULT: hbIR (max attempted) = 4579, hbIR (settled) = 4365, max-jOPS = 4350, critical-jOPS = 1129

specjbb2015 witch this patch:

RUN RESULT: hbIR (max attempted) = 4187, hbIR (settled) = 4038, max-jOPS = 4396, critical-jOPS = 1170


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-8388926: RISC-V: Skip redundant zext.w in set_narrow_klass when bit 31 is clear (Enhancement - P4)

Contributors

  • gns <wangbingzhen.riscv@isrc.iscas.ac.cn>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 32038

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@zifeihan

Copy link
Copy Markdown
Member Author

/contributor add gns wangbingzhen.riscv@isrc.iscas.ac.cn

@bridgekeeper

bridgekeeper Bot commented Jul 24, 2026

Copy link
Copy Markdown

👋 Welcome back gcao! 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 commented Jul 24, 2026

Copy link
Copy Markdown

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

@openjdk

openjdk Bot commented Jul 24, 2026

Copy link
Copy Markdown

@zifeihan
Contributor gns <wangbingzhen.riscv@isrc.iscas.ac.cn> successfully added.

@openjdk openjdk Bot added the hotspot hotspot-dev@openjdk.org label Jul 24, 2026
@openjdk

openjdk Bot commented Jul 24, 2026

Copy link
Copy Markdown

@zifeihan The following label will be automatically applied to this pull request:

  • hotspot

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 commented Jul 24, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot. This can be overridden with the /reviewers command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Jul 24, 2026
@mlbridge

mlbridge Bot commented Jul 24, 2026

Copy link
Copy Markdown

Webrevs

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

Labels

hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant