Skip to content

Commit 51c2602

Browse files
authored
[RISCV] Add compress patterns for Xqcilo load/store instructions (llvm#137758)
1 parent 8f75747 commit 51c2602

File tree

3 files changed

+133
-44
lines changed

3 files changed

+133
-44
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,3 +1323,36 @@ def : PatGprNoX0GprNoX0<sshlsat, QC_SHLSAT>;
13231323

13241324
let Predicates = [HasVendorXqciint, IsRV32] in
13251325
def : Pat<(riscv_mileaveret_glue), (QC_C_MILEAVERET)>;
1326+
1327+
1328+
//===----------------------------------------------------------------------===/i
1329+
// Compress Instruction tablegen backend.
1330+
//===----------------------------------------------------------------------===//
1331+
1332+
let isCompressOnly = true, Predicates = [HasVendorXqcilo, IsRV32] in {
1333+
def : CompressPat<(QC_E_LW GPRC:$rd, GPRCMem:$rs1, uimm7_lsb00:$imm),
1334+
(C_LW GPRC:$rd, GPRCMem:$rs1, uimm7_lsb00:$imm)>;
1335+
def : CompressPat<(QC_E_LW GPRNoX0:$rd, SPMem:$rs1, uimm8_lsb00:$imm),
1336+
(C_LWSP GPRNoX0:$rd, SPMem:$rs1, uimm8_lsb00:$imm)>;
1337+
def : CompressPat<(QC_E_LB GPR:$rd, GPRMem:$rs1, simm12:$imm12),
1338+
(LB GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
1339+
def : CompressPat<(QC_E_LBU GPR:$rd, GPRMem:$rs1, simm12:$imm12),
1340+
(LBU GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
1341+
def : CompressPat<(QC_E_LH GPR:$rd, GPRMem:$rs1, simm12:$imm12),
1342+
(LH GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
1343+
def : CompressPat<(QC_E_LHU GPR:$rd, GPRMem:$rs1, simm12:$imm12),
1344+
(LHU GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
1345+
def : CompressPat<(QC_E_LW GPR:$rd, GPRMem:$rs1, simm12:$imm12),
1346+
(LW GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
1347+
1348+
def : CompressPat<(QC_E_SW GPRC:$rs2, GPRCMem:$rs1, uimm7_lsb00:$imm),
1349+
(C_SW GPRC:$rs2, GPRCMem:$rs1, uimm7_lsb00:$imm)>;
1350+
def : CompressPat<(QC_E_SW GPR:$rs2, SPMem:$rs1, uimm8_lsb00:$imm),
1351+
(C_SWSP GPR:$rs2, SPMem:$rs1, uimm8_lsb00:$imm)>;
1352+
def : CompressPat<(QC_E_SB GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
1353+
(SB GPR:$rs2, GPRMem:$rs1, simm12:$imm12)>;
1354+
def : CompressPat<(QC_E_SH GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
1355+
(SH GPR:$rs2, GPRMem:$rs1, simm12:$imm12)>;
1356+
def : CompressPat<(QC_E_SW GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
1357+
(SW GPR:$rs2, GPRMem:$rs1, simm12:$imm12)>;
1358+
} // isCompressOnly = true, Predicates = [HasVendorXqcilo, IsRV32]
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
11
# Xqcilo - Qualcomm uC Large Offset Load Store extension
22
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -M no-aliases -show-encoding \
3-
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
3+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-NOALIAS %s
44
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
55
# RUN: | llvm-objdump --mattr=+experimental-xqcilo -M no-aliases --no-print-imm-hex -d - \
66
# RUN: | FileCheck -check-prefix=CHECK-INST %s
77
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -show-encoding \
8-
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
8+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-ALIAS %s
99
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
1010
# RUN: | llvm-objdump --mattr=+experimental-xqcilo --no-print-imm-hex -d - \
1111
# RUN: | FileCheck -check-prefix=CHECK-INST %s
1212

13-
# CHECK-INST: qc.e.lb a1, 0(a0)
14-
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0x00,0x00,0x00]
13+
# CHECK-INST: lb a1, 0(a0)
14+
# CHECK-ENC: encoding: [0x83,0x05,0x05,0x00]
1515
qc.e.lb x11, (x10)
1616

1717

18-
# CHECK-INST: qc.e.lbu a1, 0(a0)
19-
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0x40,0x00,0x00]
18+
# CHECK-INST: lbu a1, 0(a0)
19+
# CHECK-ENC: encoding: [0x83,0x45,0x05,0x00]
2020
qc.e.lbu x11, (x10)
2121

2222

23-
# CHECK-INST: qc.e.lh a1, 0(a0)
24-
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0x80,0x00,0x00]
23+
# CHECK-INST: lh a1, 0(a0)
24+
# CHECK-ENC: encoding: [0x83,0x15,0x05,0x00]
2525
qc.e.lh x11, (x10)
2626

2727

28-
# CHECK-INST: qc.e.lhu a1, 0(a0)
29-
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0xc0,0x00,0x00]
28+
# CHECK-INST: lhu a1, 0(a0)
29+
# CHECK-ENC: encoding: [0x83,0x55,0x05,0x00]
3030
qc.e.lhu x11, (x10)
3131

3232

33-
# CHECK-INST: qc.e.lw a1, 0(a0)
34-
# CHECK-ENC: encoding: [0x9f,0x65,0x05,0x00,0x00,0x00]
33+
# CHECK-NOALIAS: c.lw a1, 0(a0)
34+
# CHECK-ALIAS: lw a1, 0(a0)
35+
# CHECK-ENC: encoding: [0x0c,0x41]
3536
qc.e.lw x11, (x10)
3637

3738

38-
# CHECK-INST: qc.e.sb a1, 0(a0)
39-
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0x40,0x00,0x00]
39+
# CHECK-INST: sb a1, 0(a0)
40+
# CHECK-ENC: encoding: [0x23,0x00,0xb5,0x00]
4041
qc.e.sb x11, (x10)
4142

4243

43-
# CHECK-INST: qc.e.sh a1, 0(a0)
44-
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0x80,0x00,0x00]
44+
# CHECK-INST: sh a1, 0(a0)
45+
# CHECK-ENC: encoding: [0x23,0x10,0xb5,0x00]
4546
qc.e.sh x11, (x10)
4647

4748

48-
# CHECK-INST: qc.e.sw a1, 0(a0)
49-
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0xc0,0x00,0x00]
49+
# CHECK-NOALIAS: c.sw a1, 0(a0)
50+
# CHECK-ALIAS: sw a1, 0(a0)
51+
# CHECK-ENC: encoding: [0x0c,0xc1]
5052
qc.e.sw x11, (x10)

llvm/test/MC/RISCV/xqcilo-valid.s

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Xqcilo - Qualcomm uC Large Offset Load Store extension
22
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -M no-aliases -show-encoding \
3-
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
3+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-NOALIAS %s
44
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
55
# RUN: | llvm-objdump --mattr=+experimental-xqcilo -M no-aliases --no-print-imm-hex -d - \
66
# RUN: | FileCheck -check-prefix=CHECK-INST %s
77
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -show-encoding \
8-
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
8+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-ALIAS %s
99
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
1010
# RUN: | llvm-objdump --mattr=+experimental-xqcilo --no-print-imm-hex -d - \
1111
# RUN: | FileCheck -check-prefix=CHECK-INST %s
1212

13-
# CHECK-INST: qc.e.lb a1, 12(a0)
14-
# CHECK-ENC: encoding: [0x9f,0x55,0xc5,0x00,0x00,0x00]
15-
qc.e.lb x11, 12(x10)
13+
# CHECK-INST: qc.e.lb a1, 3000(a0)
14+
# CHECK-ENC: encoding: [0x9f,0x55,0x85,0x3b,0x02,0x00]
15+
qc.e.lb x11, 3000(x10)
1616

1717
# CHECK-INST: qc.e.lb a1, -33554432(a0)
1818
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0x00,0x00,0x80]
@@ -23,9 +23,9 @@ qc.e.lb x11, -33554432(x10)
2323
qc.e.lb x11, 33554431(x10)
2424

2525

26-
# CHECK-INST: qc.e.lbu a1, 12(a0)
27-
# CHECK-ENC: encoding: [0x9f,0x55,0xc5,0x40,0x00,0x00]
28-
qc.e.lbu x11, 12(x10)
26+
# CHECK-INST: qc.e.lbu a1, 3000(a0)
27+
# CHECK-ENC: encoding: [0x9f,0x55,0x85,0x7b,0x02,0x00]
28+
qc.e.lbu x11, 3000(x10)
2929

3030
# CHECK-INST: qc.e.lbu a1, -33554432(a0)
3131
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0x40,0x00,0x80]
@@ -36,9 +36,9 @@ qc.e.lbu x11, -33554432(x10)
3636
qc.e.lbu x11, 33554431(x10)
3737

