RFR: 8376167: RISC-V: Fix redundant zext.w in macroAssembler_riscv.cpp

Fei Yang fyang at openjdk.org
Thu Feb 12 08:47:42 UTC 2026


On Thu, 12 Feb 2026 03:10:22 GMT, pure <duke at openjdk.org> wrote:

> The RISC-V addiw instruction includes built-in sign extension. When the 32-bit immediate value is 0, no sign extension is needed. The current JIT assembler generates a redundant zext.w instruction.
> 
> 0x0000002aac9e9ce8:   lui     t3,0x95010                  ; {metadata('java/lang/Long')}
> 0x0000002aac9e9cec:   addiw   t3,t3,-1136
> 0x0000002aac9e9cf0:   zext.w  t3,t3
> 0x0000002aac9e9cf4:   beq     t2,t3,0x0000002aac9e9cfc
> 
> So, in macroAssembler_riscv.cpp source code, we can add the additional judgment to avoid the zext instruction

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp line 5349:

> 5347: 
> 5348:   relocate(metadata_Relocation::spec(index), [&] {
> 5349:     li32(dst, nk);

I see this `li32` is with a `metadata_Relocation`. Did you check the new value of `nk` after code patching?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/29683#discussion_r2797518103


More information about the hotspot-dev mailing list