Skip to content

[RISCV] Add compress patterns for Xqcilo load/store instructions #137758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
Original file line number Diff line number Diff line change
Expand Up @@ -1323,3 +1323,36 @@ def : PatGprNoX0GprNoX0<sshlsat, QC_SHLSAT>;

let Predicates = [HasVendorXqciint, IsRV32] in
def : Pat<(riscv_mileaveret_glue), (QC_C_MILEAVERET)>;


//===----------------------------------------------------------------------===/i
// Compress Instruction tablegen backend.
//===----------------------------------------------------------------------===//

let isCompressOnly = true, Predicates = [HasVendorXqcilo, IsRV32] in {
def : CompressPat<(QC_E_LW GPRC:$rd, GPRCMem:$rs1, uimm7_lsb00:$imm),
(C_LW GPRC:$rd, GPRCMem:$rs1, uimm7_lsb00:$imm)>;
def : CompressPat<(QC_E_LW GPRNoX0:$rd, SPMem:$rs1, uimm8_lsb00:$imm),
(C_LWSP GPRNoX0:$rd, SPMem:$rs1, uimm8_lsb00:$imm)>;
def : CompressPat<(QC_E_LB GPR:$rd, GPRMem:$rs1, simm12:$imm12),
(LB GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
def : CompressPat<(QC_E_LBU GPR:$rd, GPRMem:$rs1, simm12:$imm12),
(LBU GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
def : CompressPat<(QC_E_LH GPR:$rd, GPRMem:$rs1, simm12:$imm12),
(LH GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
def : CompressPat<(QC_E_LHU GPR:$rd, GPRMem:$rs1, simm12:$imm12),
(LHU GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;
def : CompressPat<(QC_E_LW GPR:$rd, GPRMem:$rs1, simm12:$imm12),
(LW GPR:$rd, GPRMem:$rs1, simm12:$imm12)>;

def : CompressPat<(QC_E_SW GPRC:$rs2, GPRCMem:$rs1, uimm7_lsb00:$imm),
(C_SW GPRC:$rs2, GPRCMem:$rs1, uimm7_lsb00:$imm)>;
def : CompressPat<(QC_E_SW GPR:$rs2, SPMem:$rs1, uimm8_lsb00:$imm),
(C_SWSP GPR:$rs2, SPMem:$rs1, uimm8_lsb00:$imm)>;
def : CompressPat<(QC_E_SB GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
(SB GPR:$rs2, GPRMem:$rs1, simm12:$imm12)>;
def : CompressPat<(QC_E_SH GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
(SH GPR:$rs2, GPRMem:$rs1, simm12:$imm12)>;
def : CompressPat<(QC_E_SW GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
(SW GPR:$rs2, GPRMem:$rs1, simm12:$imm12)>;
} // isCompressOnly = true, Predicates = [HasVendorXqcilo, IsRV32]
38 changes: 20 additions & 18 deletions llvm/test/MC/RISCV/xqcilo-aliases-valid.s
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
# Xqcilo - Qualcomm uC Large Offset Load Store extension
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -M no-aliases -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-NOALIAS %s
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
# RUN: | llvm-objdump --mattr=+experimental-xqcilo -M no-aliases --no-print-imm-hex -d - \
# RUN: | FileCheck -check-prefix=CHECK-INST %s
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-ALIAS %s
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
# RUN: | llvm-objdump --mattr=+experimental-xqcilo --no-print-imm-hex -d - \
# RUN: | FileCheck -check-prefix=CHECK-INST %s

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


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


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


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


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


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


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


# CHECK-INST: qc.e.sw a1, 0(a0)
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0xc0,0x00,0x00]
# CHECK-NOALIAS: c.sw a1, 0(a0)
# CHECK-ALIAS: sw a1, 0(a0)
# CHECK-ENC: encoding: [0x0c,0xc1]
qc.e.sw x11, (x10)
106 changes: 80 additions & 26 deletions llvm/test/MC/RISCV/xqcilo-valid.s
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Xqcilo - Qualcomm uC Large Offset Load Store extension
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -M no-aliases -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-NOALIAS %s
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
# RUN: | llvm-objdump --mattr=+experimental-xqcilo -M no-aliases --no-print-imm-hex -d - \
# RUN: | FileCheck -check-prefix=CHECK-INST %s
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcilo -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-ALIAS %s
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcilo < %s \
# RUN: | llvm-objdump --mattr=+experimental-xqcilo --no-print-imm-hex -d - \
# RUN: | FileCheck -check-prefix=CHECK-INST %s

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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

# CHECK-INST: qc.e.sw a1, -33554432(a0)
# CHECK-ENC: encoding: [0x1f,0x60,0xb5,0xc0,0x00,0x80]
Expand All @@ -112,3 +112,57 @@ qc.e.sw x11, -33554432(x10)
# CHECK-INST: qc.e.sw a1, 33554431(a0)
# CHECK-ENC: encoding: [0x9f,0x6f,0xb5,0xfe,0xff,0x7f]
qc.e.sw x11, 33554431(x10)

# Check that compressed patterns work

# CHECK-INST: lb a1, 100(a0)
# CHECK-ENC: encoding: [0x83,0x05,0x45,0x06]
qc.e.lb x11, 100(x10)

# CHECK-INST: lbu a1, 200(a0)
# CHECK-ENC: encoding: [0x83,0x45,0x85,0x0c]
qc.e.lbu x11, 200(x10)

# CHECK-INST: lh a1, 300(a0)
# CHECK-ENC: encoding: [0x83,0x15,0xc5,0x12]
qc.e.lh x11, 300(x10)

# CHECK-INST: lhu a1, 400(a0)
# CHECK-ENC: encoding: [0x83,0x55,0x05,0x19]
qc.e.lhu x11, 400(x10)

# CHECK-INST: lw a1, 500(a0)
# CHECK-ENC: encoding: [0x83,0x25,0x45,0x1f]
qc.e.lw x11, 500(x10)

# CHECK-INST: sb a1, 600(a0)
# CHECK-ENC: encoding: [0x23,0x0c,0xb5,0x24]
qc.e.sb x11, 600(x10)

# CHECK-INST: sh a1, 700(a0)
# CHECK-ENC: encoding: [0x23,0x1e,0xb5,0x2a]
qc.e.sh x11, 700(x10)

# CHECK-INST: sw a1, 800(a0)
# CHECK-ENC: encoding: [0x23,0x20,0xb5,0x32]
qc.e.sw x11, 800(x10)

# CHECK-ALIAS: lw a1, 32(a0)
# CHECK-NOALIAS: c.lw a1, 32(a0)
# CHECK-ENC: encoding: [0x0c,0x51]
qc.e.lw x11, 32(x10)

# CHECK-ALIAS: sw a1, 124(a0)
# CHECK-NOALIAS: c.sw a1, 124(a0)
# CHECK-ENC: encoding: [0x6c,0xdd]
qc.e.sw x11, 124(x10)

# CHECK-ALIAS: lw ra, 64(sp)
# CHECK-NOALIAS: c.lwsp ra, 64(sp)
# CHECK-ENC: encoding: [0x86,0x40]
qc.e.lw x1, 64(x2)

# CHECK-ALIAS: sw a1, 252(sp)
# CHECK-NOALIAS: c.swsp a1, 252(sp)
# CHECK-ENC: encoding: [0xae,0xdf]
qc.e.sw x11, 252(x2)