3838

39-
# CHECK-INST: qc.e.lh a1, 12(a0)
40-
# CHECK-ENC: encoding: [0x9f,0x55,0xc5,0x80,0x00,0x00]
41-
qc.e.lh x11, 12(x10)
39+
# CHECK-INST: qc.e.lh a1, 3000(a0)
40+
# CHECK-ENC: encoding: [0x9f,0x55,0x85,0xbb,0x02,0x00]
41+
qc.e.lh x11, 3000(x10)
4242

4343
# CHECK-INST: qc.e.lh a1, -33554432(a0)
4444
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0x80,0x00,0x80]
@@ -49,9 +49,9 @@ qc.e.lh x11, -33554432(x10)
4949
qc.e.lh x11, 33554431(x10)
5050

5151

52-
# CHECK-INST: qc.e.lhu a1, 12(a0)
53-
# CHECK-ENC: encoding: [0x9f,0x55,0xc5,0xc0,0x00,0x00]
54-
qc.e.lhu x11, 12(x10)
52+
# CHECK-INST: qc.e.lhu a1, 3000(a0)
53+
# CHECK-ENC: encoding: [0x9f,0x55,0x85,0xfb,0x02,0x00]
54+
qc.e.lhu x11, 3000(x10)
5555

5656
# CHECK-INST: qc.e.lhu a1, -33554432(a0)
5757
# CHECK-ENC: encoding: [0x9f,0x55,0x05,0xc0,0x00,0x80]
@@ -62,9 +62,9 @@ qc.e.lhu x11, -33554432(x10)
6262
qc.e.lhu x11, 33554431(x10)
6363

