Skip to content

Commit 04cb2b3

Browse files
authored
[RISCV] Add some compress patterns for Xqci instructions (llvm#139273)
There are some patterns that have not been added that will need changes to the CompressInstEmitter. Those will be handled in later patches.
1 parent e340529 commit 04cb2b3

File tree

7 files changed

+107
-24
lines changed

7 files changed

+107
-24
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,3 +1407,33 @@ let Predicates = [HasVendorXqcibm, IsRV32] in {
14071407
def : CompressPat<(QC_EXTU GPRNoX0:$rd, GPRNoX0:$rd, uimm5ge6_plus1:$width, 0),
14081408
(QC_C_EXTU GPRNoX0:$rd, uimm5ge6_plus1:$width)>;
14091409
}
1410+
1411+
let Predicates = [HasVendorXqcibm, HasStdExtZbs, IsRV32] in {
1412+
def : CompressPat<(BSETI GPRC:$rs1, GPRC:$rs1, uimmlog2xlennonzero:$shamt),
1413+
(QC_C_BSETI GPRC:$rs1, uimmlog2xlennonzero:$shamt)>;
1414+
def : CompressPat<(BEXTI GPRC:$rs1, GPRC:$rs1, uimmlog2xlennonzero:$shamt),
1415+
(QC_C_BEXTI GPRC:$rs1, uimmlog2xlennonzero:$shamt)>;
1416+
} // Predicates = [HasVendorXqcibm, HasStdExtZbs, IsRV32]
1417+
1418+
let isCompressOnly = true, Predicates = [HasVendorXqcilb, IsRV32] in {
1419+
def : CompressPat<(QC_E_J bare_simm12_lsb0:$offset),
1420+
(C_J bare_simm12_lsb0:$offset)>;
1421+
def : CompressPat<(QC_E_JAL bare_simm12_lsb0:$offset),
1422+
(C_JAL bare_simm12_lsb0:$offset)>;
1423+
} // isCompressOnly = true, Predicates = [HasVendorXqcilb, IsRV32]
1424+
1425+
let Predicates = [HasVendorXqcili, IsRV32] in {
1426+
def : CompressPat<(QC_LI GPRNoX0:$rd, simm6:$imm),
1427+
(C_LI GPRNoX0:$rd, simm6:$imm)>;
1428+
1429+
let isCompressOnly = true in
1430+
def : CompressPat<(QC_E_LI GPRNoX0:$rd, simm6:$imm),
1431+
(C_LI GPRNoX0:$rd, simm6:$imm)>;
1432+
} // Predicates = [HasVendorXqcili, IsRV32]
1433+
1434+
let isCompressOnly = true, Predicates = [HasVendorXqcilia, IsRV32] in {
1435+
def : CompressPat<(QC_E_ADDI GPRNoX0:$rs1, GPRNoX0:$rs1, simm6nonzero:$imm),
1436+
(C_ADDI GPRNoX0:$rs1, simm6nonzero:$imm)>;
1437+
def : CompressPat<(QC_E_ANDI GPRC:$rs1, GPRC:$rs1, simm6:$imm),
1438+
(C_ANDI GPRC:$rs1, simm6:$imm)>;
1439+
} // let isCompressOnly = true, Predicates = [HasVendorXqcilia, IsRV32]

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Xqcibm - Qualcomm uC Bit Manipulation Extension
2-
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcibm -M no-aliases -show-encoding \
2+
# Zbs is needed for checking compress instructions patterns for bexti/bseti
3+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcibm,+zbs -M no-aliases -show-encoding \
34
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-NOALIAS %s
4-
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcibm < %s \
5-
# RUN: | llvm-objdump --mattr=+experimental-xqcibm -M no-aliases --no-print-imm-hex -d - \
5+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcibm,+zbs < %s \
6+
# RUN: | llvm-objdump --mattr=+experimental-xqcibm,+zbs -M no-aliases --no-print-imm-hex -d - \
67
# RUN: | FileCheck -check-prefix=CHECK-INST %s
7-
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcibm -show-encoding \
8+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcibm,+zbs -show-encoding \
89
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-ALIAS %s
9-
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcibm < %s \
10-
# RUN: | llvm-objdump --mattr=+experimental-xqcibm --no-print-imm-hex -d - \
10+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcibm,+zbs < %s \
11+
# RUN: | llvm-objdump --mattr=+experimental-xqcibm,+zbs --no-print-imm-hex -d - \
1112
# RUN: | FileCheck -check-prefix=CHECK-INST %s
1213

1314
# CHECK-INST: qc.compress2 t2, t0
@@ -110,11 +111,13 @@ qc.extdpr x1, x4, x15
110111
# CHECK-ENC: encoding: [0x0b,0x33,0x9c,0x13]
111112
qc.extdprh x6, x24, x25
112113

113-
# CHECK-INST: qc.c.bexti s1, 8
114+
# CHECK-NOALIAS: qc.c.bexti s1, 8
115+
# CHECK-ALIAS: bexti s1, s1, 8
114116
# CHECK-ENC: encoding: [0xa1,0x90]
115117
qc.c.bexti x9, 8
116118

117-
# CHECK-INST: qc.c.bseti a2, 16
119+
# CHECK-NOALIAS: qc.c.bseti a2, 16
120+
# CHECK-ALIAS: bseti a2, a2, 16
118121
# CHECK-ENC: encoding: [0x41,0x96]
119122
qc.c.bseti x12, 16
120123

@@ -123,9 +126,19 @@ qc.c.bseti x12, 16
123126
# CHECK-ENC: encoding: [0xfe,0x17]
124127
qc.c.extu x15, 32
125128

126-
# Check that compress pattern for qc.extu works
129+
# Check that compress patterns work as expected
127130

128131
# CHECK-NOALIAS: qc.c.extu a1, 11
129132
# CHECK-ALIAS: qc.extu a1, a1, 11, 0
130133
# CHECK-ENC: encoding: [0xaa,0x15]
131-
qc.extu x11, x11, 11, 0
134+
qc.extu x11, x11, 11, 0
135+
136+
# CHECK-NOALIAS: qc.c.bexti s1, 8
137+
# CHECK-ALIAS: bexti s1, s1, 8
138+
# CHECK-ENC-ZBS: encoding: [0xa1,0x90]
139+
bexti x9, x9, 8
140+
141+
# CHECK-NOALIAS: qc.c.bseti a2, 16
142+
# CHECK-ALIAS: bseti a2, a2, 16
143+
# CHECK-ENC: encoding: [0x41,0x96]
144+
bseti x12, x12, 16

llvm/test/MC/RISCV/xqcilb-relocations.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
.text
1111

12+
.option exact
13+
1214
qc.e.j foo
1315
# RELOC: R_RISCV_CUSTOM195 foo 0x0
1416
# INSTR: qc.e.j foo
@@ -33,6 +35,8 @@ qc.e.j .L1
3335
qc.e.jal .L1
3436
# INSTR:qc.e.jal .L1
3537

38+
.option noexact
39+
3640
.L1:
3741
ret
3842

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Xqcilb - Qualcomm uC Long Branch Extension
22
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilb -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-xqcilb < %s \
55
# RUN: | llvm-objdump --mattr=+experimental-xqcilb -M no-aliases --no-print-imm-hex -d - \
6-
# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
6+
# RUN: | FileCheck -check-prefixes=CHECK-OBJ,CHECK-OBJ-NOALIAS %s
77
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilb -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-xqcilb < %s \
1010
# RUN: | llvm-objdump --mattr=+experimental-xqcilb --no-print-imm-hex -d - \
11-
# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
11+
# RUN: | FileCheck -check-prefixes=CHECK-OBJ,CHECK-OBJ-ALIAS %s
1212

1313
# CHECK-INST: qc.e.j -2147483648
1414
# CHECK-OBJ: qc.e.j 0x80000000
@@ -20,7 +20,18 @@ qc.e.j -2147483648
2020
# CHECK-ENC: encoding: [0x9f,0xcc,0x0e,0xfe,0xff,0x7f]
2121
qc.e.jal 2147483640
2222

23-
# CHECK-INST: qc.e.jal -116
24-
# CHECK-OBJ: qc.e.jal 0xffffff98
25-
# CHECK-ENC: encoding: [0x9f,0xc6,0x0e,0xf8,0xff,0xff]
23+
# Check that compress patterns work as expected
24+
25+
# CHECK-NOALIAS: c.jal -116
26+
# CHECK-ALIAS: jal -116
27+
# CHECK-OBJ-NOALIAS: c.jal 0xffffff98
28+
# CHECK-OBJ-ALIAS: jal 0xffffff98
29+
# CHECK-ENC: encoding: [0x71,0x37]
2630
qc.e.jal 0xffffff8c
31+
32+
# CHECK-NOALIAS: c.j 1024
33+
# CHECK-ALIAS: j 1024
34+
# CHECK-OBJ-NOALIAS: c.j 0x40e
35+
# CHECK-OBJ-ALIAS: j 0x40e
36+
# CHECK-ENC: encoding: [0x01,0xa1]
37+
qc.e.j 1024

llvm/test/MC/RISCV/xqcili-relocations.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
.text
1111

12+
.option exact
13+
1214
qc.li x4, %qc.abs20(foo)
1315
# RELOC: R_RISCV_CUSTOM192 foo 0x0
1416
# INSTR: qc.li tp, %qc.abs20(foo)
@@ -33,6 +35,8 @@ qc.li x7, %qc.abs20(.L1)
3335
qc.e.li x6, .L1
3436
# INSTR: qc.e.li t1, .L1
3537

38+
.option noexact
39+
3640
.L1:
3741
ret
3842

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
# Xqcili - Qualcomm uC Load Large Immediate Extension
22
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcili -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

55
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcili < %s \
66
# RUN: | llvm-objdump --mattr=+experimental-xqcili -M no-aliases --no-print-imm-hex -d - \
77
# RUN: | FileCheck -check-prefix=CHECK-INST %s
88

99
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcili -show-encoding \
10-
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
10+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-ALIAS %s
1111

1212
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcili < %s \
1313
# RUN: | llvm-objdump --mattr=+experimental-xqcili --no-print-imm-hex -d - \
1414
# RUN: | FileCheck -check-prefix=CHECK-INST %s
1515

16-
# CHECK-INST: qc.e.li a0, -1
17-
# CHECK-ENC: encoding: [0x1f,0x05,0xff,0xff,0xff,0xff]
18-
qc.e.li x10, 4294967295
1916

2017
# CHECK-INST: qc.e.li a0, -2147483648
2118
# CHECK-ENC: encoding: [0x1f,0x05,0x00,0x00,0x00,0x80]
@@ -44,3 +41,15 @@ qc.li x10, 12345
4441
# CHECK-INST: qc.li a0, -12346
4542
# CHECK-ENC: encoding: [0x1b,0xf5,0xc6,0xcf]
4643
qc.li x10, -12346
44+
45+
# Check that compress patterns work as expected
46+
47+
# CHECK-ALIAS: li a0, -1
48+
# CHECK-NOALIAS: c.li a0, -1
49+
# CHECK-ENC: encoding: [0x7d,0x55]
50+
qc.e.li x10, 4294967295
51+
52+
# CHECK-ALIAS: li a0, 31
53+
# CHECK-NOALIAS: c.li a0, 31
54+
# CHECK-ENC: encoding: [0x7d,0x45]
55+
qc.li x10, 31

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Xqcilia - Qualcomm uC Large Immediate Arithmetic extension
22
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilia -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-xqcilia < %s \
55
# RUN: | llvm-objdump --mattr=+experimental-xqcilia -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-xqcilia -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-xqcilia < %s \
1010
# RUN: | llvm-objdump --mattr=+experimental-xqcilia --no-print-imm-hex -d - \
1111
# RUN: | FileCheck -check-prefix=CHECK-INST %s
@@ -80,3 +80,15 @@ qc.e.xori x10, x9, -33554432
8080
# CHECK-INST: qc.e.xori a0, s1, 33554431
8181
# CHECK-ENC: encoding: [0x1f,0xb5,0xf4,0x3f,0xff,0x7f]
8282
qc.e.xori x10, x9, 33554431
83+
84+
# Check that compress patterns work as expected
85+
86+
# CHECK-ALIAS: addi t0, t0, 20
87+
# CHECK-NOALIAS: c.addi t0, 20
88+
# CHECK-ENC: encoding: [0xd1,0x02]
89+
qc.e.addi x5, x5, 20
90+
91+
# CHECK-ALIAS: andi s1, s1, -10
92+
# CHECK-NOALIAS: c.andi s1, -10
93+
# CHECK-ENC: encoding: [0xd9,0x98]
94+
qc.e.andi x9, x9, -10

0 commit comments

Comments
 (0)