From 06598543496c4072cab89d700ca687171c032141 Mon Sep 17 00:00:00 2001 From: Dingli Zhang Date: Thu, 10 Jul 2025 17:16:15 +0800 Subject: [PATCH 1/4] 8361836: RISC-V: Relax min vector length to 32-bit for short vectors --- src/hotspot/cpu/riscv/riscv.ad | 3 +++ .../vectorapi/reshape/utils/TestCastMethods.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/hotspot/cpu/riscv/riscv.ad b/src/hotspot/cpu/riscv/riscv.ad index 9adcc1d9c5a9f..5648472ea37f6 100644 --- a/src/hotspot/cpu/riscv/riscv.ad +++ b/src/hotspot/cpu/riscv/riscv.ad @@ -1994,6 +1994,9 @@ int Matcher::min_vector_size(const BasicType bt) { } else if (bt == T_BOOLEAN) { // To support vector api load/store mask. size = 2; + // To support vector type conversions between short and wider types. + } else if (bt == T_SHORT) { + size = 2; } if (size < 2) size = 2; return MIN2(size, max_size); diff --git a/test/hotspot/jtreg/compiler/vectorapi/reshape/utils/TestCastMethods.java b/test/hotspot/jtreg/compiler/vectorapi/reshape/utils/TestCastMethods.java index 6cdd3754c09e2..fac829c82e4dd 100644 --- a/test/hotspot/jtreg/compiler/vectorapi/reshape/utils/TestCastMethods.java +++ b/test/hotspot/jtreg/compiler/vectorapi/reshape/utils/TestCastMethods.java @@ -127,11 +127,17 @@ public class TestCastMethods { // from S 64 // to X 64 makePair(SSPEC64, BSPEC64), + makePair(SSPEC64, ISPEC64), + makePair(SSPEC64, ISPEC64, true), + makePair(SSPEC64, FSPEC64), // to X 128 makePair(SSPEC64, BSPEC128), makePair(SSPEC64, ISPEC128), makePair(SSPEC64, ISPEC128, true), + makePair(SSPEC64, LSPEC128), + makePair(SSPEC64, LSPEC128, true), makePair(SSPEC64, FSPEC128), + makePair(SSPEC64, DSPEC128), // to X 256 makePair(SSPEC64, BSPEC256), makePair(SSPEC64, ISPEC256), @@ -156,7 +162,10 @@ public class TestCastMethods { makePair(SSPEC128, BSPEC128), makePair(SSPEC128, ISPEC128), makePair(SSPEC128, ISPEC128, true), + makePair(SSPEC128, LSPEC128), + makePair(SSPEC128, LSPEC128, true), makePair(SSPEC128, FSPEC128), + makePair(SSPEC128, DSPEC128), // to X 256 makePair(SSPEC128, BSPEC256), makePair(SSPEC128, ISPEC256), @@ -228,6 +237,7 @@ public class TestCastMethods { // ====== from I ====== // from I 64 // to X 64 + makePair(ISPEC64, SSPEC64), makePair(ISPEC64, FSPEC64), // to X 128 makePair(ISPEC64, LSPEC128), @@ -299,10 +309,12 @@ public class TestCastMethods { // ====== from L ====== // from L 128 // to X 64 + makePair(LSPEC128, SSPEC64), makePair(LSPEC128, ISPEC64), makePair(LSPEC128, FSPEC64), makePair(LSPEC128, DSPEC64), // to X 128 + makePair(LSPEC128, SSPEC128), makePair(LSPEC128, ISPEC128), makePair(LSPEC128, FSPEC128), makePair(LSPEC128, DSPEC128), @@ -369,6 +381,7 @@ public class TestCastMethods { // ====== from F ====== // from F 64 // to X 64 + makePair(FSPEC64, SSPEC64), makePair(FSPEC64, ISPEC64), // to X 128 makePair(FSPEC64, ISPEC128), @@ -433,10 +446,12 @@ public class TestCastMethods { // ====== from D ====== // from D 128 // to X 64 + makePair(DSPEC128, SSPEC64), makePair(DSPEC128, ISPEC64), makePair(DSPEC128, LSPEC64), makePair(DSPEC128, FSPEC64), // to X 128 + makePair(DSPEC128, SSPEC128), makePair(DSPEC128, ISPEC128), makePair(DSPEC128, LSPEC128), makePair(DSPEC128, FSPEC128), From 0773a3668caad98e46978d1bd899f6ca5faad206 Mon Sep 17 00:00:00 2001 From: Dingli Zhang Date: Thu, 10 Jul 2025 17:23:10 +0800 Subject: [PATCH 2/4] Adjust the position of comment --- src/hotspot/cpu/riscv/riscv.ad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/cpu/riscv/riscv.ad b/src/hotspot/cpu/riscv/riscv.ad index 5648472ea37f6..0c8268111e982 100644 --- a/src/hotspot/cpu/riscv/riscv.ad +++ b/src/hotspot/cpu/riscv/riscv.ad @@ -1994,8 +1994,8 @@ int Matcher::min_vector_size(const BasicType bt) { } else if (bt == T_BOOLEAN) { // To support vector api load/store mask. size = 2; - // To support vector type conversions between short and wider types. } else if (bt == T_SHORT) { + // To support vector type conversions between short and wider types. size = 2; } if (size < 2) size = 2; From 84d6b25fb5f9d0f4854eb80bb152c8ce18a674a4 Mon Sep 17 00:00:00 2001 From: Dingli Zhang Date: Tue, 15 Jul 2025 11:57:51 +0800 Subject: [PATCH 3/4] Use switch-case in min_vector_size --- src/hotspot/cpu/riscv/riscv.ad | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/hotspot/cpu/riscv/riscv.ad b/src/hotspot/cpu/riscv/riscv.ad index 0c8268111e982..0d97c95687a79 100644 --- a/src/hotspot/cpu/riscv/riscv.ad +++ b/src/hotspot/cpu/riscv/riscv.ad @@ -1985,20 +1985,28 @@ int Matcher::max_vector_size(const BasicType bt) { } int Matcher::min_vector_size(const BasicType bt) { - int max_size = max_vector_size(bt); - // Limit the min vector size to 8 bytes. - int size = 8 / type2aelembytes(bt); - if (bt == T_BYTE) { - // To support vector api shuffle/rearrange. - size = 4; - } else if (bt == T_BOOLEAN) { - // To support vector api load/store mask. - size = 2; - } else if (bt == T_SHORT) { - // To support vector type conversions between short and wider types. - size = 2; + int size; + switch(bt) { + case T_BOOLEAN: + // To support vector api load/store mask. + size = 2; + break; + case T_BYTE: + // To support vector api shuffle/rearrange. + size = 4; + break; + case T_SHORT: + // To support vector type conversions between short and wider types. + size = 2; + break; + default: + // Limit the min vector length to 64-bit. + size = 8 / type2aelembytes(bt); + // The number of elements in a vector should be at least 2. + size = MAX2(size, 2); } - if (size < 2) size = 2; + + int max_size = max_vector_size(bt); return MIN2(size, max_size); } From 7120525bbbe39467fdf57eac5a2de7e8eb92d072 Mon Sep 17 00:00:00 2001 From: Dingli Zhang Date: Tue, 15 Jul 2025 18:24:18 +0800 Subject: [PATCH 4/4] Update comments --- src/hotspot/cpu/riscv/riscv.ad | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hotspot/cpu/riscv/riscv.ad b/src/hotspot/cpu/riscv/riscv.ad index 0d97c95687a79..cc59af8fae1b5 100644 --- a/src/hotspot/cpu/riscv/riscv.ad +++ b/src/hotspot/cpu/riscv/riscv.ad @@ -1988,15 +1988,18 @@ int Matcher::min_vector_size(const BasicType bt) { int size; switch(bt) { case T_BOOLEAN: - // To support vector api load/store mask. + // Load/store a vector mask with only 2 elements for vector types + // such as "2I/2F/2L/2D". size = 2; break; case T_BYTE: - // To support vector api shuffle/rearrange. + // Generate a "4B" vector, to support vector cast between "8B/16B" + // and "4S/4I/4L/4F/4D". size = 4; break; case T_SHORT: - // To support vector type conversions between short and wider types. + // Generate a "2S" vector, to support vector cast between "4S/8S" + // and "2I/2L/2F/2D". size = 2; break; default: