Skip to content

Commit f5742c4

Browse files
authored
[RISCV] Intrinsic Support for XCVelw (#129168)
1 parent 5dd2b06 commit f5742c4

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

llvm/include/llvm/IR/IntrinsicsRISCVXCV.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ let TargetPrefix = "riscv" in {
9090
def int_riscv_cv_mac_machhuRN : ScalarCoreVMacGprGprGprImmIntrinsic;
9191
def int_riscv_cv_mac_macsRN : ScalarCoreVMacGprGprGprImmIntrinsic;
9292
def int_riscv_cv_mac_machhsRN : ScalarCoreVMacGprGprGprImmIntrinsic;
93+
94+
def int_riscv_cv_elw_elw
95+
: Intrinsic<[llvm_i32_ty], [llvm_ptr_ty],
96+
[IntrReadMem, IntrArgMemOnly, IntrHasSideEffects]>;
9397
} // TargetPrefix = "riscv"

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,9 @@ bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
40824082

40834083
return false;
40844084
}
4085+
case RISCV::PseudoCV_ELW:
4086+
emitLoadStoreSymbol(Inst, RISCV::CV_ELW, IDLoc, Out, /*HasTmpReg=*/false);
4087+
return false;
40854088
}
40864089

40874090
emitToStreamer(Out, Inst);

llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,9 @@ let Predicates = [HasVendorXCVmem, IsRV32] in {
633633
def CV_SW_rr : CVStore_rr<0b011, 0b0010110, "cv.sw">;
634634
}
635635

636-
let Predicates = [HasVendorXCVelw, IsRV32], hasSideEffects = 0,
636+
let Predicates = [HasVendorXCVelw, IsRV32], hasSideEffects = 1,
637637
mayLoad = 1, mayStore = 0 in {
638+
def PseudoCV_ELW : PseudoLoad<"cv.elw">;
638639
// Event load
639640
def CV_ELW : CVLoad_ri<0b011, "cv.elw">;
640641
}
@@ -706,6 +707,12 @@ let Predicates = [HasVendorXCVmem, IsRV32], AddedComplexity = 1 in {
706707
def : CVStrrPat<store, CV_SW_rr>;
707708
}
708709

710+
let Predicates = [HasVendorXCVelw, IsRV32] in {
711+
def : Pat<(int_riscv_cv_elw_elw (XLenVT GPR:$rs1)), (PseudoCV_ELW GPR:$rs1)>;
712+
def : Pat<(int_riscv_cv_elw_elw (AddrRegImm (XLenVT GPR:$rs1), simm12_lo:$imm12)),
713+
(CV_ELW GPR:$rs1, simm12_lo:$imm12)>;
714+
}
715+
709716
multiclass PatCoreVBitManip<Intrinsic intr> {
710717
def : PatGprGpr<intr, !cast<RVInst>("CV_" # NAME # "R")>;
711718
def : Pat<(intr GPR:$rs1, cv_uimm10:$imm),

llvm/test/CodeGen/RISCV/xcvelw.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -mtriple=riscv32 -mattr=+xcvelw -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s
4+
5+
declare i32 @llvm.riscv.cv.elw.elw(i8*)
6+
7+
define i32 @test.cv.elw.elw(i8* %a) {
8+
; CHECK-LABEL: test.cv.elw.elw:
9+
; CHECK: # %bb.0:
10+
; CHECK-NEXT: cv.elw a0, 0(a0)
11+
; CHECK-NEXT: ret
12+
%1 = call i32 @llvm.riscv.cv.elw.elw(i8* %a)
13+
ret i32 %1
14+
}
15+
16+
define i32 @test.cv.elw.elw2(i8* %a, i32 %b) {
17+
; CHECK-LABEL: test.cv.elw.elw2:
18+
; CHECK: # %bb.0:
19+
; CHECK-NEXT: add a0, a1, a0
20+
; CHECK-NEXT: cv.elw a0, 7(a0)
21+
; CHECK-NEXT: ret
22+
%c = add i32 %b, 4
23+
%d = add i32 %c, 3
24+
%e = getelementptr i8, i8* %a, i32 %d
25+
%1 = call i32 @llvm.riscv.cv.elw.elw(i8* %e)
26+
ret i32 %1
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: llvm-mc %s -triple=riscv32 --mattr=+xcvelw | FileCheck %s
2+
3+
# CHECK: .Lpcrel_hi0:
4+
# CHECK: auipc a2, %pcrel_hi(a_symbol)
5+
# CHECK: cv.elw a2, %pcrel_lo(.Lpcrel_hi0)(a2)
6+
cv.elw a2, a_symbol
7+
8+
# CHECK: .Lpcrel_hi1:
9+
# CHECK: auipc a3, %pcrel_hi(a_symbol)
10+
# CHECK: cv.elw a3, %pcrel_lo(.Lpcrel_hi1)(a3)
11+
cv.elw a3, a_symbol

0 commit comments

Comments
 (0)