[llvm] de2d0f4 - [RISCV][P-ext] Add zero/sign extend support between 32-bit and 64-bit vectors. (#201694)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 19:54:39 PDT 2026


Author: Craig Topper
Date: 2026-06-04T19:54:34-07:00
New Revision: de2d0f48ea2c237f12a046c2b56589b1b0ea22e0

URL: https://github.com/llvm/llvm-project/commit/de2d0f48ea2c237f12a046c2b56589b1b0ea22e0
DIFF: https://github.com/llvm/llvm-project/commit/de2d0f48ea2c237f12a046c2b56589b1b0ea22e0.diff

LOG: [RISCV][P-ext] Add zero/sign extend support between 32-bit and 64-bit vectors. (#201694)

Still need to improve sext on RV64.

Assisted-by: Claude Sonnet 4.6

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp
    llvm/lib/Target/RISCV/RISCVInstrInfoP.td
    llvm/test/CodeGen/RISCV/rvp-simd-32.ll
    llvm/test/CodeGen/RISCV/rvp-simd-64.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 4e2c68f7fe105..d56cb0dd50474 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -653,11 +653,18 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
       setOperationAction({ISD::SELECT, ISD::VSELECT}, {MVT::v4i16, MVT::v8i8},
                          Custom);
       setOperationAction(ISD::MUL, {MVT::v4i16, MVT::v8i8}, Custom);
+      setOperationAction({ISD::SIGN_EXTEND, ISD::ZERO_EXTEND},
+                         {MVT::v4i16, MVT::v2i32}, Legal);
       setOperationAction(ISD::SETCC, P64VecVTs, Legal);
       setCondCodeAction(
           {ISD::SETGE, ISD::SETUGT, ISD::SETUGE, ISD::SETULE, ISD::SETLE},
           P64VecVTs, Expand);
       setCondCodeAction({ISD::SETNE, ISD::SETGT}, P64VecVTs, Custom);
+    } else {
+      setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG,
+                         {MVT::v4i16, MVT::v2i32}, Legal);
+      setOperationAction(ISD::ANY_EXTEND_VECTOR_INREG, {MVT::v4i16, MVT::v2i32},
+                         Custom);
     }
   }
 
@@ -9019,6 +9026,14 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
     }
     return lowerToScalableOp(Op, DAG);
   }
+  case ISD::ANY_EXTEND_VECTOR_INREG: {
+    EVT VT = Op.getValueType();
+    assert(Subtarget.hasStdExtP() && Subtarget.is64Bit() &&
+           (VT == MVT::v2i32 || VT == MVT::v4i16) &&
+           "Unexpected custom legalisation");
+    return DAG.getNode(ISD::ZERO_EXTEND_VECTOR_INREG, SDLoc(Op), VT,
+                       Op.getOperand(0));
+  }
   case ISD::SHL:
   case ISD::SRL:
   case ISD::SRA:

diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfoP.td b/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
index 036aff6975cde..feb52f0c63fff 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
@@ -2162,6 +2162,14 @@ let append Predicates = [IsRV32] in {
   def : LdPat<load, LW, v4i8>;
   def : LdPat<load, LW, v2i16>;
 
+  // Zero-extend patterns using wzip*p with zero
+  def : Pat<(v4i16 (zext (v4i8 GPR:$rs))), (WZIP8P GPR:$rs, (v4i8 X0))>;
+  def : Pat<(v2i32 (zext (v2i16 GPR:$rs))), (WZIP16P GPR:$rs, (v2i16 X0))>;
+
+  // Sign-extend patterns using pwadd with zero
+  def : Pat<(v4i16 (sext (v4i8 GPR:$rs))), (PWADD_B GPR:$rs, (v4i8 X0))>;
+  def : Pat<(v2i32 (sext (v2i16 GPR:$rs))), (PWADD_H GPR:$rs, (v2i16 X0))>;
+
   // Build vector patterns
   def : Pat<(v2i16 (build_vector (XLenVT GPR:$a), (XLenVT GPR:$b))),
             (PACK GPR:$a, GPR:$b)>;
@@ -2538,5 +2546,9 @@ let append Predicates = [IsRV64] in {
 
   def : Pat<(v2i32 (build_vector (XLenVT GPR:$a), (XLenVT GPR:$b))),
             (PACK GPR:$a, GPR:$b)>;
+
+  // Zero-extend patterns using zip*p with zero
+  def : Pat<(v4i16 (zext_invec (v8i8 GPR:$rs))), (ZIP8P GPR:$rs, (v8i8 X0))>;
+  def : Pat<(v2i32 (zext_invec (v4i16 GPR:$rs))), (ZIP16P GPR:$rs, (v4i16 X0))>;
 } // append Predicates = [IsRV64]
 } // Predicates = [HasStdExtP]

