Skip to content

Commit 7e7f3b9

Browse files
committed
[llvm][RISCV] Support P Extension CodeGen
This patch supports: PSLLI_B, PSLLI_H, PSLLI_W, PSSLAI_H and PSSLAI_W
1 parent 13251f5 commit 7e7f3b9

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
523523
setOperationAction(ISD::SADDSAT, VTs, Legal);
524524
setOperationAction(ISD::USUBSAT, VTs, Legal);
525525
setOperationAction(ISD::SSUBSAT, VTs, Legal);
526+
setOperationAction(ISD::SSHLSAT, VTs, Legal);
526527
setOperationAction({ISD::AVGFLOORS, ISD::AVGFLOORU}, VTs, Legal);
527528
setOperationAction({ISD::ABDS, ISD::ABDU}, VTs, Legal);
528529
setOperationAction(ISD::BUILD_VECTOR, VTs, Custom);

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
//===----------------------------------------------------------------------===//
2020

2121
def simm10 : RISCVSImmOp<10>, TImmLeaf<XLenVT, "return isInt<10>(Imm);">;
22+
def tuimm3 : RISCVUImmOp<3>, TImmLeaf<XLenVT, "return isUInt<3>(Imm);">;
23+
def tuimm4 : RISCVUImmOp<4>, TImmLeaf<XLenVT, "return isUInt<4>(Imm);">;
2224

