Skip to content

Commit e1e65a4

Browse files
authored
[RISCV] Fix GPRPairNoX0 Disassembly (#158001)
Both GPRPair and GPRPairNoX0 were using the same decoder before this change, which meant that GPRPairNoX0 would disassemble zeroes to the `X0_Pair`. This ensures the NoX0 decoder correctly fails to decode zeroes.
1 parent 89e32ac commit e1e65a4

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ static DecodeStatus DecodeGPRPairRegisterClass(MCInst &Inst, uint32_t RegNo,
255255
return MCDisassembler::Success;
256256
}
257257

258+
static DecodeStatus
259+
DecodeGPRPairNoX0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address,
260+
const MCDisassembler *Decoder) {
261+
if (RegNo == 0)
262+
return MCDisassembler::Fail;
263+
264+
return DecodeGPRPairRegisterClass(Inst, RegNo, Address, Decoder);
265+
}
266+
258267
static DecodeStatus DecodeGPRPairCRegisterClass(MCInst &Inst, uint32_t RegNo,
259268
uint64_t Address,
260269
const MCDisassembler *Decoder) {

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ let RegAltNameIndices = [ABIRegAltName] in {
358358
}
359359
}
360360

361-
let RegInfos = XLenPairRI, CopyCost = 2,
362-
DecoderMethod = "DecodeGPRPairRegisterClass" in {
361+
let RegInfos = XLenPairRI, CopyCost = 2 in {
363362
def GPRPair : RISCVRegisterClass<[XLenPairVT, XLenPairFVT], 64, (add
364363
X10_X11, X12_X13, X14_X15, X16_X17,
365364
X6_X7,
@@ -370,12 +369,11 @@ def GPRPair : RISCVRegisterClass<[XLenPairVT, XLenPairFVT], 64, (add
370369
)>;
371370

372371
def GPRPairNoX0 : RISCVRegisterClass<[XLenPairVT, XLenPairFVT], 64, (sub GPRPair, X0_Pair)>;
373-
} // let RegInfos = XLenPairRI, DecoderMethod = "DecodeGPRPairRegisterClass"
374372

375-
let RegInfos = XLenPairRI, CopyCost = 2 in
376373
def GPRPairC : RISCVRegisterClass<[XLenPairVT, XLenPairFVT], 64, (add
377374
X10_X11, X12_X13, X14_X15, X8_X9
378375
)>;
376+
} // let RegInfos = XLenPairRI, CopyCost = 2
379377

380378
//===----------------------------------------------------------------------===//
381379
// Floating Point registers
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# RUN: not llvm-mc -disassemble -triple=riscv32 -mattr=+zclsd -M no-aliases %s \
2+
# RUN: | FileCheck -check-prefixes=CHECK %s
3+
4+
5+
[0x00,0x00]
6+
# CHECK: unimp
7+
8+
[0x52,0x70]
9+
# CHECK-NOT: c.ldsp zero, {{[0-9]+}}(sp)
10+
11+
[0x00,0x00]
12+
# CHECK: unimp

0 commit comments

Comments
 (0)