RFR: 8308817: RISC-V: Support VectorTest node for Vector API
Gui Cao
gcao at openjdk.org
Thu May 25 03:29:50 UTC 2023
Hi,
we have added VectorTest node, It was implemented by referring to RVV v1.0 [1]. please take a look and have some reviews. Thanks a lot.
We can use the Int256VectorTests.java[2] to print the compilation log, verify and observe the generation of nodes.
For example, we can use the following command to print the compilation log of a jtreg test case:
/home/zifeihan/jdk-tools/jtreg/bin/jtreg \
-v:default \
-concurrency:16 -timeout:50 \
-javaoption:-XX:+UnlockExperimentalVMOptions \
-javaoption:-XX:+UseRVV \
-javaoption:-XX:+PrintOptoAssembly \
-javaoption:-XX:LogFile=/home/zifeihan/jdk-rvv/Int256VectorTests_PrintOptoAssembly_20230525.log \
-jdk:/home/zifeihan/jdk-rvv/build/linux-riscv64-server-fastdebug/jdk \
-compilejdk:/home/zifeihan/jdk-rvv/build/linux-x86_64-server-release/images/jdk \
/home/zifeihan/jdk/test/jdk/jdk/incubator/vector/Int256VectorTests.java
Also here's a more concise test case, VectorTestDemo:
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.VectorMask;
public class VectorTestDemo {
static boolean[] d = new boolean[]{true, false, false, false, false, false, false, false};
static VectorMask<Byte> avmask = VectorMask.fromArray(ByteVector.SPECIES_64, d, 0);
public static void main(String[] args) {
for (int i = 0; i < 300000; i++) {
final boolean alltrue = alltrue();
if (alltrue != false) {
throw new RuntimeException("alltrue");
}
final boolean anytrue = anytrue();
if (anytrue != true) {
throw new RuntimeException("anytrue");
}
}
}
public static boolean anytrue() {
return avmask.anyTrue();
}
public static boolean alltrue() {
return avmask.allTrue();
}
}
We can compile `VectorTestDemo.java` using `javac --add-modules jdk.incubator.vector VectorTestDemo.java`, and use `./java -XX:-TieredCompilation -XX:+UnlockExperimentalVMOptions -XX:+UseRVV -XX:+PrintOptoAssembly -XX:+LogCompilation -XX:LogFile=compile.log VectorTestDemo > aaa.log` to start the test case, we can observe the specified compilation log `compile.log`, which contains the VectorTest node for the PR implementation.
Some of the compilation logs of VectorTestDemo#anytrue method are as follows.
05e lwu R28, [R7, #12] # loadN, compressed ptr, #@loadN ! Field: jdk/internal/vm/vector/VectorSupport$VectorPayload.payload (constant)
062 decode_heap_oop R7, R28 #@decodeHeapOop
066 addi R7, R7, #16 # ptr, #@addP_reg_imm
068 loadV V1, [R7] # vector (rvv)
070 vloadmask V0, V1
078 CMove R10, (vectortest eq V0 V0), zero, one #@cmovI_vtest_anytrue_negate
Some of the compilation logs of the VectorTestDemo#alltrue method are as follows.
05e lwu R28, [R7, #12] # loadN, compressed ptr, #@loadN ! Field: jdk/internal/vm/vector/VectorSupport$VectorPayload.payload (constant)
062 decode_heap_oop R7, R28 #@decodeHeapOop
066 addi R7, R7, #16 # ptr, #@addP_reg_imm
068 loadV V1, [R7] # vector (rvv)
070 vloadmask V0, V1
078 CMove R10, (vectortest ne V0 V0), zero, one #@cmovI_vtest_alltrue_negate
Some of the compilation logs of VectorTest#main method are as follows.
0b2 decode_heap_oop R7, R7 #@decodeHeapOop
0b4 addi R7, R7, #16 # ptr, #@addP_reg_imm
0b6 loadV V1, [R7] # vector (rvv)
0be vloadmask V0, V1
0c6 CMove R28, (vectortest eq V0 V0), zero, one #@cmovI_vtest_anytrue_negate
0d2 beq (vectortest overflow V0, V0) B8 #@vtest_alltrue_branch P=0.000001 C=-1.000000
As comment in the PR in cmovI_vtest_anytrue instruct, cmpOp is negated in CMoveINode::Ideal. So we keep this version for better understanding of the code change.
[1] https://github.com/riscv/riscv-v-spec/blob/v1.0/v-spec.adoc
[2] https://github.com/openjdk/jdk/blob/master/test/jdk/jdk/incubator/vector/Int256VectorTests.java
### Testing:
qemu with UseRVV:
- [ ] Tier1 tests (release)
- [ ] Tier2 tests (release)
- [ ] Tier3 tests (release)
- [x] test/jdk/jdk/incubator/vector (fastdebug)
-------------
Commit messages:
- Support VectorTest node for Vector API
Changes: https://git.openjdk.org/jdk/pull/14138/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14138&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8308817
Stats: 108 lines in 2 files changed: 107 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/14138.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/14138/head:pull/14138
PR: https://git.openjdk.org/jdk/pull/14138
More information about the hotspot-compiler-dev
mailing list