Skip to content

Commit 7a053f3

Browse files
committed
[RISCV] Use simm8 instead of uimm8 for pli.b
This is more consistent with pli.h and pli.w which use sign extension to turn their 10 bit immediate into 16 or 32 bits. This also matches the prototype binutils patch here https://github.com/ruyisdk/riscv-binutils/commits/p-dev/
1 parent e342dcd commit 7a053f3

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
808808

809809
bool isSImm5() const { return isSImm<5>(); }
810810
bool isSImm6() const { return isSImm<6>(); }
811+
bool isSImm8() const { return isSImm<8>(); }
811812
bool isSImm10() const { return isSImm<10>(); }
812813
bool isSImm11() const { return isSImm<11>(); }
813814
bool isSImm16() const { return isSImm<16>(); }
@@ -1547,6 +1548,9 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15471548
return generateImmOutOfRangeError(
15481549
Operands, ErrorInfo, 0, (1 << 9) - 8,
15491550
"immediate must be a multiple of 8 bytes in the range");
1551+
case Match_InvalidSImm8:
1552+
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 7),
1553+
(1 << 7) - 1);
15501554
case Match_InvalidSImm10:
15511555
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 9),
15521556
(1 << 9) - 1);

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ enum OperandType : unsigned {
346346
OPERAND_SIMM5_PLUS1,
347347
OPERAND_SIMM6,
348348
OPERAND_SIMM6_NONZERO,
349+
OPERAND_SIMM8,
349350
OPERAND_SIMM10,
350351
OPERAND_SIMM10_LSB0000_NONZERO,
351352
OPERAND_SIMM11,

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
// Operand and SDNode transformation definitions.
1919
//===----------------------------------------------------------------------===//
2020

21-
def simm10 : RISCVSImmLeafOp<10>;
21+
def simm8 : RISCVSImmOp<8>;
22+
def simm10 : RISCVSImmOp<10>;
2223

2324
def SImm10UnsignedAsmOperand : SImmAsmOperand<10, "Unsigned"> {
2425
let RenderMethod = "addSImm10UnsignedOperands";
@@ -75,13 +76,13 @@ class PLUI_i<bits<7> funct7, string opcodestr>
7576

7677
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
7778
class PLI_B_i<bits<8> funct8, string opcodestr>
78-
: RVInst<(outs GPR:$rd), (ins uimm8:$uimm8), opcodestr, "$rd, $uimm8", [],
79+
: RVInst<(outs GPR:$rd), (ins simm8:$imm8), opcodestr, "$rd, $imm8", [],
7980
InstFormatOther> {
80-
bits<8> uimm8;
81+
bits<8> imm8;
8182
bits<5> rd;
8283

8384
let Inst{31-24} = funct8;
84-
let Inst{23-16} = uimm8;
85+
let Inst{23-16} = imm8;
8586
let Inst{15} = 0b0;
8687
let Inst{14-12} = 0b010;
8788
let Inst{11-7} = rd;

llvm/test/MC/RISCV/rv32p-invalid.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Imm overflow
55
pli.h a0, 0x400 # CHECK: :[[@LINE]]:11: error: immediate must be an integer in the range [-512, 511]
66
plui.h a1, 0x400 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [-512, 1023]
7-
pli.b a0, 0x200 # CHECK: :[[@LINE]]:11: error: immediate must be an integer in the range [0, 255]
7+
pli.b a0, 0x200 # CHECK: :[[@LINE]]:11: error: immediate must be an integer in the range [-128, 127]
88

99
pslli.b a6, a7, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 7]
1010
pslli.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]

llvm/test/MC/RISCV/rv32p-valid.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pli.h a5, 16
6161
# CHECK-ASM-AND-OBJ: pli.b a6, 16
6262
# CHECK-ASM: encoding: [0x1b,0x28,0x10,0xb4]
6363
pli.b a6, 16
64+
# CHECK-ASM-AND-OBJ: pli.b a6, -128
65+
# CHECK-ASM: encoding: [0x1b,0x28,0x80,0xb4]
66+
pli.b a6, -128
6467
# CHECK-ASM-AND-OBJ: psext.h.b a7, a0
6568
# CHECK-ASM: encoding: [0x9b,0x28,0x45,0xe0]
6669
psext.h.b a7, a0

llvm/test/MC/RISCV/rv64p-valid.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pli.w a5, 5
7979
# CHECK-ASM-AND-OBJ: pli.b a6, 6
8080
# CHECK-ASM: encoding: [0x1b,0x28,0x06,0xb4]
8181
pli.b a6, 6
82+
# CHECK-ASM-AND-OBJ: pli.b a6, -1
83+
# CHECK-ASM: encoding: [0x1b,0x28,0xff,0xb4]
84+
pli.b a6, -1
8285
# CHECK-ASM-AND-OBJ: psext.h.b t3, a2
8386
# CHECK-ASM: encoding: [0x1b,0x2e,0x46,0xe0]
8487
psext.h.b t3, a2

0 commit comments

Comments
 (0)