Skip to content

8389108: RISC-V: C2: Optimize identity hash mask extraction with shift pair - #32046

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

8389108: RISC-V: C2: Optimize identity hash mask extraction with shift pair#32046
zifeihan wants to merge 1 commit into
openjdk:masterfrom
zifeihan:JDK-8389108

Conversation

@zifeihan

@zifeihan zifeihan commented Jul 25, 2026

Copy link
Copy Markdown
Member

Hi, please consider that.
On RISC-V, extracting the 31-bit identity hash from the mark word requires an AND with hash_mask (0x7FFFFFFF). The generic path loads this constant into a register and then performs a register-register AND:
opto log without this patch:

0b4     B5: #	out( B36 B6 ) <- in( B4 )  Freq: 0.404595
0b4 +   ld  R7, [R11]	# int, #@loadL
0b8 +   srli  R7, R7, (#11 & 0x3f)	#@urShiftL_reg_imm
0bc +   mv R29, #2147483647	# int, #@loadConI
0c2 +   addw  R7, R7, zr	#@convL2I_reg
0c4 +   andr  R10, R7, R29	#@andI_reg_reg

assembly log without this patch:

 ;; B5: #	out( B36 B6 ) <- in( B4 )  Freq: 0.404595
  0x00007fff84c8c5b4:   ld	t2,0(a1)
  0x00007fff84c8c5b8:   srli	t2,t2,0xb
  0x00007fff84c8c5bc:   lui	t4,0x80000
  0x00007fff84c8c5c0:   addiw	t4,t4,-1 # 0x000000007fffffff
  0x00007fff84c8c5c2:   sext.w	t2,t2
  0x00007fff84c8c5c4:   and	a0,t2,t4

This patch adds a specialized AD rule andI_31bits that uses a shift pair (slli 33 + srli 33) to clear the upper 33 bits, replacing the constant load and AND. Using iRegIorL2I as the source operand also subsumes the preceding ConvL2I, eliminating the addw.

opto log witch this patch:

0b2     B5: #	out( B36 B6 ) <- in( B4 )  Freq: 0.404595
0b2 +   ld  R7, [R13]	# int, #@loadL
0b6 +   srli  R7, R7, (#11 & 0x3f)	#@urShiftL_reg_imm
0ba +   slli  R10, l2i(R7), 33
	srli  R10, R10, 33	#@andI_31bits

assembly log with this patch:

 ;; B5: #	out( B36 B6 ) <- in( B4 )  Freq: 0.404595
  0x00007fff9908c5b2:   ld	t2,0(a3)
  0x00007fff9908c5b6:   srli	t2,t2,0xb
  0x00007fff9908c5ba:   slli	a0,t2,0x21
  0x00007fff9908c5be:   srli	a0,a0,0x21

Testing

  • Run tier1-tier3 test with release on SG2044

Performance Test:

specjbb2015 without this patch on SG2044:

RUN RESULT: hbIR (max attempted) = 16584, hbIR (settled) = 13837, max-jOPS = 12604, critical-jOPS = 1554

specjbb2015 witch this patch on SG2044:

RUN RESULT: hbIR (max attempted) = 16584, hbIR (settled) = 13837, max-jOPS = 18740, critical-jOPS = 1680


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-8389108: RISC-V: C2: Optimize identity hash mask extraction with shift pair (Enhancement - P4)

Contributors

  • Dingli Zhang <dzhang@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 32046

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@zifeihan

Copy link
Copy Markdown
Member Author

/contributor add @DingliZhang

@bridgekeeper

bridgekeeper Bot commented Jul 25, 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 25, 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 25, 2026

Copy link
Copy Markdown

@zifeihan
Contributor Dingli Zhang <dzhang@openjdk.org> successfully added.

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

openjdk Bot commented Jul 25, 2026

Copy link
Copy Markdown

@zifeihan 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 commented Jul 25, 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-compiler. This can be overridden with the /reviewers command.

@zifeihan zifeihan changed the title RISC-V: C2: Optimize identity hash mask extraction with shift pair 8389108: RISC-V: C2: Optimize identity hash mask extraction with shift pair Jul 25, 2026
@openjdk openjdk Bot added the rfr Pull request is ready for review label Jul 25, 2026
@mlbridge

mlbridge Bot commented Jul 25, 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-compiler hotspot-compiler-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant