Skip to content

Commit 152fcf6

Browse files
authored
[RISCV] Add validation of SPIMM for cm.push/pop. (#84989)
This checks the immediate is a multiple of 16 bytes.
1 parent f908135 commit 152fcf6

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ enum OperandType : unsigned {
297297
OPERAND_RVKRNUM_0_7,
298298
OPERAND_RVKRNUM_1_10,
299299
OPERAND_RVKRNUM_2_14,
300-
OPERAND_LAST_RISCV_IMM = OPERAND_RVKRNUM_2_14,
300+
OPERAND_SPIMM,
301+
OPERAND_LAST_RISCV_IMM = OPERAND_SPIMM,
301302
// Operand is either a register or uimm5, this is used by V extension pseudo
302303
// instructions to represent a value that be passed as AVL to either vsetvli
303304
// or vsetivli.

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,9 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
20502050
case RISCVOp::OPERAND_RVKRNUM_2_14:
20512051
Ok = Imm >= 2 && Imm <= 14;
20522052
break;
2053+
case RISCVOp::OPERAND_SPIMM:
2054+
Ok = (Imm & 0xf) == 0;
2055+
break;
20532056
}
20542057
if (!Ok) {
20552058
ErrInfo = "Invalid immediate";

llvm/lib/Target/RISCV/RISCVInstrInfoZc.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ def rlist : Operand<OtherVT> {
7171
}];
7272
}
7373

74-
def stackadj : Operand<OtherVT> {
74+
def stackadj : RISCVOp<OtherVT> {
7575
let ParserMatchClass = StackAdjAsmOperand;
7676
let PrintMethod = "printStackAdj";
7777
let DecoderMethod = "decodeZcmpSpimm";
78+
let OperandType = "OPERAND_SPIMM";
7879
let MCOperandPredicate = [{
7980
int64_t Imm;
8081
if (!MCOp.evaluateAsConstantImm(Imm))
@@ -83,10 +84,11 @@ def stackadj : Operand<OtherVT> {
8384
}];
8485
}
8586

86-
def negstackadj : Operand<OtherVT> {
87+
def negstackadj : RISCVOp<OtherVT> {
8788
let ParserMatchClass = NegStackAdjAsmOperand;
8889
let PrintMethod = "printNegStackAdj";
8990
let DecoderMethod = "decodeZcmpSpimm";
91+
let OperandType = "OPERAND_SPIMM";
9092
let MCOperandPredicate = [{
9193
int64_t Imm;
9294
if (!MCOp.evaluateAsConstantImm(Imm))

0 commit comments

Comments
 (0)