Skip to content

Commit 0d5b680

Browse files
committed
Change simm10 to simm10_unsigned to handle extended range for PLUI
1 parent 82921ce commit 0d5b680

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ 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>(); }
813812
bool isSImm11() const { return isSImm<11>(); }
814813
bool isSImm16() const { return isSImm<16>(); }
815814
bool isSImm26() const { return isSImm<26>(); }
@@ -909,6 +908,8 @@ struct RISCVOperand final : public MCParsedAsmOperand {
909908
VK == RISCVMCExpr::VK_QC_ABS20;
910909
}
911910

911+
bool isSImm10Unsigned() const { return isSImm<10>() || isUImm<10>(); }
912+
912913
bool isUImm20LUI() const {
913914
if (!isImm())
914915
return false;
@@ -1539,9 +1540,9 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15391540
return generateImmOutOfRangeError(
15401541
Operands, ErrorInfo, 0, (1 << 9) - 8,
15411542
"immediate must be a multiple of 8 bytes in the range");
1542-
case Match_InvalidSImm10:
1543+
case Match_InvalidSImm10Unsigned:
15431544
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 9),
1544-
(1 << 9) - 1);
1545+
(1 << 10) - 1);
15451546
case Match_InvalidUImm10Lsb00NonZero:
15461547
return generateImmOutOfRangeError(
15471548
Operands, ErrorInfo, 4, (1 << 10) - 4,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ enum OperandType : unsigned {
336336
OPERAND_SIMM5_PLUS1,
337337
OPERAND_SIMM6,
338338
OPERAND_SIMM6_NONZERO,
339-
OPERAND_SIMM10,
339+
OPERAND_SIMM10_UNSIGNED,
340340
OPERAND_SIMM10_LSB0000_NONZERO,
341341
OPERAND_SIMM11,
342342
OPERAND_SIMM12,

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

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

21-
def simm10 : RISCVSImmLeafOp<10>;
21+
// A 10-bit signed immediate allowing range [-512, 1023]
22+
// but will decode to [-512, 511].
23+
def simm10_unsigned : RISCVOp {
24+
let ParserMatchClass = SImmAsmOperand<10, "Unsigned">;
25+
let EncoderMethod = "getImmOpValue";
26+
let DecoderMethod = "decodeSImmOperand<10>";
27+
let OperandType = "OPERAND_SIMM10_UNSIGNED";
28+
let MCOperandPredicate = [{
29+
int64_t Imm;
30+
if (!MCOp.evaluateAsConstantImm(Imm))
31+
return false;
32+
return isInt<10>(Imm) || isUInt<10>(Imm);
33+
}];
34+
}
2235

2336
//===----------------------------------------------------------------------===//
2437
// Instruction class templates
2538
//===----------------------------------------------------------------------===//
2639

2740
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
2841
class RVPUnaryImm10<bits<7> funct7, string opcodestr>
29-
: RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins simm10:$simm10),
30-
opcodestr, "$rd, $simm10"> {
31-
bits<10> simm10;
42+
: RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins simm10_unsigned:$simm10u),
43+
opcodestr, "$rd, $simm10u"> {
44+
bits<10> simm10u;
3245

3346
let Inst{31-25} = funct7;
34-
let Inst{24-16} = simm10{8-0};
35-
let Inst{15} = simm10{9};
47+
let Inst{24-16} = simm10u{8-0};
48+
let Inst{15} = simm10u{9};
3649
}
3750

3851
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Imm overflow
55
pli.h a0, 0x400
6-
# CHECK-ERROR: immediate must be an integer in the range [-512, 511]
6+
# CHECK-ERROR: immediate must be an integer in the range [-512, 1023]
77
pli.b a0, 0x200
88
# CHECK-ERROR: immediate must be an integer in the range [0, 255]
99

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

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

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

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

0 commit comments

Comments
 (0)