Skip to content

Commit 508a6b2

Browse files
authored
[RISCV] Use decodeUImmLog2XLenNonZeroOperand in decodeRVCInstrRdRs1UImm. NFC (#133759)
decodeUImmLog2XLenNonZeroOperand already contains the uimm5 check for RV32 so we can reuse it. This makes C_SLLI_HINT code more similar to the tblgen code for C_SLLI.
1 parent f928247 commit 508a6b2

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,10 @@ static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn,
488488
uint64_t Address,
489489
const MCDisassembler *Decoder);
490490

491-
static DecodeStatus decodeRVCInstrRdRs1UImm(MCInst &Inst, uint32_t Insn,
492-
uint64_t Address,
493-
const MCDisassembler *Decoder);
491+
static DecodeStatus
492+
decodeRVCInstrRdRs1UImmLog2XLenNonZero(MCInst &Inst, uint32_t Insn,
493+
uint64_t Address,
494+
const MCDisassembler *Decoder);
494495

495496
static DecodeStatus decodeRVCInstrRdRs2(MCInst &Inst, uint32_t Insn,
496497
uint64_t Address,
@@ -553,21 +554,16 @@ static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn,
553554
return MCDisassembler::Success;
554555
}
555556

556-
static DecodeStatus decodeRVCInstrRdRs1UImm(MCInst &Inst, uint32_t Insn,
557-
uint64_t Address,
558-
const MCDisassembler *Decoder) {
557+
static DecodeStatus
558+
decodeRVCInstrRdRs1UImmLog2XLenNonZero(MCInst &Inst, uint32_t Insn,
559+
uint64_t Address,
560+
const MCDisassembler *Decoder) {
559561
Inst.addOperand(MCOperand::createReg(RISCV::X0));
560562
Inst.addOperand(Inst.getOperand(0));
561563

562-
uint32_t UImm6 = fieldFromInstruction(Insn, 12, 1) << 5;
563-
// On RV32C, uimm[5]=1 is reserved for custom extensions.
564-
if (UImm6 != 0 && Decoder->getSubtargetInfo().hasFeature(RISCV::Feature32Bit))
565-
return MCDisassembler::Fail;
566-
UImm6 |= fieldFromInstruction(Insn, 2, 5);
567-
[[maybe_unused]] DecodeStatus Result =
568-
decodeUImmOperand<6>(Inst, UImm6, Address, Decoder);
569-
assert(Result == MCDisassembler::Success && "Invalid immediate");
570-
return MCDisassembler::Success;
564+
uint32_t UImm6 =
565+
fieldFromInstruction(Insn, 12, 1) << 5 | fieldFromInstruction(Insn, 2, 5);
566+
return decodeUImmLog2XLenNonZeroOperand(Inst, UImm6, Address, Decoder);
571567
}
572568

573569
static DecodeStatus decodeRVCInstrRdRs2(MCInst &Inst, uint32_t Insn,

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def C_SLLI_HINT : RVInst16CI<0b000, 0b10, (outs GPRX0:$rd_wb),
661661
Sched<[WriteShiftImm, ReadShiftImm]> {
662662
let Constraints = "$rd = $rd_wb";
663663
let Inst{11-7} = 0;
664-
let DecoderMethod = "decodeRVCInstrRdRs1UImm";
664+
let DecoderMethod = "decodeRVCInstrRdRs1UImmLog2XLenNonZero";
665665
}
666666

667667
def C_SLLI64_HINT : RVInst16CI<0b000, 0b10, (outs GPR:$rd_wb), (ins GPR:$rd),

0 commit comments

Comments
 (0)