Skip to content

[RISCV] Add compress patterns for QC_E_J/JAL and QC_E_LI #141561

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 2 commits into from
May 28, 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
3 changes: 2 additions & 1 deletion llvm/lib/Target/RISCV/RISCVInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ def Simm21Lsb0JALAsmOperand : BareSImmNLsb0AsmOperand<21> {
}

// A 21-bit signed immediate where the least significant bit is zero.
def simm21_lsb0_jal : Operand<OtherVT> {
def simm21_lsb0_jal : Operand<OtherVT>,
ImmLeaf<XLenVT, [{return isShiftedInt<20, 1>(Imm);}]> {
let ParserMatchClass = Simm21Lsb0JALAsmOperand;
let PrintMethod = "printBranchOperand";
let EncoderMethod = "getImmOpValueAsrN<1>";
Expand Down
12 changes: 10 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def simm16nonzero : RISCVOp<XLenVT>,
let OperandType = "OPERAND_SIMM16_NONZERO";
}

def simm20_li : RISCVOp<XLenVT> {
def simm20_li : RISCVOp<XLenVT>,
ImmLeaf<XLenVT, [{return isInt<20>(Imm);}]>{
let ParserMatchClass = SImmAsmOperand<20, "LI">;
let EncoderMethod = "getImmOpValue";
let DecoderMethod = "decodeSImmOperand<20>";
Expand Down Expand Up @@ -1514,15 +1515,22 @@ def : CompressPat<(QC_E_J bare_simm12_lsb0:$offset),
(C_J bare_simm12_lsb0:$offset)>;
def : CompressPat<(QC_E_JAL bare_simm12_lsb0:$offset),
(C_JAL bare_simm12_lsb0:$offset)>;
def : CompressPat<(QC_E_JAL simm21_lsb0_jal:$offset),
(JAL X1, simm21_lsb0_jal:$offset)>;
def : CompressPat<(QC_E_J simm21_lsb0_jal:$offset),
(JAL X0, simm21_lsb0_jal:$offset)>;
} // isCompressOnly = true, Predicates = [HasVendorXqcilb, IsRV32]

let Predicates = [HasVendorXqcili, IsRV32] in {
def : CompressPat<(QC_LI GPRNoX0:$rd, simm6:$imm),
(C_LI GPRNoX0:$rd, simm6:$imm)>;

let isCompressOnly = true in
let isCompressOnly = true in {
def : CompressPat<(QC_E_LI GPRNoX0:$rd, simm6:$imm),
(C_LI GPRNoX0:$rd, simm6:$imm)>;
def : CompressPat<(QC_E_LI GPRNoX0:$rd, simm20_li:$imm),
(QC_LI GPRNoX0:$rd, simm20_li:$imm)>;
} // isCompressOnly = true
} // Predicates = [HasVendorXqcili, IsRV32]

let isCompressOnly = true, Predicates = [HasVendorXqcilia, IsRV32] in {
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/MC/RISCV/xqcilb-valid.s
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ qc.e.jal 0xffffff8c
# CHECK-OBJ-ALIAS: j 0x40e
# CHECK-ENC: encoding: [0x01,0xa1]
qc.e.j 1024

# CHECK-NOALIAS: jal ra, 3000
# CHECK-ALIAS: jal 3000
# CHECK-OBJ-NOALIAS: jal ra, 0xbc8
# CHECK-OBJ-ALIAS: jal 0xbc8
# CHECK-ENC: encoding: [0xef,0x00,0x90,0x3b]
qc.e.jal 3000

# CHECK-NOALIAS: jal zero, -3000
# CHECK-ALIAS: j -3000
# CHECK-OBJ-NOALIAS: jal zero, 0xfffff45c
# CHECK-OBJ-ALIAS: j 0xfffff45c
# CHECK-ENC: encoding: [0x6f,0xf0,0x8f,0xc4]
qc.e.j -3000
5 changes: 5 additions & 0 deletions llvm/test/MC/RISCV/xqcili-valid.s
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ qc.e.li x10, 4294967295
# CHECK-NOALIAS: c.li a0, 31
# CHECK-ENC: encoding: [0x7d,0x45]
qc.li x10, 31

# CHECK-ALIAS: li a0, 4294
# CHECK-NOALIAS: qc.li a0, 4294
# CHECK-ENC: encoding: [0x1b,0x05,0xc6,0x10]
qc.e.li x10, 4294