6464

65-
# CHECK-INST: qc.e.lw a1, 12(a0)
66-
# CHECK-ENC: encoding: [0x9f,0x65,0xc5,0x00,0x00,0x00]
67-
qc.e.lw x11, 12(x10)
65+
# CHECK-INST: qc.e.lw a1, 3000(a0)
66+
# CHECK-ENC: encoding: [0x9f,0x65,0x85,0x3b,0x02,0x00]
67+
qc.e.lw x11, 3000(x10)
6868

6969
# CHECK-INST: qc.e.lw a1, -33554432(a0)
7070
# CHECK-ENC: encoding: [0x9f,0x65,0x05,0x00,0x00,0x80]
@@ -75,9 +75,9 @@ qc.e.lw x11, -33554432(x10)
7575
qc.e.lw x11, 33554431(x10)
7676

7777

78-
# CHECK-INST: qc.e.sb a1, 12(a0)
79-
# CHECK-ENC: encoding: [0x1f,0x66,0xb5,0x40,0x00,0x00]
80-
qc.e.sb x11, 12(x10)
78+
# CHECK-INST: qc.e.sb a1, 3000(a0)
79+
# CHECK-ENC: encoding: [0x1f,0x6c,0xb5,0x7a,0x02,0x00]
80+
qc.e.sb x11, 3000(x10)
8181

8282
# CHECK-INST: qc.e.sb a1, -33554432(a0)
8383
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0x40,0x00,0x80]
@@ -88,9 +88,9 @@ qc.e.sb x11, -33554432(x10)
8888
qc.e.sb x11, 33554431(x10)
8989

9090

91-
# CHECK-INST: qc.e.sh a1, 12(a0)
92-
# CHECK-ENC: encoding: [0x1f,0x66,0xb5,0x80,0x00,0x00]
93-
qc.e.sh x11, 12(x10)
91+
# CHECK-INST: qc.e.sh a1, 3000(a0)
92+
# CHECK-ENC: encoding: [0x1f,0x6c,0xb5,0xba,0x02,0x00]
93+
qc.e.sh x11, 3000(x10)
9494

