8355667: RISC-V: Add backend implementation for unsigned vector Min / Max operations

Reviewed-by: mli, gcao
This commit is contained in:
Fei Yang 2025-04-29 13:41:04 +00:00
parent 9f42ff8960
commit 2ed7ad4b5c
3 changed files with 95 additions and 35 deletions

View File

@ -1409,6 +1409,66 @@ instruct vmin_masked(vReg dst_src1, vReg src2, vRegMask_V0 v0) %{
ins_pipe(pipe_slow);
%}
// vector unsigned integer max/min
instruct vmaxu(vReg dst, vReg src1, vReg src2) %{
match(Set dst (UMaxV src1 src2));
ins_cost(VEC_COST);
format %{ "vmaxu $dst, $src1, $src2" %}
ins_encode %{
BasicType bt = Matcher::vector_element_basic_type(this);
assert(is_integral_type(bt), "unsupported type");
__ vsetvli_helper(bt, Matcher::vector_length(this));
__ vmaxu_vv(as_VectorRegister($dst$$reg),
as_VectorRegister($src1$$reg), as_VectorRegister($src2$$reg));
%}
ins_pipe(pipe_slow);
%}
instruct vminu(vReg dst, vReg src1, vReg src2) %{
match(Set dst (UMinV src1 src2));
ins_cost(VEC_COST);
format %{ "vminu $dst, $src1, $src2" %}
ins_encode %{
BasicType bt = Matcher::vector_element_basic_type(this);
assert(is_integral_type(bt), "unsupported type");
__ vsetvli_helper(bt, Matcher::vector_length(this));
__ vminu_vv(as_VectorRegister($dst$$reg),
as_VectorRegister($src1$$reg), as_VectorRegister($src2$$reg));
%}
ins_pipe(pipe_slow);
%}
// vector unsigned integer max/min - predicated
instruct vmaxu_masked(vReg dst_src1, vReg src2, vRegMask_V0 v0) %{
match(Set dst_src1 (UMaxV (Binary dst_src1 src2) v0));
ins_cost(VEC_COST);
format %{ "vmaxu_masked $dst_src1, $dst_src1, $src2, $v0" %}
ins_encode %{
BasicType bt = Matcher::vector_element_basic_type(this);
assert(is_integral_type(bt), "unsupported type");
__ vsetvli_helper(bt, Matcher::vector_length(this));
__ vmaxu_vv(as_VectorRegister($dst_src1$$reg), as_VectorRegister($dst_src1$$reg),
as_VectorRegister($src2$$reg), Assembler::v0_t);
%}
ins_pipe(pipe_slow);
%}
instruct vminu_masked(vReg dst_src1, vReg src2, vRegMask_V0 v0) %{
match(Set dst_src1 (UMinV (Binary dst_src1 src2) v0));
ins_cost(VEC_COST);
format %{ "vminu_masked $dst_src1, $dst_src1, $src2, $v0" %}
ins_encode %{
BasicType bt = Matcher::vector_element_basic_type(this);
assert(is_integral_type(bt), "unsupported type");
__ vsetvli_helper(bt, Matcher::vector_length(this));
__ vminu_vv(as_VectorRegister($dst_src1$$reg), as_VectorRegister($dst_src1$$reg),
as_VectorRegister($src2$$reg), Assembler::v0_t);
%}
ins_pipe(pipe_slow);
%}
// vector float-point max/min
instruct vmax_fp(vReg dst, vReg src1, vReg src2, vRegMask_V0 v0) %{

View File

@ -76,7 +76,7 @@ public class VectorCommutativeOperSharingTest {
IRNode.MUL_VI, IRNode.VECTOR_SIZE_ANY, " 2 ",
IRNode.MAX_VI, IRNode.VECTOR_SIZE_ANY, " 2 ",
IRNode.MIN_VI, IRNode.VECTOR_SIZE_ANY, " 2 "},
applyIfCPUFeature = {"avx", "true"})
applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing1(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -115,7 +115,7 @@ public class VectorCommutativeOperSharingTest {
@IR(counts = {IRNode.XOR_VI, IRNode.VECTOR_SIZE_ANY, " 0 ",
IRNode.OR_VI, IRNode.VECTOR_SIZE_ANY, " 1 ",
IRNode.AND_VI, IRNode.VECTOR_SIZE_ANY, " 1 "},
applyIfCPUFeature = {"avx", "true"})
applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing2(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -172,7 +172,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing4(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -197,7 +197,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing5(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -222,7 +222,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing6(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -247,7 +247,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing7(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -272,7 +272,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing8(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -297,7 +297,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing9(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -322,7 +322,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing10(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -347,7 +347,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing11(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -372,7 +372,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing12(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -397,7 +397,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing13(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -422,7 +422,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 2 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing14(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -447,7 +447,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing15(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -472,7 +472,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing16(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -497,7 +497,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing17(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -522,7 +522,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing18(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -547,7 +547,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx512vl", "true", "sve", "true"})
@IR(counts = {IRNode.ADD_VI, IRNode.VECTOR_SIZE_ANY, " 3 "}, applyIfCPUFeatureOr = {"avx512vl", "true", "sve", "true", "rvv", "true"})
public void testVectorIRSharing19(int index) {
VectorMask<Integer> VMASK = VectorMask.fromLong(I_SPECIES, ((1 << 4) - 1));
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
@ -575,7 +575,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.UMAX_VI, IRNode.VECTOR_SIZE_ANY, " 1 "}, applyIfCPUFeatureOr = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VI, IRNode.VECTOR_SIZE_ANY, " 1 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing20(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);
@ -600,7 +600,7 @@ public class VectorCommutativeOperSharingTest {
}
@Test
@IR(counts = {IRNode.UMIN_VI, IRNode.VECTOR_SIZE_ANY, " 1 "}, applyIfCPUFeatureOr = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VI, IRNode.VECTOR_SIZE_ANY, " 1 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
public void testVectorIRSharing21(int index) {
IntVector vec1 = IntVector.fromArray(I_SPECIES, ia, index);
IntVector vec2 = IntVector.fromArray(I_SPECIES, ib, index);

View File

@ -105,7 +105,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMAX_VB, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VB, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umax_byte() {
for (int i = 0; i < COUNT; i += bspec.length()) {
@ -128,7 +128,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMAX_VS, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VS, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umax_short() {
for (int i = 0; i < COUNT; i += sspec.length()) {
@ -151,7 +151,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMAX_VI, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VI, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umax_int() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -174,7 +174,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMAX_VL, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VL, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umax_long() {
for (int i = 0; i < COUNT; i += lspec.length()) {
@ -197,7 +197,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VB, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VB, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_byte() {
for (int i = 0; i < COUNT; i += bspec.length()) {
@ -220,7 +220,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VS, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VS, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_short() {
for (int i = 0; i < COUNT; i += sspec.length()) {
@ -243,7 +243,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VI, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VI, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_int() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -266,7 +266,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VL, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VL, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_long() {
for (int i = 0; i < COUNT; i += lspec.length()) {
@ -289,7 +289,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VI, " 0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VI, " 0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_ir_transform1() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -312,7 +312,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMAX_VI, " 0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VI, " 0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umax_ir_transform1() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -335,7 +335,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMAX_VI, " 0 ", IRNode.UMIN_VI, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VI, " 0 ", IRNode.UMIN_VI, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_max_ir_transform1() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -362,7 +362,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VI, " 0 ", IRNode.UMAX_VI, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VI, " 0 ", IRNode.UMAX_VI, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_max_ir_transform2() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -389,7 +389,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMAX_VI, " 0 ", IRNode.UMIN_VI, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMAX_VI, " 0 ", IRNode.UMIN_VI, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_max_ir_transform3() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -416,7 +416,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VI, " 0 ", IRNode.UMAX_VI, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VI, " 0 ", IRNode.UMAX_VI, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_max_ir_transform4() {
for (int i = 0; i < COUNT; i += ispec.length()) {
@ -443,7 +443,7 @@ public class VectorUnsignedMinMaxOperationsTest {
}
@Test
@IR(counts = {IRNode.UMIN_VI, " 0 ", IRNode.UMAX_VI, " >0 "}, applyIfCPUFeature = {"avx", "true"})
@IR(counts = {IRNode.UMIN_VI, " 0 ", IRNode.UMAX_VI, " >0 "}, applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
@Warmup(value = 10000)
public void umin_max_ir_transform5() {
for (int i = 0; i < COUNT; i += ispec.length()) {