[llvm] 32cfafd - [RISCV] Verify VL operand on instructions if present
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 13:07:01 PDT 2022
Author: Philip Reames
Date: 2022-09-15T13:06:52-07:00
New Revision: 32cfafddb1c584dc94f0e9943f7a550b8e9b08a0
URL: https://github.com/llvm/llvm-project/commit/32cfafddb1c584dc94f0e9943f7a550b8e9b08a0
DIFF: https://github.com/llvm/llvm-project/commit/32cfafddb1c584dc94f0e9943f7a550b8e9b08a0.diff
LOG: [RISCV] Verify VL operand on instructions if present
These should only be immediate values or GPR registers.
Differential Revision: https://reviews.llvm.org/D133953
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index a98bd5acf896..e205a8980b0c 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();
More information about the llvm-commits
mailing list