diff --git a/src/hotspot/cpu/riscv/riscv.ad b/src/hotspot/cpu/riscv/riscv.ad index 9adcc1d9c5a9f..cc59af8fae1b5 100644 --- a/src/hotspot/cpu/riscv/riscv.ad +++ b/src/hotspot/cpu/riscv/riscv.ad @@ -1985,17 +1985,31 @@ 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; + int size; + switch(bt) { + case T_BOOLEAN: + // Load/store a vector mask with only 2 elements for vector types + // such as "2I/2F/2L/2D". + size = 2; + break; + case T_BYTE: + // Generate a "4B" vector, to support vector cast between "8B/16B" + // and "4S/4I/4L/4F/4D". + size = 4; + break; + case T_SHORT: + // Generate a "2S" vector, to support vector cast between "4S/8S" + // and "2I/2L/2F/2D". + 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); } 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),