Skip to content

Commit 884f738

Browse files
authored
[RISCV] Add compress patterns for Xqcilia instructions with tied-operands (#147242)
Now that the compress instruction emitter supports source instructions with tied-operands, add some patterns for such instructions in the Xqcilia extension.
1 parent a79acbd commit 884f738

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,12 +1560,18 @@ def : CompressPat<(QC_E_LI GPRNoX0:$rd, simm20_li:$imm),
15601560
} // Predicates = [HasVendorXqcili, IsRV32]
15611561

15621562
let isCompressOnly = true, Predicates = [HasVendorXqcilia, IsRV32] in {
1563+
def : CompressPat<(QC_E_ADDAI GPRNoX0:$rd, simm6nonzero:$imm),
1564+
(C_ADDI GPRNoX0:$rd, simm6nonzero:$imm)>;
15631565
def : CompressPat<(QC_E_ADDI GPRNoX0:$rs1, GPRNoX0:$rs1, simm6nonzero:$imm),
15641566
(C_ADDI GPRNoX0:$rs1, simm6nonzero:$imm)>;
1567+
def : CompressPat<(QC_E_ANDAI GPRC:$rd, simm6:$imm),
1568+
(C_ANDI GPRC:$rd, simm6:$imm)>;
15651569
def : CompressPat<(QC_E_ANDI GPRC:$rs1, GPRC:$rs1, simm6:$imm),
15661570
(C_ANDI GPRC:$rs1, simm6:$imm)>;
15671571
def : CompressPat<(QC_E_ADDI GPRNoX0:$rs1, GPRNoX0:$rs2, 0),
15681572
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1573+
def : CompressPat<(QC_E_ADDAI X2, simm10_lsb0000nonzero:$imm),
1574+
(C_ADDI16SP X2, simm10_lsb0000nonzero:$imm)>;
15691575
def : CompressPat<(QC_E_ADDI X2, X2, simm10_lsb0000nonzero:$imm),
15701576
(C_ADDI16SP X2, simm10_lsb0000nonzero:$imm)>;
15711577
} // let isCompressOnly = true, Predicates = [HasVendorXqcilia, IsRV32]

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
# RUN: | llvm-objdump --mattr=+experimental-xqcilia --no-print-imm-hex -d - \
1111
# RUN: | FileCheck -check-prefix=CHECK-INST %s
1212

13+
.option exact
14+
1315
# CHECK-INST: qc.e.addai s1, -1
1416
# CHECK-ENC: encoding: [0x9f,0x24,0xff,0xff,0xff,0xff]
1517
qc.e.addai x9, 4294967295
1618

19+
1720
# CHECK-INST: qc.e.addai s1, -2147483648
1821
# CHECK-ENC: encoding: [0x9f,0x24,0x00,0x00,0x00,0x80]
1922
qc.e.addai x9, -2147483648
@@ -32,6 +35,7 @@ qc.e.addi x10, x9, 33554431
3235
# CHECK-ENC: encoding: [0x9f,0xa4,0xff,0xff,0xff,0xff]
3336
qc.e.andai x9, 4294967295
3437

38+
3539
# CHECK-INST: qc.e.andai s1, -2147483648
3640
# CHECK-ENC: encoding: [0x9f,0xa4,0x00,0x00,0x00,0x80]
3741
qc.e.andai x9, -2147483648
@@ -83,6 +87,8 @@ qc.e.xori x10, x9, 33554431
8387

8488
# Check that compress patterns work as expected
8589

90+
.option noexact
91+
8692
# CHECK-ALIAS: addi t0, t0, 20
8793
# CHECK-NOALIAS: c.addi t0, 20
8894
# CHECK-ENC: encoding: [0xd1,0x02]
@@ -102,3 +108,18 @@ qc.e.addi x5, x6, 0
102108
# CHECK-NOALIAS: c.addi16sp sp, 48
103109
# CHECK-ENC: encoding: [0x45,0x61]
104110
qc.e.addi x2, x2, 48
111+
112+
# CHECK-ALIAS: addi s1, s1, -1
113+
# CHECK-NOALIAS: c.addi s1, -1
114+
# CHECK-ENC: encoding: [0xfd,0x14]
115+
qc.e.addai x9, 4294967295
116+
117+
# CHECK-ALIAS: addi sp, sp, 48
118+
# CHECK-NOALIAS: c.addi16sp sp, 48
119+
# CHECK-ENC: encoding: [0x45,0x61]
120+
qc.e.addai x2, 48
121+
122+
# CHECK-ALIAS: andi s1, s1, -1
123+
# CHECK-NOALIAS: c.andi s1, -1
124+
# CHECK-ENC: encoding: [0xfd,0x98]
125+
qc.e.andai x9, 4294967295

0 commit comments

Comments
 (0)