Skip to content

Commit 40f21a7

Browse files
authored
[llvm][RISCV] Support P Extension CodeGen (#167895)
This patch supports: PSLLI_B, PSLLI_H, PSLLI_W, PSSLAI_H and PSSLAI_W
1 parent 175168c commit 40f21a7

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
525525
setOperationAction(ISD::SADDSAT, VTs, Legal);
526526
setOperationAction(ISD::USUBSAT, VTs, Legal);
527527
setOperationAction(ISD::SSUBSAT, VTs, Legal);
528+
setOperationAction(ISD::SSHLSAT, VTs, Legal);
528529
setOperationAction({ISD::AVGFLOORS, ISD::AVGFLOORU}, VTs, Legal);
529530
setOperationAction({ISD::ABDS, ISD::ABDU}, VTs, Legal);
530531
setOperationAction(ISD::SPLAT_VECTOR, VTs, Legal);

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,17 @@ let Predicates = [HasStdExtP] in {
15201520
def: Pat<(XLenVecI16VT (abds GPR:$rs1, GPR:$rs2)), (PDIF_H GPR:$rs1, GPR:$rs2)>;
15211521
def: Pat<(XLenVecI16VT (abdu GPR:$rs1, GPR:$rs2)), (PDIFU_H GPR:$rs1, GPR:$rs2)>;
15221522

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

15241535
// 8-bit PLI SD node pattern
15251536
def: Pat<(XLenVecI8VT (splat_vector simm8_unsigned:$imm8)), (PLI_B simm8_unsigned:$imm8)>;
@@ -1570,6 +1581,14 @@ let Predicates = [HasStdExtP, IsRV64] in {
15701581
// splat pattern
15711582
def: Pat<(v2i32 (splat_vector (XLenVT GPR:$rs2))), (PADD_WS (XLenVT X0), GPR:$rs2)>;
15721583

1584+
// 32-bit logical shift left patterns
1585+
def: Pat<(v2i32 (shl GPR:$rs1, (v2i32 (splat_vector uimm5:$shamt)))),
1586+
(PSLLI_W GPR:$rs1, uimm5:$shamt)>;
1587+
1588+
// 32-bit signed saturation shift left patterns
1589+
def: Pat<(v2i32 (sshlsat GPR:$rs1, (v2i32 (splat_vector uimm5:$shamt)))),
1590+
(PSSLAI_W GPR:$rs1, uimm5:$shamt)>;
1591+
15731592
// Load/Store patterns
15741593
def : StPat<store, SD, GPR, v8i8>;
15751594
def : StPat<store, SD, GPR, v4i16>;

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,48 @@ define void @test_build_vector_i16(ptr %ret_ptr, i16 %a, i16 %b) {
564564
ret void
565565
}
566566

567+
; Test logical shift left immediate for v2i16
568+
define void @test_pslli_h(ptr %ret_ptr, ptr %a_ptr) {
569+
; CHECK-LABEL: test_pslli_h:
570+
; CHECK: # %bb.0:
571+
; CHECK-NEXT: lw a1, 0(a1)
572+
; CHECK-NEXT: pslli.h a1, a1, 2
573+
; CHECK-NEXT: sw a1, 0(a0)
574+
; CHECK-NEXT: ret
575+
%a = load <2 x i16>, ptr %a_ptr
576+
%res = shl <2 x i16> %a, splat(i16 2)
577+
store <2 x i16> %res, ptr %ret_ptr
578+
ret void
579+
}
580+
581+
; Test logical shift left immediate for v4i8
582+
define void @test_pslli_b(ptr %ret_ptr, ptr %a_ptr) {
583+
; CHECK-LABEL: test_pslli_b:
584+
; CHECK: # %bb.0:
585+
; CHECK-NEXT: lw a1, 0(a1)
586+
; CHECK-NEXT: pslli.b a1, a1, 2
587+
; CHECK-NEXT: sw a1, 0(a0)
588+
; CHECK-NEXT: ret
589+
%a = load <4 x i8>, ptr %a_ptr
590+
%res = shl <4 x i8> %a, splat(i8 2)
591+
store <4 x i8> %res, ptr %ret_ptr
592+
ret void
593+
}
594+
595+
; Test arithmetic saturation shift left immediate for v2i16
596+
define void @test_psslai_h(ptr %ret_ptr, ptr %a_ptr) {
597+
; CHECK-LABEL: test_psslai_h:
598+
; CHECK: # %bb.0:
599+
; CHECK-NEXT: lw a1, 0(a1)
600+
; CHECK-NEXT: psslai.h a1, a1, 2
601+
; CHECK-NEXT: sw a1, 0(a0)
602+
; CHECK-NEXT: ret
603+
%a = load <2 x i16>, ptr %a_ptr
604+
%res = call <2 x i16> @llvm.sshl.sat.v2i16(<2 x i16> %a, <2 x i16> splat(i16 2))
605+
store <2 x i16> %res, ptr %ret_ptr
606+
ret void
607+
}
608+
567609
; Intrinsic declarations
568610
declare <2 x i16> @llvm.sadd.sat.v2i16(<2 x i16>, <2 x i16>)
569611
declare <2 x i16> @llvm.uadd.sat.v2i16(<2 x i16>, <2 x i16>)

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,61 @@ define void @test_build_vector_i32(ptr %ret_ptr, i32 %a, i32 %b) {
738738
ret void
739739
}
740740

741+
; Test logical shift left immediate for v4i16
742+
define void @test_pslli_h(ptr %ret_ptr, ptr %a_ptr) {
743+
; CHECK-LABEL: test_pslli_h:
744+
; CHECK: # %bb.0:
745+
; CHECK-NEXT: ld a1, 0(a1)
746+
; CHECK-NEXT: pslli.h a1, a1, 2
747+
; CHECK-NEXT: sd a1, 0(a0)
748+
; CHECK-NEXT: ret
749+
%a = load <4 x i16>, ptr %a_ptr
750+
%res = shl <4 x i16> %a, splat(i16 2)
751+
store <4 x i16> %res, ptr %ret_ptr
752+
ret void
753+
}
754+
755+
; Test logical shift left immediate for v8i8
756+
define void @test_pslli_b(ptr %ret_ptr, ptr %a_ptr) {
757+
; CHECK-LABEL: test_pslli_b:
758+
; CHECK: # %bb.0:
759+
; CHECK-NEXT: ld a1, 0(a1)
760+
; CHECK-NEXT: pslli.b a1, a1, 2
761+
; CHECK-NEXT: sd a1, 0(a0)
762+
; CHECK-NEXT: ret
763+
%a = load <8 x i8>, ptr %a_ptr
764+
%res = shl <8 x i8> %a, splat(i8 2)
765+
store <8 x i8> %res, ptr %ret_ptr
766+
ret void
767+
}
768+
769+
; Test logical shift left immediate for v2i32
770+
define void @test_pslli_w(ptr %ret_ptr, ptr %a_ptr) {
771+
; CHECK-LABEL: test_pslli_w:
772+
; CHECK: # %bb.0:
773+
; CHECK-NEXT: ld a1, 0(a1)
774+
; CHECK-NEXT: pslli.w a1, a1, 2
775+
; CHECK-NEXT: sd a1, 0(a0)
776+
; CHECK-NEXT: ret
777+
%a = load <2 x i32>, ptr %a_ptr
778+
%res = shl <2 x i32> %a, splat(i32 2)
779+
store <2 x i32> %res, ptr %ret_ptr
780+
ret void
781+
}
782+
783+
; Test arithmetic saturation shift left immediate for v2i32
784+
define void @test_psslai_w(ptr %ret_ptr, ptr %a_ptr) {
785+
; CHECK-LABEL: test_psslai_w:
786+
; CHECK: # %bb.0:
787+
; CHECK-NEXT: ld a1, 0(a1)
788+
; CHECK-NEXT: psslai.w a1, a1, 2
789+
; CHECK-NEXT: sd a1, 0(a0)
790+
; CHECK-NEXT: ret
791+
%a = load <2 x i32>, ptr %a_ptr
792+
%res = call <2 x i32> @llvm.sshl.sat.v2i32(<2 x i32> %a, <2 x i32> splat(i32 2))
793+
store <2 x i32> %res, ptr %ret_ptr
794+
ret void
795+
}
741796
; Intrinsic declarations
742797
declare <4 x i16> @llvm.sadd.sat.v4i16(<4 x i16>, <4 x i16>)
743798
declare <4 x i16> @llvm.uadd.sat.v4i16(<4 x i16>, <4 x i16>)

0 commit comments

Comments
 (0)