RFR: 8308277: RISC-V: Improve vectorization of Match.sqrt() on float

Feilong Jiang fjiang at openjdk.org
Wed May 17 11:09:56 UTC 2023


[JDK-8190800](https://bugs.openjdk.org/browse/JDK-8190800) added `VSqrtF` and `SqrtF` nodes to support the vectorization of Match.sqrt() on floats. For riscv port, however, the scalar version of `sqrtF` still uses the old match rule that converts Float to Double first. It can be simplified to just use `SqrtF`.

The old match rule also affects the vectorization of Math.sqrt() on float. The current implementation will convert float to double with `vcvtFtoD`, then do `vsqrtD`, and finally convert the result back to float with `vcvtDtoF`. If we use the new `SqrtF` match rule, it will only use `vsqrtF` to do the conversion. Take the test (Sqrt.java) from [JDK-8190800](https://bugs.openjdk.org/browse/JDK-8190800) as an example, here is the output with `-XX:+PrintOptoAssembly` and `-XX:+UseRVV`:

before:


19a loadV V1, [R13] # vector (rvv)
1a2 vcvtFtoD V2, V1
1ae vfsqrt.v V1, V2 #@vsqrtD
1b6 vcvtDtoF V1, V1
1c2 storeV [R14], V1 # vector (rvv)


after:

1be loadV V1, [R12] # vector (rvv)
1c6 vfsqrt.v V1, V1 #@vsqrtF
1ce addi R12, R29, #144 # ptr, #@addP_reg_imm
1d2 storeV [R12], V1 # vector (rvv)

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

Commit messages:
 - RISC-V: Math.sqrt() does not vectroized on floats

Changes: https://git.openjdk.org/jdk/pull/14029/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14029&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8308277
  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/14029.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14029/head:pull/14029

PR: https://git.openjdk.org/jdk/pull/14029


More information about the hotspot-compiler-dev mailing list