9595
# CHECK-INST: qc.e.sh a1, -33554432(a0)
9696
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0x80,0x00,0x80]
@@ -101,9 +101,9 @@ qc.e.sh x11, -33554432(x10)
101101
qc.e.sh x11, 33554431(x10)
102102

103103

104-
# CHECK-INST: qc.e.sw a1, 12(a0)
105-
# CHECK-ENC: encoding: [0x1f,0x66,0xb5,0xc0,0x00,0x00]
106-
qc.e.sw x11, 12(x10)
104+
# CHECK-INST: qc.e.sw a1, 3000(a0)
105+
# CHECK-ENC: encoding: [0x1f,0x6c,0xb5,0xfa,0x02,0x00]
106+
qc.e.sw x11, 3000(x10)
107107

108108
# CHECK-INST: qc.e.sw a1, -33554432(a0)
109109
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0xc0,0x00,0x80]
@@ -112,3 +112,57 @@ qc.e.sw x11, -33554432(x10)
112112
# CHECK-INST: qc.e.sw a1, 33554431(a0)
113113
# CHECK-ENC: encoding: [0x9f,0x6f,0xb5,0xfe,0xff,0x7f]
114114
qc.e.sw x11, 33554431(x10)
115+
116+
# Check that compressed patterns work
117+
118+
# CHECK-INST: lb a1, 100(a0)
119+
# CHECK-ENC: encoding: [0x83,0x05,0x45,0x06]
120+
qc.e.lb x11, 100(x10)
121+
122+
# CHECK-INST: lbu a1, 200(a0)
123+
# CHECK-ENC: encoding: [0x83,0x45,0x85,0x0c]
124+
qc.e.lbu x11, 200(x10)
125+
126+
# CHECK-INST: lh a1, 300(a0)
127+
# CHECK-ENC: encoding: [0x83,0x15,0xc5,0x12]
128+
qc.e.lh x11, 300(x10)
129+
130+
# CHECK-INST: lhu a1, 400(a0)
131+
# CHECK-ENC: encoding: [0x83,0x55,0x05,0x19]
132+
qc.e.lhu x11, 400(x10)
133+
134+
# CHECK-INST: lw a1, 500(a0)
135+
# CHECK-ENC: encoding: [0x83,0x25,0x45,0x1f]
136+
qc.e.lw x11, 500(x10)
137+
138+
# CHECK-INST: sb a1, 600(a0)
139+
# CHECK-ENC: encoding: [0x23,0x0c,0xb5,0x24]
140+
qc.e.sb x11, 600(x10)
141+
142+
# CHECK-INST: sh a1, 700(a0)
143+
# CHECK-ENC: encoding: [0x23,0x1e,0xb5,0x2a]
144+
qc.e.sh x11, 700(x10)
145+
146+
# CHECK-INST: sw a1, 800(a0)
147+
# CHECK-ENC: encoding: [0x23,0x20,0xb5,0x32]
148+
qc.e.sw x11, 800(x10)
149+
150+
# CHECK-ALIAS: lw a1, 32(a0)
151+
# CHECK-NOALIAS: c.lw a1, 32(a0)
152+
# CHECK-ENC: encoding: [0x0c,0x51]
153+
qc.e.lw x11, 32(x10)
154+
155+
# CHECK-ALIAS: sw a1, 124(a0)
156+
# CHECK-NOALIAS: c.sw a1, 124(a0)
157+
# CHECK-ENC: encoding: [0x6c,0xdd]
158+
qc.e.sw x11, 124(x10)
159+
160+
# CHECK-ALIAS: lw ra, 64(sp)
161+
# CHECK-NOALIAS: c.lwsp ra, 64(sp)
162+
# CHECK-ENC: encoding: [0x86,0x40]
163+
qc.e.lw x1, 64(x2)
164+
165+
# CHECK-ALIAS: sw a1, 252(sp)
166+
# CHECK-NOALIAS: c.swsp a1, 252(sp)
167+
# CHECK-ENC: encoding: [0xae,0xdf]
168+
qc.e.sw x11, 252(x2)

0 commit comments

Comments
 (0)