diff  --git a/llvm/test/CodeGen/RISCV/rvp-simd-32.ll b/llvm/test/CodeGen/RISCV/rvp-simd-32.ll
index 852f50b7d0e4e..efc11fe524717 100644
--- a/llvm/test/CodeGen/RISCV/rvp-simd-32.ll
+++ b/llvm/test/CodeGen/RISCV/rvp-simd-32.ll
@@ -1268,25 +1268,11 @@ define <4 x i8> @test_pmulhu_b(<4 x i8> %a, <4 x i8> %b) {
 define <4 x i8> @test_pmulhsu_b(<4 x i8> %a, <4 x i8> %b) {
 ; RV32-LABEL: test_pmulhsu_b:
 ; RV32:       # %bb.0:
-; RV32-NEXT:    sext.b a2, a0
-; RV32-NEXT:    slli a3, a0, 16
-; RV32-NEXT:    srai a4, a0, 24
-; RV32-NEXT:    slli a0, a0, 8
-; RV32-NEXT:    zext.b a5, a1
-; RV32-NEXT:    slli a6, a1, 16
-; RV32-NEXT:    srli a7, a1, 24
-; RV32-NEXT:    slli a1, a1, 8
-; RV32-NEXT:    srai a3, a3, 24
-; RV32-NEXT:    srai a0, a0, 24
-; RV32-NEXT:    srli a6, a6, 24
-; RV32-NEXT:    srli a1, a1, 24
-; RV32-NEXT:    pack a1, a1, a7
-; RV32-NEXT:    pack a0, a0, a4
-; RV32-NEXT:    pack a4, a5, a6
-; RV32-NEXT:    pack a2, a2, a3
-; RV32-NEXT:    pwmul.h a0, a0, a1
-; RV32-NEXT:    pncvt.h a1, a0
-; RV32-NEXT:    pwmul.h a2, a2, a4
+; RV32-NEXT:    pwcvt.b a2, a0
+; RV32-NEXT:    pwcvtu.b a0, a1
+; RV32-NEXT:    pwmul.h a4, a3, a1
+; RV32-NEXT:    pncvt.h a1, a4
+; RV32-NEXT:    pwmul.h a2, a2, a0
 ; RV32-NEXT:    pncvt.h a0, a2
 ; RV32-NEXT:    psrli.dh a0, a0, 8
 ; RV32-NEXT:    srli a3, a1, 16
@@ -1297,26 +1283,8 @@ define <4 x i8> @test_pmulhsu_b(<4 x i8> %a, <4 x i8> %b) {
 ;
 ; RV64-LABEL: test_pmulhsu_b:
 ; RV64:       # %bb.0:
-; RV64-NEXT:    srli a2, a0, 24
-; RV64-NEXT:    srli a3, a0, 16
-; RV64-NEXT:    ppaire.b a4, a0, a0
-; RV64-NEXT:    srli a0, a0, 8
-; RV64-NEXT:    ppaire.b a2, a2, a0
-; RV64-NEXT:    ppaire.b a3, a3, a0
-; RV64-NEXT:    ppaire.h a2, a3, a2
-; RV64-NEXT:    srli a3, a1, 24
-; RV64-NEXT:    ppaire.b a0, a0, a0
-; RV64-NEXT:    ppaire.h a0, a4, a0
-; RV64-NEXT:    srli a4, a1, 16
-; RV64-NEXT:    pzext.h.b a3, a3
-; RV64-NEXT:    pzext.h.b a4, a4
-; RV64-NEXT:    ppaire.h a3, a4, a3
-; RV64-NEXT:    pzext.h.b a4, a1
-; RV64-NEXT:    srli a1, a1, 8
-; RV64-NEXT:    pzext.h.b a1, a1
-; RV64-NEXT:    ppaire.h a1, a4, a1
-; RV64-NEXT:    pack a0, a0, a2
-; RV64-NEXT:    pack a1, a1, a3
+; RV64-NEXT:    pwcvtu.b a0, a0
+; RV64-NEXT:    pwcvtu.b a1, a1
 ; RV64-NEXT:    pslli.h a0, a0, 8
 ; RV64-NEXT:    psrai.h a0, a0, 8
 ; RV64-NEXT:    pmul.w.h11 a2, a0, a1
@@ -1325,9 +1293,9 @@ define <4 x i8> @test_pmulhsu_b(<4 x i8> %a, <4 x i8> %b) {
 ; RV64-NEXT:    psrli.h a0, a0, 8
 ; RV64-NEXT:    srli a1, a0, 48
 ; RV64-NEXT:    srli a2, a0, 32
-; RV64-NEXT:    srli a3, a0, 16
 ; RV64-NEXT:    ppaire.b a1, a2, a1
-; RV64-NEXT:    ppaire.b a0, a0, a3
+; RV64-NEXT:    srli a2, a0, 16
+; RV64-NEXT:    ppaire.b a0, a0, a2
 ; RV64-NEXT:    ppaire.h a0, a0, a1
 ; RV64-NEXT:    ret
   %a_ext = sext <4 x i8> %a to <4 x i16>
@@ -1341,25 +1309,11 @@ define <4 x i8> @test_pmulhsu_b(<4 x i8> %a, <4 x i8> %b) {
 define <4 x i8> @test_pmulhsu_b_commuted(<4 x i8> %a, <4 x i8> %b) {
 ; RV32-LABEL: test_pmulhsu_b_commuted:
 ; RV32:       # %bb.0:
-; RV32-NEXT:    zext.b a2, a0
-; RV32-NEXT:    slli a3, a0, 16
-; RV32-NEXT:    srli a4, a0, 24
-; RV32-NEXT:    slli a0, a0, 8
-; RV32-NEXT:    sext.b a5, a1
-; RV32-NEXT:    slli a6, a1, 16
-; RV32-NEXT:    srai a7, a1, 24
-; RV32-NEXT:    slli a1, a1, 8
-; RV32-NEXT:    srli a3, a3, 24
-; RV32-NEXT:    srli a0, a0, 24
-; RV32-NEXT:    srai a6, a6, 24
-; RV32-NEXT:    srai a1, a1, 24
-; RV32-NEXT:    pack a1, a1, a7
-; RV32-NEXT:    pack a0, a0, a4
-; RV32-NEXT:    pack a4, a5, a6
-; RV32-NEXT:    pack a2, a2, a3
-; RV32-NEXT:    pwmul.h a0, a0, a1
-; RV32-NEXT:    pncvt.h a1, a0
-; RV32-NEXT:    pwmul.h a2, a2, a4
+; RV32-NEXT:    pwcvtu.b a2, a0
+; RV32-NEXT:    pwcvt.b a0, a1
+; RV32-NEXT:    pwmul.h a4, a3, a1
+; RV32-NEXT:    pncvt.h a1, a4
+; RV32-NEXT:    pwmul.h a2, a2, a0
 ; RV32-NEXT:    pncvt.h a0, a2
 ; RV32-NEXT:    psrli.dh a0, a0, 8
 ; RV32-NEXT:    srli a3, a1, 16
@@ -1370,26 +1324,8 @@ define <4 x i8> @test_pmulhsu_b_commuted(<4 x i8> %a, <4 x i8> %b) {
 ;
 ; RV64-LABEL: test_pmulhsu_b_commuted:
 ; RV64:       # %bb.0:
-; RV64-NEXT:    srli a2, a0, 24
-; RV64-NEXT:    srli a3, a0, 16
-; RV64-NEXT:    pzext.h.b a4, a0
-; RV64-NEXT:    srli a0, a0, 8
-; RV64-NEXT:    pzext.h.b a2, a2
-; RV64-NEXT:    pzext.h.b a3, a3
-; RV64-NEXT:    ppaire.h a2, a3, a2
-; RV64-NEXT:    srli a3, a1, 24
-; RV64-NEXT:    pzext.h.b a0, a0
-; RV64-NEXT:    ppaire.h a0, a4, a0
-; RV64-NEXT:    srli a4, a1, 16
-; RV64-NEXT:    ppaire.b a3, a3, a0
-; RV64-NEXT:    ppaire.b a4, a4, a0
-; RV64-NEXT:    ppaire.h a3, a4, a3
-; RV64-NEXT:    ppaire.b a4, a1, a0
-; RV64-NEXT:    srli a1, a1, 8
-; RV64-NEXT:    ppaire.b a1, a1, a0
-; RV64-NEXT:    ppaire.h a1, a4, a1
-; RV64-NEXT:    pack a0, a0, a2
-; RV64-NEXT:    pack a1, a1, a3
+; RV64-NEXT:    pwcvtu.b a0, a0
+; RV64-NEXT:    pwcvtu.b a1, a1
 ; RV64-NEXT:    pslli.h a1, a1, 8
 ; RV64-NEXT:    psrai.h a1, a1, 8
 ; RV64-NEXT:    pmul.w.h11 a2, a0, a1
@@ -1398,9 +1334,9 @@ define <4 x i8> @test_pmulhsu_b_commuted(<4 x i8> %a, <4 x i8> %b) {
 ; RV64-NEXT:    psrli.h a0, a0, 8
 ; RV64-NEXT:    srli a1, a0, 48
 ; RV64-NEXT:    srli a2, a0, 32
-; RV64-NEXT:    srli a3, a0, 16
 ; RV64-NEXT:    ppaire.b a1, a2, a1
-; RV64-NEXT:    ppaire.b a0, a0, a3
+; RV64-NEXT:    srli a2, a0, 16
+; RV64-NEXT:    ppaire.b a0, a0, a2
 ; RV64-NEXT:    ppaire.h a0, a0, a1
 ; RV64-NEXT:    ret
   %a_ext = zext <4 x i8> %a to <4 x i16>

diff  --git a/llvm/test/CodeGen/RISCV/rvp-simd-64.ll b/llvm/test/CodeGen/RISCV/rvp-simd-64.ll
index dfe5e38b37308..04e7049c79e7a 100644
--- a/llvm/test/CodeGen/RISCV/rvp-simd-64.ll
+++ b/llvm/test/CodeGen/RISCV/rvp-simd-64.ll
@@ -2208,52 +2208,20 @@ define <2 x i32> @test_psra_ws_vec_shamt(<2 x i32> %a, <2 x i32> %b) {
 define <8 x i8> @test_pmulh_b(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-LABEL: test_pmulh_b:
 ; RV32:       # %bb.0:
-; RV32-NEXT:    addi sp, sp, -16
-; RV32-NEXT:    .cfi_def_cfa_offset 16
-; RV32-NEXT:    sw s0, 12(sp) # 4-byte Folded Spill
-; RV32-NEXT:    .cfi_offset s0, -4
-; RV32-NEXT:    sext.b a4, a0
-; RV32-NEXT:    slli a5, a0, 16
-; RV32-NEXT:    srai a6, a0, 24
-; RV32-NEXT:    slli a0, a0, 8
-; RV32-NEXT:    sext.b a7, a1
-; RV32-NEXT:    slli t0, a1, 16
-; RV32-NEXT:    srai t1, a1, 24
-; RV32-NEXT:    slli a1, a1, 8
-; RV32-NEXT:    sext.b t2, a2
-; RV32-NEXT:    slli t3, a2, 16
-; RV32-NEXT:    srai t4, a2, 24
-; RV32-NEXT:    slli a2, a2, 8
-; RV32-NEXT:    sext.b t5, a3
-; RV32-NEXT:    slli t6, a3, 16
-; RV32-NEXT:    srai s0, a3, 24
-; RV32-NEXT:    slli a3, a3, 8
-; RV32-NEXT:    srai a5, a5, 24
-; RV32-NEXT:    srai a0, a0, 24
-; RV32-NEXT:    srai t0, t0, 24
-; RV32-NEXT:    srai a1, a1, 24
-; RV32-NEXT:    srai t3, t3, 24
-; RV32-NEXT:    srai a2, a2, 24
-; RV32-NEXT:    srai t6, t6, 24
-; RV32-NEXT:    srai a3, a3, 24
-; RV32-NEXT:    pack a3, a3, s0
-; RV32-NEXT:    pack a1, a1, t1
-; RV32-NEXT:    pack t1, t5, t6
-; RV32-NEXT:    pack a7, a7, t0
-; RV32-NEXT:    pack a2, a2, t4
-; RV32-NEXT:    pack a0, a0, a6
-; RV32-NEXT:    pack a6, t2, t3
-; RV32-NEXT:    pack a4, a4, a5
-; RV32-NEXT:    pwmul.h t3, a1, a3
-; RV32-NEXT:    pwmul.h t1, a7, t1
+; RV32-NEXT:    pwcvt.b a4, a0
+; RV32-NEXT:    pwcvt.b a0, a1
+; RV32-NEXT:    pwcvt.b a6, a2
+; RV32-NEXT:    pwcvt.b a2, a3
+; RV32-NEXT:    pwmul.h t1, a1, a3
 ; RV32-NEXT:    pwmul.h a0, a0, a2
-; RV32-NEXT:    pwmul.h a2, a4, a6
-; RV32-NEXT:    pncvt.h a5, t3
-; RV32-NEXT:    pncvt.h a1, a0
-; RV32-NEXT:    pncvt.h a4, t1
-; RV32-NEXT:    pncvt.h a0, a2
-; RV32-NEXT:    psrli.dh a0, a0, 8
-; RV32-NEXT:    psrli.dh a2, a4, 8
+; RV32-NEXT:    pwmul.h a2, a5, a7
+; RV32-NEXT:    pwmul.h a4, a4, a6
+; RV32-NEXT:    pncvt.h a7, t1
+; RV32-NEXT:    pncvt.h a3, a2
+; RV32-NEXT:    pncvt.h a6, a0
+; RV32-NEXT:    pncvt.h a2, a4
+; RV32-NEXT:    psrli.dh a0, a2, 8
+; RV32-NEXT:    psrli.dh a2, a6, 8
 ; RV32-NEXT:    srli a4, a3, 16
 ; RV32-NEXT:    srli a5, a2, 16
 ; RV32-NEXT:    srli a6, a1, 16
@@ -2264,10 +2232,6 @@ define <8 x i8> @test_pmulh_b(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-NEXT:    ppaire.b a0, a0, a7
 ; RV32-NEXT:    pack a1, a2, a3
 ; RV32-NEXT:    pack a0, a0, a4
-; RV32-NEXT:    lw s0, 12(sp) # 4-byte Folded Reload
-; RV32-NEXT:    .cfi_restore s0
-; RV32-NEXT:    addi sp, sp, 16
-; RV32-NEXT:    .cfi_def_cfa_offset 0
 ; RV32-NEXT:    ret
 ;
 ; RV64-LABEL: test_pmulh_b:
@@ -2326,52 +2290,20 @@ define <2 x i32> @test_pmulh_w(<2 x i32> %a, <2 x i32> %b) {
 define <8 x i8> @test_pmulhu_b(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-LABEL: test_pmulhu_b:
 ; RV32:       # %bb.0:
-; RV32-NEXT:    addi sp, sp, -16
-; RV32-NEXT:    .cfi_def_cfa_offset 16
-; RV32-NEXT:    sw s0, 12(sp) # 4-byte Folded Spill
-; RV32-NEXT:    .cfi_offset s0, -4
-; RV32-NEXT:    zext.b a4, a0
-; RV32-NEXT:    slli a5, a0, 16
-; RV32-NEXT:    srli a6, a0, 24
-; RV32-NEXT:    slli a0, a0, 8
-; RV32-NEXT:    zext.b a7, a1
-; RV32-NEXT:    slli t0, a1, 16
-; RV32-NEXT:    srli t1, a1, 24
-; RV32-NEXT:    slli a1, a1, 8
-; RV32-NEXT:    zext.b t2, a2
-; RV32-NEXT:    slli t3, a2, 16
-; RV32-NEXT:    srli t4, a2, 24
-; RV32-NEXT:    slli a2, a2, 8
-; RV32-NEXT:    zext.b t5, a3
-; RV32-NEXT:    slli t6, a3, 16
-; RV32-NEXT:    srli s0, a3, 24
-; RV32-NEXT:    slli a3, a3, 8
-; RV32-NEXT:    srli a5, a5, 24
-; RV32-NEXT:    srli a0, a0, 24
-; RV32-NEXT:    srli t0, t0, 24
-; RV32-NEXT:    srli a1, a1, 24
-; RV32-NEXT:    srli t3, t3, 24
-; RV32-NEXT:    srli a2, a2, 24
-; RV32-NEXT:    srli t6, t6, 24
-; RV32-NEXT:    srli a3, a3, 24
-; RV32-NEXT:    pack a3, a3, s0
-; RV32-NEXT:    pack a1, a1, t1
-; RV32-NEXT:    pack t1, t5, t6
-; RV32-NEXT:    pack a7, a7, t0
-; RV32-NEXT:    pack a2, a2, t4
-; RV32-NEXT:    pack a0, a0, a6
-; RV32-NEXT:    pack a6, t2, t3
-; RV32-NEXT:    pack a4, a4, a5
-; RV32-NEXT:    pwmul.h t3, a1, a3
-; RV32-NEXT:    pwmul.h t1, a7, t1
+; RV32-NEXT:    pwcvtu.b a4, a0
+; RV32-NEXT:    pwcvtu.b a0, a1
+; RV32-NEXT:    pwcvtu.b a6, a2
+; RV32-NEXT:    pwcvtu.b a2, a3
+; RV32-NEXT:    pwmul.h t1, a1, a3
 ; RV32-NEXT:    pwmul.h a0, a0, a2
-; RV32-NEXT:    pwmul.h a2, a4, a6
-; RV32-NEXT:    pncvt.h a5, t3
-; RV32-NEXT:    pncvt.h a1, a0
-; RV32-NEXT:    pncvt.h a4, t1
-; RV32-NEXT:    pncvt.h a0, a2
-; RV32-NEXT:    psrli.dh a0, a0, 8
-; RV32-NEXT:    psrli.dh a2, a4, 8
+; RV32-NEXT:    pwmul.h a2, a5, a7
+; RV32-NEXT:    pwmul.h a4, a4, a6
+; RV32-NEXT:    pncvt.h a7, t1
+; RV32-NEXT:    pncvt.h a3, a2
+; RV32-NEXT:    pncvt.h a6, a0
+; RV32-NEXT:    pncvt.h a2, a4
+; RV32-NEXT:    psrli.dh a0, a2, 8
+; RV32-NEXT:    psrli.dh a2, a6, 8
 ; RV32-NEXT:    srli a4, a3, 16
 ; RV32-NEXT:    srli a5, a2, 16
 ; RV32-NEXT:    srli a6, a1, 16
@@ -2382,10 +2314,6 @@ define <8 x i8> @test_pmulhu_b(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-NEXT:    ppaire.b a0, a0, a7
 ; RV32-NEXT:    pack a1, a2, a3
 ; RV32-NEXT:    pack a0, a0, a4
-; RV32-NEXT:    lw s0, 12(sp) # 4-byte Folded Reload
-; RV32-NEXT:    .cfi_restore s0
-; RV32-NEXT:    addi sp, sp, 16
-; RV32-NEXT:    .cfi_def_cfa_offset 0
 ; RV32-NEXT:    ret
 ;
 ; RV64-LABEL: test_pmulhu_b:
@@ -2443,52 +2371,20 @@ define <2 x i32> @test_pmulhu_w(<2 x i32> %a, <2 x i32> %b) {
 define <8 x i8> @test_pmulhsu_b(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-LABEL: test_pmulhsu_b:
 ; RV32:       # %bb.0:
-; RV32-NEXT:    addi sp, sp, -16
-; RV32-NEXT:    .cfi_def_cfa_offset 16
-; RV32-NEXT:    sw s0, 12(sp) # 4-byte Folded Spill
-; RV32-NEXT:    .cfi_offset s0, -4
-; RV32-NEXT:    sext.b a4, a0
-; RV32-NEXT:    slli a5, a0, 16
-; RV32-NEXT:    srai a6, a0, 24
-; RV32-NEXT:    slli a0, a0, 8
-; RV32-NEXT:    sext.b a7, a1
-; RV32-NEXT:    slli t0, a1, 16
-; RV32-NEXT:    srai t1, a1, 24
-; RV32-NEXT:    slli a1, a1, 8
-; RV32-NEXT:    zext.b t2, a2
-; RV32-NEXT:    slli t3, a2, 16
-; RV32-NEXT:    srli t4, a2, 24
-; RV32-NEXT:    slli a2, a2, 8
-; RV32-NEXT:    zext.b t5, a3
-; RV32-NEXT:    slli t6, a3, 16
-; RV32-NEXT:    srli s0, a3, 24
-; RV32-NEXT:    slli a3, a3, 8
-; RV32-NEXT:    srai a5, a5, 24
-; RV32-NEXT:    srai a0, a0, 24
-; RV32-NEXT:    srai t0, t0, 24
-; RV32-NEXT:    srai a1, a1, 24
-; RV32-NEXT:    srli t3, t3, 24
-; RV32-NEXT:    srli a2, a2, 24
-; RV32-NEXT:    srli t6, t6, 24
-; RV32-NEXT:    srli a3, a3, 24
-; RV32-NEXT:    pack a3, a3, s0
-; RV32-NEXT:    pack a1, a1, t1
-; RV32-NEXT:    pack t1, t5, t6
-; RV32-NEXT:    pack a7, a7, t0
-; RV32-NEXT:    pack a2, a2, t4
-; RV32-NEXT:    pack a0, a0, a6
-; RV32-NEXT:    pack a6, t2, t3
-; RV32-NEXT:    pack a4, a4, a5
-; RV32-NEXT:    pwmul.h t3, a1, a3
-; RV32-NEXT:    pwmul.h t1, a7, t1
+; RV32-NEXT:    pwcvt.b a4, a0
+; RV32-NEXT:    pwcvt.b a0, a1
+; RV32-NEXT:    pwcvtu.b a6, a2
+; RV32-NEXT:    pwcvtu.b a2, a3
+; RV32-NEXT:    pwmul.h t1, a1, a3
 ; RV32-NEXT:    pwmul.h a0, a0, a2
-; RV32-NEXT:    pwmul.h a2, a4, a6
-; RV32-NEXT:    pncvt.h a5, t3
-; RV32-NEXT:    pncvt.h a1, a0
-; RV32-NEXT:    pncvt.h a4, t1
-; RV32-NEXT:    pncvt.h a0, a2
-; RV32-NEXT:    psrli.dh a0, a0, 8
-; RV32-NEXT:    psrli.dh a2, a4, 8
+; RV32-NEXT:    pwmul.h a2, a5, a7
+; RV32-NEXT:    pwmul.h a4, a4, a6
+; RV32-NEXT:    pncvt.h a7, t1
+; RV32-NEXT:    pncvt.h a3, a2
+; RV32-NEXT:    pncvt.h a6, a0
+; RV32-NEXT:    pncvt.h a2, a4
+; RV32-NEXT:    psrli.dh a0, a2, 8
+; RV32-NEXT:    psrli.dh a2, a6, 8
 ; RV32-NEXT:    srli a4, a3, 16
 ; RV32-NEXT:    srli a5, a2, 16
 ; RV32-NEXT:    srli a6, a1, 16
@@ -2499,10 +2395,6 @@ define <8 x i8> @test_pmulhsu_b(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-NEXT:    ppaire.b a0, a0, a7
 ; RV32-NEXT:    pack a1, a2, a3
 ; RV32-NEXT:    pack a0, a0, a4
-; RV32-NEXT:    lw s0, 12(sp) # 4-byte Folded Reload
-; RV32-NEXT:    .cfi_restore s0
-; RV32-NEXT:    addi sp, sp, 16
-; RV32-NEXT:    .cfi_def_cfa_offset 0
 ; RV32-NEXT:    ret
 ;
 ; RV64-LABEL: test_pmulhsu_b:
@@ -2519,50 +2411,14 @@ define <8 x i8> @test_pmulhsu_b(<8 x i8> %a, <8 x i8> %b) {
 ; RV64-NEXT:    ppaire.b a3, a3, a6
 ; RV64-NEXT:    srli a6, a1, 32
 ; RV64-NEXT:    ppaire.b a5, a6, a5
-; RV64-NEXT:    srli a6, a0, 24
-; RV64-NEXT:    ppaire.h a2, a4, a2
-; RV64-NEXT:    srli a4, a0, 16
-; RV64-NEXT:    ppaire.b a6, a6, a0
-; RV64-NEXT:    ppaire.b a4, a4, a0
-; RV64-NEXT:    ppaire.h a4, a4, a6
-; RV64-NEXT:    ppaire.b a6, a0, a0
-; RV64-NEXT:    srli a0, a0, 8
-; RV64-NEXT:    ppaire.b a0, a0, a0
-; RV64-NEXT:    ppaire.h a0, a6, a0
-; RV64-NEXT:    srli a6, a1, 24
-; RV64-NEXT:    ppaire.h a3, a5, a3
-; RV64-NEXT:    srli a5, a1, 16
-; RV64-NEXT:    pzext.h.b a6, a6
-; RV64-NEXT:    pzext.h.b a5, a5
-; RV64-NEXT:    ppaire.h a5, a5, a6
-; RV64-NEXT:    pzext.h.b a6, a1
-; RV64-NEXT:    srli a1, a1, 8
-; RV64-NEXT:    pzext.h.b a1, a1
-; RV64-NEXT:    ppaire.h a1, a6, a1
-; RV64-NEXT:    srli a6, a2, 24
-; RV64-NEXT:    pack a0, a0, a4
-; RV64-NEXT:    srli a4, a2, 16
-; RV64-NEXT:    pack a1, a1, a5
-; RV64-NEXT:    ppaire.b a5, a2, a0
-; RV64-NEXT:    srli a2, a2, 8
-; RV64-NEXT:    ppaire.b a6, a6, a0
-; RV64-NEXT:    ppaire.b a4, a4, a0
-; RV64-NEXT:    ppaire.h a4, a4, a6
-; RV64-NEXT:    srli a6, a3, 24
-; RV64-NEXT:    ppaire.b a2, a2, a0
-; RV64-NEXT:    ppaire.h a2, a5, a2
-; RV64-NEXT:    srli a5, a3, 16
-; RV64-NEXT:    pzext.h.b a6, a6
-; RV64-NEXT:    pzext.h.b a5, a5
-; RV64-NEXT:    ppaire.h a5, a5, a6
-; RV64-NEXT:    pzext.h.b a6, a3
-; RV64-NEXT:    srli a3, a3, 8
-; RV64-NEXT:    pzext.h.b a3, a3
-; RV64-NEXT:    ppaire.h a3, a6, a3
+; RV64-NEXT:    pwcvtu.b a0, a0
+; RV64-NEXT:    pwcvtu.b a1, a1
 ; RV64-NEXT:    pslli.h a0, a0, 8
+; RV64-NEXT:    ppaire.h a2, a4, a2
 ; RV64-NEXT:    psrai.h a0, a0, 8
-; RV64-NEXT:    pack a2, a2, a4
-; RV64-NEXT:    pack a3, a3, a5
+; RV64-NEXT:    ppaire.h a3, a5, a3
+; RV64-NEXT:    pwcvtu.b a2, a2
+; RV64-NEXT:    pwcvtu.b a3, a3
 ; RV64-NEXT:    pmul.w.h11 a4, a0, a1
 ; RV64-NEXT:    pmul.w.h00 a0, a0, a1
 ; RV64-NEXT:    pslli.h a1, a2, 8
@@ -2598,52 +2454,20 @@ define <8 x i8> @test_pmulhsu_b(<8 x i8> %a, <8 x i8> %b) {
 define <8 x i8> @test_pmulhsu_b_commuted(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-LABEL: test_pmulhsu_b_commuted:
 ; RV32:       # %bb.0:
-; RV32-NEXT:    addi sp, sp, -16
-; RV32-NEXT:    .cfi_def_cfa_offset 16
-; RV32-NEXT:    sw s0, 12(sp) # 4-byte Folded Spill
-; RV32-NEXT:    .cfi_offset s0, -4
-; RV32-NEXT:    zext.b a4, a0
-; RV32-NEXT:    slli a5, a0, 16
-; RV32-NEXT:    srli a6, a0, 24
-; RV32-NEXT:    slli a0, a0, 8
-; RV32-NEXT:    zext.b a7, a1
-; RV32-NEXT:    slli t0, a1, 16
-; RV32-NEXT:    srli t1, a1, 24
-; RV32-NEXT:    slli a1, a1, 8
-; RV32-NEXT:    sext.b t2, a2
-; RV32-NEXT:    slli t3, a2, 16
-; RV32-NEXT:    srai t4, a2, 24
-; RV32-NEXT:    slli a2, a2, 8
-; RV32-NEXT:    sext.b t5, a3
-; RV32-NEXT:    slli t6, a3, 16
-; RV32-NEXT:    srai s0, a3, 24
-; RV32-NEXT:    slli a3, a3, 8
-; RV32-NEXT:    srli a5, a5, 24
-; RV32-NEXT:    srli a0, a0, 24
-; RV32-NEXT:    srli t0, t0, 24
-; RV32-NEXT:    srli a1, a1, 24
-; RV32-NEXT:    srai t3, t3, 24
-; RV32-NEXT:    srai a2, a2, 24
-; RV32-NEXT:    srai t6, t6, 24
-; RV32-NEXT:    srai a3, a3, 24
-; RV32-NEXT:    pack a3, a3, s0
-; RV32-NEXT:    pack a1, a1, t1
-; RV32-NEXT:    pack t1, t5, t6
-; RV32-NEXT:    pack a7, a7, t0
-; RV32-NEXT:    pack a2, a2, t4
-; RV32-NEXT:    pack a0, a0, a6
-; RV32-NEXT:    pack a6, t2, t3
-; RV32-NEXT:    pack a4, a4, a5
-; RV32-NEXT:    pwmul.h t3, a1, a3
-; RV32-NEXT:    pwmul.h t1, a7, t1
+; RV32-NEXT:    pwcvtu.b a4, a0
+; RV32-NEXT:    pwcvtu.b a0, a1
+; RV32-NEXT:    pwcvt.b a6, a2
+; RV32-NEXT:    pwcvt.b a2, a3
+; RV32-NEXT:    pwmul.h t1, a1, a3
 ; RV32-NEXT:    pwmul.h a0, a0, a2
-; RV32-NEXT:    pwmul.h a2, a4, a6
-; RV32-NEXT:    pncvt.h a5, t3
-; RV32-NEXT:    pncvt.h a1, a0
-; RV32-NEXT:    pncvt.h a4, t1
-; RV32-NEXT:    pncvt.h a0, a2
-; RV32-NEXT:    psrli.dh a0, a0, 8
-; RV32-NEXT:    psrli.dh a2, a4, 8
+; RV32-NEXT:    pwmul.h a2, a5, a7
+; RV32-NEXT:    pwmul.h a4, a4, a6
+; RV32-NEXT:    pncvt.h a7, t1
+; RV32-NEXT:    pncvt.h a3, a2
+; RV32-NEXT:    pncvt.h a6, a0
+; RV32-NEXT:    pncvt.h a2, a4
+; RV32-NEXT:    psrli.dh a0, a2, 8
+; RV32-NEXT:    psrli.dh a2, a6, 8
 ; RV32-NEXT:    srli a4, a3, 16
 ; RV32-NEXT:    srli a5, a2, 16
 ; RV32-NEXT:    srli a6, a1, 16
@@ -2654,10 +2478,6 @@ define <8 x i8> @test_pmulhsu_b_commuted(<8 x i8> %a, <8 x i8> %b) {
 ; RV32-NEXT:    ppaire.b a0, a0, a7
 ; RV32-NEXT:    pack a1, a2, a3
 ; RV32-NEXT:    pack a0, a0, a4
-; RV32-NEXT:    lw s0, 12(sp) # 4-byte Folded Reload
-; RV32-NEXT:    .cfi_restore s0
-; RV32-NEXT:    addi sp, sp, 16
-; RV32-NEXT:    .cfi_def_cfa_offset 0
 ; RV32-NEXT:    ret
 ;
 ; RV64-LABEL: test_pmulhsu_b_commuted:
@@ -2674,50 +2494,14 @@ define <8 x i8> @test_pmulhsu_b_commuted(<8 x i8> %a, <8 x i8> %b) {
 ; RV64-NEXT:    ppaire.b a3, a3, a6
 ; RV64-NEXT:    srli a6, a1, 32
 ; RV64-NEXT:    ppaire.b a5, a6, a5
-; RV64-NEXT:    srli a6, a0, 24
+; RV64-NEXT:    pwcvtu.b a0, a0
+; RV64-NEXT:    pwcvtu.b a1, a1
+; RV64-NEXT:    pslli.h a1, a1, 8
 ; RV64-NEXT:    ppaire.h a2, a4, a2
-; RV64-NEXT:    srli a4, a0, 16
-; RV64-NEXT:    pzext.h.b a6, a6
-; RV64-NEXT:    pzext.h.b a4, a4
-; RV64-NEXT:    ppaire.h a4, a4, a6
-; RV64-NEXT:    pzext.h.b a6, a0
-; RV64-NEXT:    srli a0, a0, 8
-; RV64-NEXT:    pzext.h.b a0, a0
-; RV64-NEXT:    ppaire.h a0, a6, a0
-; RV64-NEXT:    srli a6, a1, 24
 ; RV64-NEXT:    ppaire.h a3, a5, a3
-; RV64-NEXT:    srli a5, a1, 16
-; RV64-NEXT:    ppaire.b a6, a6, a0
-; RV64-NEXT:    ppaire.b a5, a5, a0
-; RV64-NEXT:    ppaire.h a5, a5, a6
-; RV64-NEXT:    ppaire.b a6, a1, a0
-; RV64-NEXT:    srli a1, a1, 8
-; RV64-NEXT:    ppaire.b a1, a1, a0
-; RV64-NEXT:    ppaire.h a1, a6, a1
-; RV64-NEXT:    srli a6, a2, 24
-; RV64-NEXT:    pack a0, a0, a4
-; RV64-NEXT:    srli a4, a2, 16
-; RV64-NEXT:    pack a1, a1, a5
-; RV64-NEXT:    pzext.h.b a5, a2
-; RV64-NEXT:    srli a2, a2, 8
-; RV64-NEXT:    pzext.h.b a6, a6
-; RV64-NEXT:    pzext.h.b a4, a4
-; RV64-NEXT:    ppaire.h a4, a4, a6
-; RV64-NEXT:    srli a6, a3, 24
-; RV64-NEXT:    pzext.h.b a2, a2
-; RV64-NEXT:    ppaire.h a2, a5, a2
-; RV64-NEXT:    srli a5, a3, 16
-; RV64-NEXT:    ppaire.b a6, a6, a0
-; RV64-NEXT:    ppaire.b a5, a5, a0
-; RV64-NEXT:    ppaire.h a5, a5, a6
-; RV64-NEXT:    ppaire.b a6, a3, a0
-; RV64-NEXT:    srli a3, a3, 8
-; RV64-NEXT:    ppaire.b a3, a3, a0
-; RV64-NEXT:    ppaire.h a3, a6, a3
-; RV64-NEXT:    pslli.h a1, a1, 8
 ; RV64-NEXT:    psrai.h a1, a1, 8
-; RV64-NEXT:    pack a2, a2, a4
-; RV64-NEXT:    pack a3, a3, a5
+; RV64-NEXT:    pwcvtu.b a2, a2
+; RV64-NEXT:    pwcvtu.b a3, a3
 ; RV64-NEXT:    pmul.w.h11 a4, a0, a1
 ; RV64-NEXT:    pmul.w.h00 a0, a0, a1
 ; RV64-NEXT:    pslli.h a1, a3, 8
@@ -4678,3 +4462,55 @@ define <2 x i32> @test_bitreverse_v2i32(<2 x i32> %a) {
   %res = call <2 x i32> @llvm.bitreverse.v2i32(<2 x i32> %a)
   ret <2 x i32> %res
 }
+
+define <4 x i16> @test_zext_v4i8_to_v4i16(<4 x i8> %a) {
+; CHECK-LABEL: test_zext_v4i8_to_v4i16:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    pwcvtu.b a0, a0
+; CHECK-NEXT:    ret
+  %res = zext <4 x i8> %a to <4 x i16>
+  ret <4 x i16> %res
+}
+
+define <2 x i32> @test_zext_v2i16_to_v2i32(<2 x i16> %a) {
+; CHECK-LABEL: test_zext_v2i16_to_v2i32:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    pwcvtu.h a0, a0
+; CHECK-NEXT:    ret
+  %res = zext <2 x i16> %a to <2 x i32>
+  ret <2 x i32> %res
+}
+
+; FIXME: Should use psext.h.b on RV64.
+define <4 x i16> @test_sext_v4i8_to_v4i16(<4 x i8> %a) {
+; RV32-LABEL: test_sext_v4i8_to_v4i16:
+; RV32:       # %bb.0:
+; RV32-NEXT:    pwcvt.b a0, a0
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sext_v4i8_to_v4i16:
+; RV64:       # %bb.0:
+; RV64-NEXT:    pwcvtu.b a0, a0
+; RV64-NEXT:    pslli.h a0, a0, 8
+; RV64-NEXT:    psrai.h a0, a0, 8
+; RV64-NEXT:    ret
+  %res = sext <4 x i8> %a to <4 x i16>
+  ret <4 x i16> %res
+}
+
+; FIXME: Should use psext.w.h on RV64.
+define <2 x i32> @test_sext_v2i16_to_v2i32(<2 x i16> %a) {
+; RV32-LABEL: test_sext_v2i16_to_v2i32:
+; RV32:       # %bb.0:
+; RV32-NEXT:    pwcvt.h a0, a0
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sext_v2i16_to_v2i32:
+; RV64:       # %bb.0:
+; RV64-NEXT:    pwcvtu.h a0, a0
+; RV64-NEXT:    pslli.w a0, a0, 16
+; RV64-NEXT:    psrai.w a0, a0, 16
+; RV64-NEXT:    ret
+  %res = sext <2 x i16> %a to <2 x i32>
+  ret <2 x i32> %res
+}


        


More information about the llvm-commits mailing list