Skip to content

Commit 7cd6711

Browse files
committed
Add back SImm10 for non-u load instructions. Add a test showing plui.h/w prints differently, remove non-objdump test for instruction string to make test work.
1 parent fa5dd24 commit 7cd6711

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

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

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

810810
bool isSImm5() const { return isSImm<5>(); }
811811
bool isSImm6() const { return isSImm<6>(); }
812+
bool isSImm10() const { return isSImm<10>(); }
812813
bool isSImm11() const { return isSImm<11>(); }
813814
bool isSImm16() const { return isSImm<16>(); }
814815
bool isSImm26() const { return isSImm<26>(); }
@@ -1540,6 +1541,9 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15401541
return generateImmOutOfRangeError(
15411542
Operands, ErrorInfo, 0, (1 << 9) - 8,
15421543
"immediate must be a multiple of 8 bytes in the range");
1544+
case Match_InvalidSImm10:
1545+
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 9),
1546+
(1 << 9) - 1);
15431547
case Match_InvalidSImm10Unsigned:
15441548
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 9),
15451549
(1 << 10) - 1);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ enum OperandType : unsigned {
336336
OPERAND_SIMM5_PLUS1,
337337
OPERAND_SIMM6,
338338
OPERAND_SIMM6_NONZERO,
339+
OPERAND_SIMM10,
339340
OPERAND_SIMM10_UNSIGNED,
340341
OPERAND_SIMM10_LSB0000_NONZERO,
341342
OPERAND_SIMM11,

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

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

21+
def simm10 : RISCVSImmLeafOp<10>;
22+
2123
// A 10-bit signed immediate allowing range [-512, 1023]
2224
// but will decode to [-512, 511].
2325
def simm10_unsigned : RISCVOp {
@@ -38,14 +40,15 @@ def simm10_unsigned : RISCVOp {
3840
//===----------------------------------------------------------------------===//
3941

4042
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
41-
class RVPUnaryImm10<bits<7> funct7, string opcodestr>
42-
: RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins simm10_unsigned:$simm10u),
43-
opcodestr, "$rd, $simm10u"> {
44-
bits<10> simm10u;
43+
class RVPUnaryImm10<bits<7> funct7, string opcodestr,
44+
DAGOperand TyImm10 = simm10>
45+
: RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins TyImm10:$imm10),
46+
opcodestr, "$rd, $imm10"> {
47+
bits<10> imm10;
4548

4649
let Inst{31-25} = funct7;
47-
let Inst{24-16} = simm10u{8-0};
48-
let Inst{15} = simm10u{9};
50+
let Inst{24-16} = imm10{8-0};
51+
let Inst{15} = imm10{9};
4952
}
5053

5154
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
@@ -155,7 +158,6 @@ def PSEXT_W_H : RVPUnaryWUF<0b01, 0b00101, "psext.w.h">;
155158
} // Predicates = [HasStdExtP, IsRV64]
156159

157160
let Predicates = [HasStdExtP] in
158-
def PLUI_H : RVPUnaryImm10<0b1111000, "plui.h">;
161+
def PLUI_H : RVPUnaryImm10<0b1111000, "plui.h", simm10_unsigned>;
159162
let Predicates = [HasStdExtP, IsRV64] in
160-
def PLUI_W : RVPUnaryImm10<0b1111001, "plui.w">;
161-
163+
def PLUI_W : RVPUnaryImm10<0b1111001, "plui.w", simm10_unsigned>;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
# Imm overflow
55
pli.h a0, 0x400
6+
# CHECK-ERROR: immediate must be an integer in the range [-512, 511]
7+
plui.h a1, 0x400
68
# CHECK-ERROR: immediate must be an integer in the range [-512, 1023]
79
pli.b a0, 0x200
810
# CHECK-ERROR: immediate must be an integer in the range [0, 255]

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-p -M no-aliases -show-encoding \
2-
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
33
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-p < %s \
44
# RUN: | llvm-objdump --mattr=+experimental-p -M no-aliases -d -r --no-print-imm-hex - \
55
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
@@ -73,3 +73,6 @@ psabs.b t0, t1
7373
# CHECK-ASM-AND-OBJ: plui.h gp, 32
7474
# CHECK-ASM: encoding: [0x9b,0x21,0x20,0xf0]
7575
plui.h gp, 32
76+
# CHECK-ASM-AND-OBJ: plui.h gp, -412
77+
# CHECK-ASM: encoding: [0x9b,0xa1,0x64,0xf0]
78+
plui.h gp, 612

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
# Imm overflow
55
pli.h a0, 0x400
6+
# CHECK-ERROR: immediate must be an integer in the range [-512, 511]
7+
plui.h a1, 0x400
68
# CHECK-ERROR: immediate must be an integer in the range [-512, 1023]
79
pli.w a1, -0x201
8-
# CHECK-ERROR: immediate must be an integer in the range [-512, 1023]
10+
# CHECK-ERROR: immediate must be an integer in the range [-512, 511]
911

1012
pslli.b a6, a7, 100
1113
# CHECK-ERROR: immediate must be an integer in the range [0, 7]

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-p -M no-aliases -show-encoding \
2-
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
33
# RUN: llvm-mc -filetype=obj --triple=riscv64 -mattr=+experimental-p < %s \
44
# RUN: | llvm-objdump --triple=riscv64 --mattr=+experimental-p -M no-aliases --no-print-imm-hex -d -r - \
55
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
@@ -97,6 +97,12 @@ psabs.b a0, s2
9797
# CHECK-ASM-AND-OBJ: plui.h s2, 4
9898
# CHECK-ASM: encoding: [0x1b,0x29,0x04,0xf0]
9999
plui.h s2, 4
100+
# CHECK-ASM-AND-OBJ: plui.h gp, -412
101+
# CHECK-ASM: encoding: [0x9b,0xa1,0x64,0xf0]
102+
plui.h gp, 612
100103
# CHECK-ASM-AND-OBJ: plui.w a2, 1
101104
# CHECK-ASM: encoding: [0x1b,0x26,0x01,0xf2]
102105
plui.w a2, 1
106+
# CHECK-ASM-AND-OBJ: plui.w a2, -1
107+
# CHECK-ASM: encoding: [0x1b,0xa6,0xff,0xf3]
108+
plui.w a2, 1023

0 commit comments

Comments
 (0)