2325
def SImm8UnsignedAsmOperand : SImmAsmOperand<8, "Unsigned"> {
2426
let RenderMethod = "addSImm8UnsignedOperands";
@@ -1517,6 +1519,17 @@ let Predicates = [HasStdExtP] in {
15171519
def: Pat<(XLenVecI16VT (abds GPR:$rs1, GPR:$rs2)), (PDIF_H GPR:$rs1, GPR:$rs2)>;
15181520
def: Pat<(XLenVecI16VT (abdu GPR:$rs1, GPR:$rs2)), (PDIFU_H GPR:$rs1, GPR:$rs2)>;
15191521

1522+
// 8-bit logical shift left patterns
1523+
def: Pat<(XLenVecI8VT (shl GPR:$rs1, (XLenVecI8VT (riscv_pli tuimm3:$shamt)))),
1524+
(PSLLI_B GPR:$rs1, tuimm3:$shamt)>;
1525+
1526+
// 16-bit logical shift left patterns
1527+
def: Pat<(XLenVecI16VT (shl GPR:$rs1, (XLenVecI16VT (riscv_pli tuimm4:$shamt)))),
1528+
(PSLLI_H GPR:$rs1, tuimm4:$shamt)>;
1529+
1530+
// 16-bit signed saturation shift left patterns
1531+
def: Pat<(XLenVecI16VT (sshlsat GPR:$rs1, (XLenVecI16VT (riscv_pli tuimm4:$shamt)))),
1532+
(PSSLAI_H GPR:$rs1, tuimm4:$shamt)>;
15201533

15211534
// 8-bit PLI SD node pattern
15221535
def: Pat<(XLenVecI8VT (riscv_pli simm8_unsigned:$imm8)), (PLI_B simm8_unsigned:$imm8)>;
@@ -1543,6 +1556,14 @@ let Predicates = [HasStdExtP, IsRV64] in {
15431556
def: Pat<(v2i32 (riscv_pasub GPR:$rs1, GPR:$rs2)), (PASUB_W GPR:$rs1, GPR:$rs2)>;
15441557
def: Pat<(v2i32 (riscv_pasubu GPR:$rs1, GPR:$rs2)), (PASUBU_W GPR:$rs1, GPR:$rs2)>;
15451558

1559+
// 32-bit logical shift left patterns
1560+
def: Pat<(v2i32 (shl GPR:$rs1, (v2i32 (riscv_pli tuimm4:$shamt)))),
1561+
(PSLLI_W GPR:$rs1, tuimm4:$shamt)>;
1562+
1563+
// 32-bit signed saturation shift left patterns
1564+
def: Pat<(v2i32 (sshlsat GPR:$rs1, (v2i32 (riscv_pli tuimm4:$shamt)))),
1565+
(PSSLAI_W GPR:$rs1, tuimm4:$shamt)>;
1566+
15461567
// Load/Store patterns
15471568
def : StPat<store, SD, GPR, v8i8>;
15481569
def : StPat<store, SD, GPR, v4i16>;

llvm/test/CodeGen/RISCV/rvp-ext-rv32.ll

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,48 @@ define void @test_extract_vector_8(ptr %ret_ptr, ptr %a_ptr) {
496496
ret void
497497
}
498498

499+
; Test logical shift left immediate for v2i16
500+
define void @test_pslli_h(ptr %ret_ptr, ptr %a_ptr) {
501+
; CHECK-LABEL: test_pslli_h:
502+
; CHECK: # %bb.0:
503+
; CHECK-NEXT: lw a1, 0(a1)
504+
; CHECK-NEXT: pslli.h a1, a1, 2
505+
; CHECK-NEXT: sw a1, 0(a0)
506+
; CHECK-NEXT: ret
507+
%a = load <2 x i16>, ptr %a_ptr
508+
%res = shl <2 x i16> %a, splat(i16 2)
509+
store <2 x i16> %res, ptr %ret_ptr
510+
ret void
511+
}
512+
513+
; Test logical shift left immediate for v4i8
514+
define void @test_pslli_b(ptr %ret_ptr, ptr %a_ptr) {
515+
; CHECK-LABEL: test_pslli_b:
516+
; CHECK: # %bb.0:
517+
; CHECK-NEXT: lw a1, 0(a1)
518+
; CHECK-NEXT: pslli.b a1, a1, 2
519+
; CHECK-NEXT: sw a1, 0(a0)
520+
; CHECK-NEXT: ret
521+
%a = load <4 x i8>, ptr %a_ptr
522+
%res = shl <4 x i8> %a, splat(i8 2)
523+
store <4 x i8> %res, ptr %ret_ptr
524+
ret void
525+
}
526+
527+
; Test arithmetic saturation shift left immediate for v2i16
528+
define void @test_psslai_h(ptr %ret_ptr, ptr %a_ptr) {
529+
; CHECK-LABEL: test_psslai_h:
530+
; CHECK: # %bb.0:
531+
; CHECK-NEXT: lw a1, 0(a1)
532+
; CHECK-NEXT: psslai.h a1, a1, 2
533+
; CHECK-NEXT: sw a1, 0(a0)
534+
; CHECK-NEXT: ret
535+
%a = load <2 x i16>, ptr %a_ptr
536+
%res = call <2 x i16> @llvm.sshl.sat.v2i16(<2 x i16> %a, <2 x i16> splat(i16 2))
537+
store <2 x i16> %res, ptr %ret_ptr
538+
ret void
539+
}
540+
499541
; Intrinsic declarations
500542
declare <2 x i16> @llvm.sadd.sat.v2i16(<2 x i16>, <2 x i16>)
501543
declare <2 x i16> @llvm.uadd.sat.v2i16(<2 x i16>, <2 x i16>)
@@ -513,3 +555,4 @@ declare <4 x i8> @llvm.smin.v4i8(<4 x i8>, <4 x i8>)
513555
declare <4 x i8> @llvm.smax.v4i8(<4 x i8>, <4 x i8>)
514556
declare <4 x i8> @llvm.umin.v4i8(<4 x i8>, <4 x i8>)
515557
declare <4 x i8> @llvm.umax.v4i8(<4 x i8>, <4 x i8>)
558+
declare <2 x i16> @llvm.sshl.sat.v2i16(<2 x i16> %a, <2 x i16> %b)

llvm/test/CodeGen/RISCV/rvp-ext-rv64.ll

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,62 @@ define void @test_extract_vector_32(ptr %ret_ptr, ptr %a_ptr) {
495495
ret void
496496
}
497497

498+
; Test logical shift left immediate for v4i16
499+
define void @test_pslli_h(ptr %ret_ptr, ptr %a_ptr) {
500+
; CHECK-LABEL: test_pslli_h:
501+
; CHECK: # %bb.0:
502+
; CHECK-NEXT: ld a1, 0(a1)
503+
; CHECK-NEXT: pslli.h a1, a1, 2
504+
; CHECK-NEXT: sd a1, 0(a0)
505+
; CHECK-NEXT: ret
506+
%a = load <4 x i16>, ptr %a_ptr
507+
%res = shl <4 x i16> %a, splat(i16 2)
508+
store <4 x i16> %res, ptr %ret_ptr
509+
ret void
510+
}
511+
512+
; Test logical shift left immediate for v8i8
513+
define void @test_pslli_b(ptr %ret_ptr, ptr %a_ptr) {
514+
; CHECK-LABEL: test_pslli_b:
515+
; CHECK: # %bb.0:
516+
; CHECK-NEXT: ld a1, 0(a1)
517+
; CHECK-NEXT: pslli.b a1, a1, 2
518+
; CHECK-NEXT: sd a1, 0(a0)
519+
; CHECK-NEXT: ret
520+
%a = load <8 x i8>, ptr %a_ptr
521+
%res = shl <8 x i8> %a, splat(i8 2)
522+
store <8 x i8> %res, ptr %ret_ptr
523+
ret void
524+
}
525+
526+
; Test logical shift left immediate for v2i32
527+
define void @test_pslli_w(ptr %ret_ptr, ptr %a_ptr) {
528+
; CHECK-LABEL: test_pslli_w:
529+
; CHECK: # %bb.0:
530+
; CHECK-NEXT: ld a1, 0(a1)
531+
; CHECK-NEXT: pslli.w a1, a1, 2
532+
; CHECK-NEXT: sd a1, 0(a0)
533+
; CHECK-NEXT: ret
534+
%a = load <2 x i32>, ptr %a_ptr
535+
%res = shl <2 x i32> %a, splat(i32 2)
536+
store <2 x i32> %res, ptr %ret_ptr
537+
ret void
538+
}
539+
540+
; Test arithmetic saturation shift left immediate for v2i32
541+
define void @test_psslai_w(ptr %ret_ptr, ptr %a_ptr) {
542+
; CHECK-LABEL: test_psslai_w:
543+
; CHECK: # %bb.0:
544+
; CHECK-NEXT: ld a1, 0(a1)
545+
; CHECK-NEXT: psslai.w a1, a1, 2
546+
; CHECK-NEXT: sd a1, 0(a0)
547+
; CHECK-NEXT: ret
548+
%a = load <2 x i32>, ptr %a_ptr
549+
%res = call <2 x i32> @llvm.sshl.sat.v2i32(<2 x i32> %a, <2 x i32> splat(i32 2))
550+
store <2 x i32> %res, ptr %ret_ptr
551+
ret void
552+
}
553+
498554
; Intrinsic declarations
499555
declare <4 x i16> @llvm.sadd.sat.v4i16(<4 x i16>, <4 x i16>)
500556
declare <4 x i16> @llvm.uadd.sat.v4i16(<4 x i16>, <4 x i16>)
@@ -512,3 +568,4 @@ declare <8 x i8> @llvm.smin.v8i8(<8 x i8>, <8 x i8>)
512568
declare <8 x i8> @llvm.smax.v8i8(<8 x i8>, <8 x i8>)
513569
declare <8 x i8> @llvm.umin.v8i8(<8 x i8>, <8 x i8>)
514570
declare <8 x i8> @llvm.umax.v8i8(<8 x i8>, <8 x i8>)
571+
declare <2 x i32> @llvm.sshl.sat.v2i32(<2 x i32> %a, <2 x i32> %b)

0 commit comments

Comments
 (0)