Skip to content

Commit e3adf6b

Browse files
authored
[RISCV] Use decodeCLUIImmOperand when disassembling C_LUI_HINT. (llvm#133789)
This correctly rejects imm==0 and prints 1048575 instead of -1. I've modified the test to only have each hex pattern once with different check lines before it. This ensures we don't have more invalid messages printed than we're checking for.
1 parent b3c7d59 commit e3adf6b

File tree

3 files changed

+6047
-2066
lines changed

3 files changed

+6047
-2066
lines changed

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,13 @@ static DecodeStatus decodeRVCInstrRdRs1ImmZero(MCInst &Inst, uint32_t Insn,
484484
uint64_t Address,
485485
const MCDisassembler *Decoder);
486486

487-
static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn,
488-
uint64_t Address,
489-
const MCDisassembler *Decoder);
487+
static DecodeStatus decodeRVCInstrRdSImm6(MCInst &Inst, uint32_t Insn,
488+
uint64_t Address,
489+
const MCDisassembler *Decoder);
490+
491+
static DecodeStatus decodeRVCInstrRdCLUIImm(MCInst &Inst, uint32_t Insn,
492+
uint64_t Address,
493+
const MCDisassembler *Decoder);
490494

491495
static DecodeStatus
492496
decodeRVCInstrRdRs1UImmLog2XLenNonZero(MCInst &Inst, uint32_t Insn,
@@ -544,18 +548,27 @@ static DecodeStatus decodeCSSPushPopchk(MCInst &Inst, uint32_t Insn,
544548
return MCDisassembler::Success;
545549
}
546550

547-
static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn,
548-
uint64_t Address,
549-
const MCDisassembler *Decoder) {
551+
static DecodeStatus decodeRVCInstrRdSImm6(MCInst &Inst, uint32_t Insn,
552+
uint64_t Address,
553+
const MCDisassembler *Decoder) {
550554
Inst.addOperand(MCOperand::createReg(RISCV::X0));
551-
uint32_t SImm6 =
555+
uint32_t Imm =
552556
fieldFromInstruction(Insn, 12, 1) << 5 | fieldFromInstruction(Insn, 2, 5);
553557
[[maybe_unused]] DecodeStatus Result =
554-
decodeSImmOperand<6>(Inst, SImm6, Address, Decoder);
558+
decodeSImmOperand<6>(Inst, Imm, Address, Decoder);
555559
assert(Result == MCDisassembler::Success && "Invalid immediate");
556560
return MCDisassembler::Success;
557561
}
558562

563+
static DecodeStatus decodeRVCInstrRdCLUIImm(MCInst &Inst, uint32_t Insn,
564+
uint64_t Address,
565+
const MCDisassembler *Decoder) {
566+
Inst.addOperand(MCOperand::createReg(RISCV::X0));
567+
uint32_t Imm =
568+
fieldFromInstruction(Insn, 12, 1) << 5 | fieldFromInstruction(Insn, 2, 5);
569+
return decodeCLUIImmOperand(Inst, Imm, Address, Decoder);
570+
}
571+
559572
static DecodeStatus
560573
decodeRVCInstrRdRs1UImmLog2XLenNonZero(MCInst &Inst, uint32_t Insn,
561574
uint64_t Address,

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,15 +629,15 @@ def C_LI_HINT : RVInst16CI<0b010, 0b01, (outs GPRX0:$rd), (ins simm6:$imm),
629629
"c.li", "$rd, $imm">,
630630
Sched<[WriteIALU]> {
631631
let Inst{11-7} = 0;
632-
let DecoderMethod = "decodeRVCInstrRdSImm";
632+
let DecoderMethod = "decodeRVCInstrRdSImm6";
633633
}
634634

635635
def C_LUI_HINT : RVInst16CI<0b011, 0b01, (outs GPRX0:$rd),
636636
(ins c_lui_imm:$imm),
637637
"c.lui", "$rd, $imm">,
638638
Sched<[WriteIALU]> {
639639
let Inst{11-7} = 0;
640-
let DecoderMethod = "decodeRVCInstrRdSImm";
640+
let DecoderMethod = "decodeRVCInstrRdCLUIImm";
641641
}
642642

643643
def C_MV_HINT : RVInst16CR<0b1000, 0b10, (outs GPRX0:$rs1), (ins GPRNoX0:$rs2),

0 commit comments

Comments
 (0)