[llvm] e395915 - [RISCV] Verify SEW/VecPolicy immediate values
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 14 14:45:59 PDT 2022
Author: Philip Reames
Date: 2022-09-14T14:45:16-07:00
New Revision: e395915ac01ffd9b6cf743f361df7265f319a8c7
URL: https://github.com/llvm/llvm-project/commit/e395915ac01ffd9b6cf743f361df7265f319a8c7
DIFF: https://github.com/llvm/llvm-project/commit/e395915ac01ffd9b6cf743f361df7265f319a8c7.diff
LOG: [RISCV] Verify SEW/VecPolicy immediate values
Copy the asserts from the printing code, and turn them into actual verifier rules. Doing this revealed an existing bug - see 0a14551.
Differential Revision: https://reviews.llvm.org/D133869
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 2307ba5c2ee46..795dc04587a14 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -1219,6 +1219,29 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
}
}
+ const uint64_t TSFlags = Desc.TSFlags;
+ if (RISCVII::hasSEWOp(TSFlags)) {
+ unsigned OpIdx = RISCVII::getSEWOpNum(Desc);
+ uint64_t Log2SEW = MI.getOperand(OpIdx).getImm();
+ if (Log2SEW > 31) {
+ ErrInfo = "Unexpected SEW value";
+ return false;
+ }
+ unsigned SEW = Log2SEW ? 1 << Log2SEW : 8;
+ if (!RISCVVType::isValidSEW(SEW)) {
+ ErrInfo = "Unexpected SEW value";
+ return false;
+ }
+ }
+ if (RISCVII::hasVecPolicyOp(TSFlags)) {
+ unsigned OpIdx = RISCVII::getVecPolicyOpNum(Desc);
+ uint64_t Policy = MI.getOperand(OpIdx).getImm();
+ if (Policy > (RISCVII::TAIL_AGNOSTIC | RISCVII::MASK_AGNOSTIC)) {
+ ErrInfo = "Invalid Policy Value";
+ return false;
+ }
+ }
+
return true;
}
More information about the llvm-commits
mailing list