Integrated: 8297715: RISC-V: C2: Use single-bit instructions from the Zbs extension
Fei Yang
fyang at openjdk.org
Fri Dec 2 08:29:34 UTC 2022
On Tue, 29 Nov 2022 03:35:12 GMT, Fei Yang <fyang at openjdk.org> wrote:
> The single-bit instructions from the Zbs extension provide a mechanism to set, clear,
> invert, or extract a single bit in a register. The bit is specified by its index.
>
> Especially, the single-bit extract (immediate) instruction 'bexti rd, rs1, shamt' [1] performs:
>
> let index = shamt & (XLEN - 1);
> X(rd) = (X(rs1) >> index) & 1;
>
>
> This instruction is a perfect match for following C2 sub-graph when integer immediate 'mask' is power of 2:
>
> Set dst (Conv2B (AndI src mask))
>
>
> The effect is that we could then optimize C2 JIT code for methods like [2]:
> Before:
>
> lhu R28, [R11, #12] # short, #@loadUS ! Field: com/sun/org/apache/xerces/internal/dom/NodeImpl.flags
> andi R7, R28, #8 #@andI_reg_imm
> snez R10, R7 #@convI2Bool
>
>
> After:
>
> lhu R28, [R11, #12] # short, #@loadUS ! Field: com/sun/org/apache/xerces/internal/dom/NodeImpl.flags
> bexti R10, R28, 3 #
>
> Note that I am not adding a matching rule for long->bool case as I see C2 compiler currently only catches and builds int->bool conversions [3]. I guess there might be no such use cases for long->bool conversion in the real-world.
>
> Testing: Tier1-3 hotspot & jdk tested with QEMU (JTREG="VM_OPTIONS=-XX:+UnlockExperimentalVMOptions -XX:+UseZbs").
>
> [1] https://github.com/riscv/riscv-bitmanip/blob/main/bitmanip/insns/bexti.adoc
>
> [2] https://github.com/openjdk/jdk/blob/master/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/NodeImpl.java#L1936
>
> [3] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/cfgnode.cpp#L1435
This pull request has now been integrated.
Changeset: d50015af
Author: Fei Yang <fyang at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/d50015af99f44909bf71fd2de97546d47cda86d6
Stats: 26 lines in 4 files changed: 24 ins; 0 del; 2 mod
8297715: RISC-V: C2: Use single-bit instructions from the Zbs extension
Reviewed-by: fjiang, yadongwang, shade
-------------
PR: https://git.openjdk.org/jdk/pull/11406
More information about the hotspot-compiler-dev
mailing list