From: Philip Reames Date: Thu, 15 Sep 2022 19:47:58 +0000 (-0700) Subject: [RISCV] Verify VL operand on instructions if present X-Git-Tag: upstream/17.0.6~33411 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32cfafddb1c584dc94f0e9943f7a550b8e9b08a0;p=platform%2Fupstream%2Fllvm.git [RISCV] Verify VL operand on instructions if present These should only be immediate values or GPR registers. Differential Revision: https://reviews.llvm.org/D133953 --- diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp index a98bd5a..e205a89 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -1216,6 +1216,21 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI, } const uint64_t TSFlags = Desc.TSFlags; + if (RISCVII::hasVLOp(TSFlags)) { + const MachineOperand &Op = MI.getOperand(RISCVII::getVLOpNum(Desc)); + if (!Op.isImm() && !Op.isReg()) { + ErrInfo = "Invalid operand type for VL operand"; + return false; + } + if (Op.isReg() && Op.getReg() != RISCV::NoRegister) { + const MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo(); + auto *RC = MRI.getRegClass(Op.getReg()); + if (!RISCV::GPRRegClass.hasSubClassEq(RC)) { + ErrInfo = "Invalid register class for VL operand"; + return false; + } + } + } if (RISCVII::hasSEWOp(TSFlags)) { unsigned OpIdx = RISCVII::getSEWOpNum(Desc); uint64_t Log2SEW = MI.getOperand(OpIdx).getImm();