Skip to content

Commit 40460a5

Browse files
authored
[RISCV] Add basic ISel patterns for Xqcilo instructions (llvm#135901)
This patch adds basic instruction selection patterns for generating the 48 bit load/store instructions that are a part of the Qualcomm uC Xqcilo vendor extension.
1 parent 3de88fe commit 40460a5

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ def bare_simm32_lsb0 : Operand<OtherVT> {
159159
let OperandType = "OPERAND_PCREL";
160160
}
161161

162+
def AddLike: PatFrags<(ops node:$A, node:$B),
163+
[(add node:$A, node:$B), (or node:$A, node:$B)], [{
164+
return CurDAG->isBaseWithConstantOffset(SDValue(N, 0));
165+
}]>;
166+
162167
//===----------------------------------------------------------------------===//
163168
// Instruction Formats
164169
//===----------------------------------------------------------------------===//
@@ -1239,6 +1244,14 @@ class PatGprNoX0Simm32NoSimm26<SDPatternOperator OpNode, RVInst48 Inst>
12391244
: Pat<(i32 (OpNode (i32 GPRNoX0:$rs1), simm32_nosimm26:$imm)),
12401245
(Inst GPRNoX0:$rs1, simm32_nosimm26:$imm)>;
12411246

1247+
class QC48LdPat<PatFrag LoadOp, RVInst48 Inst>
1248+
: Pat<(i32 (LoadOp (AddLike (i32 GPR:$rs1), simm26_nosimm12:$imm26))),
1249+
(Inst GPR:$rs1, simm26_nosimm12:$imm26)>;
1250+
1251+
class QC48StPat<PatFrag StoreOp, RVInst48 Inst>
1252+
: Pat<(StoreOp (i32 GPR:$rs2), (AddLike (i32 GPR:$rs1), simm26_nosimm12:$imm26)),
1253+
(Inst GPR:$rs2, GPR:$rs1, simm26_nosimm12:$imm26)>;
1254+
12421255
/// Simple arithmetic operations
12431256

12441257
let Predicates = [HasVendorXqcilia, IsRV32] in {
@@ -1253,5 +1266,19 @@ def : PatGprNoX0Simm26NoSimm12<or, QC_E_ORI>;
12531266
def : PatGprNoX0Simm26NoSimm12<xor, QC_E_XORI>;
12541267
} // Predicates = [HasVendorXqcilia, IsRV32]
12551268

1269+
let Predicates = [HasVendorXqcilo, IsRV32], AddedComplexity = 2 in {
1270+
def : QC48LdPat<sextloadi8, QC_E_LB>;
1271+
def : QC48LdPat<extloadi8, QC_E_LBU>; // Prefer unsigned due to no c.lb in Zcb.
1272+
def : QC48LdPat<sextloadi16, QC_E_LH>;
1273+
def : QC48LdPat<extloadi16, QC_E_LH>;
1274+
def : QC48LdPat<load, QC_E_LW>;
1275+
def : QC48LdPat<zextloadi8, QC_E_LBU>;
1276+
def : QC48LdPat<zextloadi16, QC_E_LHU>;
1277+
1278+
def : QC48StPat<truncstorei8, QC_E_SB>;
1279+
def : QC48StPat<truncstorei16, QC_E_SH>;
1280+
def : QC48StPat<store, QC_E_SW>;
1281+
} // Predicates = [HasVendorXqcilo, IsRV32], AddedComplexity = 2
1282+
12561283
let Predicates = [HasVendorXqciint, IsRV32] in
12571284
def : Pat<(riscv_mileaveret_glue), (QC_C_MILEAVERET)>;

llvm/test/CodeGen/RISCV/xqcilo.ll

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s -check-prefixes=RV32I
4+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilo -verify-machineinstrs < %s \
5+
; RUN: | FileCheck %s -check-prefixes=RV32IXQCILO
6+
7+
define i32 @lb_ri(i8* %a) {
8+
; RV32I-LABEL: lb_ri:
9+
; RV32I: # %bb.0:
10+
; RV32I-NEXT: lui a1, 2
11+
; RV32I-NEXT: add a0, a0, a1
12+
; RV32I-NEXT: lb a0, 1808(a0)
13+
; RV32I-NEXT: ret
14+
;
15+
; RV32IXQCILO-LABEL: lb_ri:
16+
; RV32IXQCILO: # %bb.0:
17+
; RV32IXQCILO-NEXT: qc.e.lb a0, 10000(a0)
18+
; RV32IXQCILO-NEXT: ret
19+
%1 = getelementptr i8, i8* %a, i32 10000
20+
%2 = load i8, i8* %1
21+
%3 = sext i8 %2 to i32
22+
ret i32 %3
23+
}
24+
25+
define i32 @lbu_ri(i8* %a) {
26+
; RV32I-LABEL: lbu_ri:
27+
; RV32I: # %bb.0:
28+
; RV32I-NEXT: lui a1, 1048574
29+
; RV32I-NEXT: add a0, a0, a1
30+
; RV32I-NEXT: lbu a0, 192(a0)
31+
; RV32I-NEXT: ret
32+
;
33+
; RV32IXQCILO-LABEL: lbu_ri:
34+
; RV32IXQCILO: # %bb.0:
35+
; RV32IXQCILO-NEXT: qc.e.lbu a0, -8000(a0)
36+
; RV32IXQCILO-NEXT: ret
37+
%1 = getelementptr i8, i8* %a, i32 -8000
38+
%2 = load i8, i8* %1
39+
%3 = zext i8 %2 to i32
40+
ret i32 %3
41+
}
42+
43+
define i32 @lh_ri(i16* %a) {
44+
; RV32I-LABEL: lh_ri:
45+
; RV32I: # %bb.0:
46+
; RV32I-NEXT: lui a1, 11
47+
; RV32I-NEXT: add a0, a0, a1
48+
; RV32I-NEXT: lhu a0, -612(a0)
49+
; RV32I-NEXT: ret
50+
;
51+
; RV32IXQCILO-LABEL: lh_ri:
52+
; RV32IXQCILO: # %bb.0:
53+
; RV32IXQCILO-NEXT: qc.e.lhu a0, 44444(a0)
54+
; RV32IXQCILO-NEXT: ret
55+
%1 = getelementptr i16, i16* %a, i32 22222
56+
%2 = load i16, i16* %1
57+
%3 = zext i16 %2 to i32
58+
ret i32 %3
59+
}
60+
61+
define i32 @lhu_ri(i16* %a) {
62+
; RV32I-LABEL: lhu_ri:
63+
; RV32I: # %bb.0:
64+
; RV32I-NEXT: lui a1, 1048570
65+
; RV32I-NEXT: add a0, a0, a1
66+
; RV32I-NEXT: lhu a0, 120(a0)
67+
; RV32I-NEXT: ret
68+
;
69+
; RV32IXQCILO-LABEL: lhu_ri:
70+
; RV32IXQCILO: # %bb.0:
71+
; RV32IXQCILO-NEXT: qc.e.lhu a0, -24456(a0)
72+
; RV32IXQCILO-NEXT: ret
73+
%1 = getelementptr i16, i16* %a, i32 -12228
74+
%2 = load i16, i16* %1
75+
%3 = zext i16 %2 to i32
76+
ret i32 %3
77+
}
78+
79+
define i32 @lw_ri(i32* %a) {
80+
; RV32I-LABEL: lw_ri:
81+
; RV32I: # %bb.0:
82+
; RV32I-NEXT: addi a0, a0, 2047
83+
; RV32I-NEXT: lw a0, 1953(a0)
84+
; RV32I-NEXT: ret
85+
;
86+
; RV32IXQCILO-LABEL: lw_ri:
87+
; RV32IXQCILO: # %bb.0:
88+
; RV32IXQCILO-NEXT: qc.e.lw a0, 4000(a0)
89+
; RV32IXQCILO-NEXT: ret
90+
%1 = getelementptr i32, i32* %a, i32 1000
91+
%2 = load i32, i32* %1
92+
ret i32 %2
93+
}
94+
95+
define void @sb_ri(i8* %a, i8 %b) {
96+
; RV32I-LABEL: sb_ri:
97+
; RV32I: # %bb.0:
98+
; RV32I-NEXT: lui a2, 2
99+
; RV32I-NEXT: add a0, a0, a2
100+
; RV32I-NEXT: sb a1, 1808(a0)
101+
; RV32I-NEXT: ret
102+
;
103+
; RV32IXQCILO-LABEL: sb_ri:
104+
; RV32IXQCILO: # %bb.0:
105+
; RV32IXQCILO-NEXT: qc.e.sb a1, 10000(a0)
106+
; RV32IXQCILO-NEXT: ret
107+
%1 = getelementptr i8, i8* %a, i32 10000
108+
store i8 %b, i8* %1
109+
ret void
110+
}
111+
112+
define void @sh_ri(i16* %a, i16 %b) {
113+
; RV32I-LABEL: sh_ri:
114+
; RV32I: # %bb.0:
115+
; RV32I-NEXT: lui a2, 11
116+
; RV32I-NEXT: add a0, a0, a2
117+
; RV32I-NEXT: sh a1, -612(a0)
118+
; RV32I-NEXT: ret
119+
;
120+
; RV32IXQCILO-LABEL: sh_ri:
121+
; RV32IXQCILO: # %bb.0:
122+
; RV32IXQCILO-NEXT: qc.e.sh a1, 44444(a0)
123+
; RV32IXQCILO-NEXT: ret
124+
%1 = getelementptr i16, i16* %a, i32 22222
125+
store i16 %b, i16* %1
126+
ret void
127+
}
128+
129+
define void @sw_ri(i32* %a, i32 %b) {
130+
; RV32I-LABEL: sw_ri:
131+
; RV32I: # %bb.0:
132+
; RV32I-NEXT: addi a0, a0, 2047
133+
; RV32I-NEXT: sw a1, 1953(a0)
134+
; RV32I-NEXT: ret
135+
;
136+
; RV32IXQCILO-LABEL: sw_ri:
137+
; RV32IXQCILO: # %bb.0:
138+
; RV32IXQCILO-NEXT: qc.e.sw a1, 4000(a0)
139+
; RV32IXQCILO-NEXT: ret
140+
%1 = getelementptr i32, i32* %a, i32 1000
141+
store i32 %b, i32* %1
142+
ret void
143+
}

0 commit comments

Comments
 (0)