diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -343,6 +343,9 @@ // RVV intrinsics may have illegal operands. for (auto VT : {MVT::i8, MVT::i16, MVT::i32}) setOperationAction(ISD::INTRINSIC_WO_CHAIN, VT, Custom); + + for (auto VT : MVT::integer_scalable_vector_valuetypes()) + setOperationAction(ISD::SPLAT_VECTOR, VT, Legal); } // Function alignments. diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td @@ -365,29 +365,57 @@ //===----------------------------------------------------------------------===// // Helpers to define the different patterns. //===----------------------------------------------------------------------===// -class VPatBinarySDNode : +class VPatBinarySDNode_VV : Pat<(result_type (vop (op_type op_reg_class:$rs1), (op_type op_reg_class:$rs2))), - (!cast(instruction_name#"_VV_"# vlmul.MX) + (!cast(instruction_name#"_VV_"# vlmul.MX) op_reg_class:$rs1, op_reg_class:$rs2, VLMax, sew)>; -multiclass VPatBinarySDNode +class VPatBinarySDNode_XI : + Pat<(result_type (vop + (vop_type vop_reg_class:$rs1), + (vop_type (splat_vector xop_kind:$rs2)))), + (!cast(instruction_name#_#suffix#_# vlmul.MX) + vop_reg_class:$rs1, + xop_kind:$rs2, + VLMax, sew)>; + +multiclass VPatBinarySDNode_VV_VX_VI { - foreach vti = AllIntegerVectors in - def : VPatBinarySDNode; + foreach vti = AllIntegerVectors in { + def : VPatBinarySDNode_VV; + def : VPatBinarySDNode_XI; + def : VPatBinarySDNode_XI; + } } class VPatBinaryNoMask; +defm "" : VPatBinarySDNode_VV_VX_VI; //===----------------------------------------------------------------------===// // 12. Vector Integer Arithmetic Instructions diff --git a/llvm/test/CodeGen/RISCV/rvv/vadd-rv32.ll b/llvm/test/CodeGen/RISCV/rvv/vadd-rv32.ll --- a/llvm/test/CodeGen/RISCV/rvv/vadd-rv32.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vadd-rv32.ll @@ -1943,3 +1943,23 @@ ret %a } + +define @sdnode_vadd_vx_nxv8i8_i8( %va, i8 signext %b) nounwind { +; CHECK-LABEL: sdnode_vadd_vx_nxv8i8_i8 +; CHECK: vsetvli {{.*}}, zero, e8,m1,ta,mu +; CHECK: vadd.vx {{v[0-9]+}}, {{v[0-9]+}}, {{a[0-9]+}} + %head = insertelement undef, i8 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = add %va, %splat + ret %vc +} + +define @sdnode_vadd_vi_nxv8i8_i8( %va) nounwind { +; CHECK-LABEL: sdnode_vadd_vi_nxv8i8_i8 +; CHECK: vsetvli {{.*}}, zero, e8,m1,ta,mu +; CHECK: vadd.vi {{v[0-9]+}}, {{v[0-9]+}}, -1 + %head = insertelement undef, i8 -1, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = add %va, %splat + ret %vc +} diff --git a/llvm/test/CodeGen/RISCV/rvv/vadd-rv64.ll b/llvm/test/CodeGen/RISCV/rvv/vadd-rv64.ll --- a/llvm/test/CodeGen/RISCV/rvv/vadd-rv64.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vadd-rv64.ll @@ -2375,3 +2375,23 @@ ret %a } + +define @sdnode_vadd_vx_nxv8i8_i8( %va, i8 signext %b) nounwind { +; CHECK-LABEL: sdnode_vadd_vx_nxv8i8_i8 +; CHECK: vsetvli {{.*}}, zero, e8,m1,ta,mu +; CHECK: vadd.vx {{v[0-9]+}}, {{v[0-9]+}}, {{a[0-9]+}} + %head = insertelement undef, i8 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = add %va, %splat + ret %vc +} + +define @sdnode_vadd_vi_nxv8i8_i8( %va) nounwind { +; CHECK-LABEL: sdnode_vadd_vi_nxv8i8_i8 +; CHECK: vsetvli {{.*}}, zero, e8,m1,ta,mu +; CHECK: vadd.vi {{v[0-9]+}}, {{v[0-9]+}}, -1 + %head = insertelement undef, i8 -1, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = add %va, %splat + ret %vc +}