Skip to content

Commit f54f4cf

Browse files
authored
[RISCV] Add compress patterns for Xqcisync instructions (#138629)
1 parent fdbc30a commit f54f4cf

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def uimm5slist : RISCVOp<XLenVT>, ImmLeaf<XLenVT,
7575
let EncoderMethod = "getImmOpValueSlist";
7676
let DecoderMethod = "decodeUImmSlistOperand";
7777
let OperandType = "OPERAND_UIMM5_SLIST";
78+
let MCOperandPredicate = [{
79+
int64_t Imm;
80+
if (!MCOp.evaluateAsConstantImm(Imm))
81+
return false;
82+
return ((Imm == 0) || (Imm == 1) ||
83+
(Imm == 2) || (Imm == 4) ||
84+
(Imm == 8) || (Imm == 16) ||
85+
(Imm == 15) || (Imm == 31));
86+
}];
7887
}
7988

8089
def uimm10 : RISCVUImmLeafOp<10>;
@@ -1341,6 +1350,13 @@ def : Pat<(riscv_mileaveret_glue), (QC_C_MILEAVERET)>;
13411350
// Compress Instruction tablegen backend.
13421351
//===----------------------------------------------------------------------===//
13431352

1353+
let Predicates = [HasVendorXqcisync, IsRV32] in {
1354+
def : CompressPat<(QC_SYNC uimm5slist:$imm5), (QC_C_SYNC uimm5slist:$imm5)>;
1355+
def : CompressPat<(QC_SYNCR uimm5slist:$imm5), (QC_C_SYNCR uimm5slist:$imm5)>;
1356+
def : CompressPat<(QC_SYNCWL uimm5slist:$imm5), (QC_C_SYNCWL uimm5slist:$imm5)>;
1357+
def : CompressPat<(QC_SYNCWF uimm5slist:$imm5), (QC_C_SYNCWF uimm5slist:$imm5)>;
1358+
} // Predicates = [HasVendorXqcisync, IsRV32]
1359+
13441360
let isCompressOnly = true, Predicates = [HasVendorXqcilo, HasStdExtZcb, IsRV32] in {
13451361
def : CompressPat<(QC_E_LBU GPRC:$rd, GPRCMem:$rs1, uimm2:$imm),
13461362
(C_LBU GPRC:$rd, GPRCMem:$rs1, uimm2:$imm)>;

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

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Xqcisync - Qualcomm uC Sync Delay Extension
22
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcisync -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-xqcisync < %s \
55
# RUN: | llvm-objdump --mattr=+experimental-xqcisync -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-xqcisync -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-xqcisync < %s \
1010
# RUN: | llvm-objdump --mattr=+experimental-xqcisync --no-print-imm-hex -d - \
1111
# RUN: | FileCheck -check-prefix=CHECK-INST %s
@@ -14,34 +14,60 @@
1414
# CHECK-ENC: encoding: [0x2a,0x00]
1515
qc.c.delay 10
1616

17-
# CHECK-INST: qc.sync 8
18-
# CHECK-ENC: encoding: [0x13,0x30,0x80,0x10]
19-
qc.sync 8
17+
# CHECK-INST: qc.sync 9
18+
# CHECK-ENC: encoding: [0x13,0x30,0x90,0x10]
19+
qc.sync 9
2020

2121
# CHECK-INST: qc.syncr 23
2222
# CHECK-ENC: encoding: [0x13,0x30,0x70,0x21]
2323
qc.syncr 23
2424

25-
# CHECK-INST: qc.syncwf 31
26-
# CHECK-ENC: encoding: [0x13,0x30,0xf0,0x41]
27-
qc.syncwf 31
25+
# CHECK-INST: qc.syncwf 30
26+
# CHECK-ENC: encoding: [0x13,0x30,0xe0,0x41]
27+
qc.syncwf 30
2828

29-
# CHECK-INST: qc.syncwl 1
30-
# CHECK-ENC: encoding: [0x13,0x30,0x10,0x80]
31-
qc.syncwl 1
29+
# CHECK-INST: qc.syncwl 6
30+
# CHECK-ENC: encoding: [0x13,0x30,0x60,0x80]
31+
qc.syncwl 6
3232

33-
# CHECK-INST: qc.c.sync 0
33+
# CHECK-NOALIAS: qc.c.sync 0
34+
# CHECK-ALIAS: qc.sync 0
3435
# CHECK-ENC: encoding: [0x01,0x80]
3536
qc.c.sync 0
3637

37-
# CHECK-INST: qc.c.syncr 15
38+
# CHECK-NOALIAS: qc.c.syncr 15
39+
# CHECK-ALIAS: qc.syncr 15
3840
# CHECK-ENC: encoding: [0x01,0x87]
3941
qc.c.syncr 15
4042

41-
# CHECK-INST: qc.c.syncwf 31
43+
# CHECK-NOALIAS: qc.c.syncwf 31
44+
# CHECK-ALIAS: qc.syncwf 31
4245
# CHECK-ENC: encoding: [0x81,0x93]
4346
qc.c.syncwf 31
4447

45-
# CHECK-INST: qc.c.syncwl 4
48+
# CHECK-NOALIAS: qc.c.syncwl 4
49+
# CHECK-ALIAS: qc.syncwl 4
4650
# CHECK-ENC: encoding: [0x81,0x95]
4751
qc.c.syncwl 4
52+
53+
# Check that compressed patterns work
54+
55+
# CHECK-NOALIAS: qc.c.sync 8
56+
# CHECK-ALIAS: qc.sync 8
57+
# CHECK-ENC: encoding: [0x01,0x82]
58+
qc.sync 8
59+
60+
# CHECK-NOALIAS: qc.c.syncr 31
61+
# CHECK-ALIAS: qc.syncr 31
62+
# CHECK-ENC: encoding: [0x81,0x87]
63+
qc.syncr 31
64+
65+
# CHECK-NOALIAS: qc.c.syncwf 0
66+
# CHECK-ALIAS: qc.syncwf 0
67+
# CHECK-ENC: encoding: [0x01,0x90]
68+
qc.syncwf 0
69+
70+
# CHECK-NOALIAS: qc.c.syncwl 16
71+
# CHECK-ALIAS: qc.syncwl 16
72+
# CHECK-ENC: encoding: [0x81,0x96]
73+
qc.syncwl 16

0 commit comments

Comments
 (0)