aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineVerifier.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-09-18 18:31:16 -0700
committerGitHub <noreply@github.com>2024-09-18 18:31:16 -0700
commit009398b3b37f7d653b4371120944f74cad934992 (patch)
treebb8926581afee0aff570be6e0f048e49a2305a64 /llvm/lib/CodeGen/MachineVerifier.cpp
parente494e2a29449a5ce7fce16b5dc1d0033b1ba69e8 (diff)
downloadllvm-009398b3b37f7d653b4371120944f74cad934992.zip
llvm-009398b3b37f7d653b4371120944f74cad934992.tar.gz
llvm-009398b3b37f7d653b4371120944f74cad934992.tar.bz2
[MachineVerifier] Improve checks for G_INSERT_SUBVECTOR. (#109209)
-Improve messages. -Remove redundant checks that are handled in generic code. -Add check that the subvector is smaller than the vector. -Add checks that subvector is smaller than the vector.
Diffstat (limited to 'llvm/lib/CodeGen/MachineVerifier.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineVerifier.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 651de06..2766420 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1710,7 +1710,6 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
}
LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
- LLT Src0Ty = MRI->getType(Src0Op.getReg());
LLT Src1Ty = MRI->getType(Src1Op.getReg());
if (!DstTy.isVector()) {
@@ -1718,33 +1717,44 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
break;
}
- if (!Src0Ty.isVector()) {
- report("First source must be a vector", MI);
+ if (!Src1Ty.isVector()) {
+ report("Second source must be a vector", MI);
break;
}
- if (!Src1Ty.isVector()) {
- report("Second source must be a vector", MI);
+ if (DstTy.getElementType() != Src1Ty.getElementType()) {
+ report("Element type of vectors must be the same", MI);
break;
}
- if (DstTy != Src0Ty) {
- report("Destination type must match the first source vector type", MI);
+ if (Src1Ty.isScalable() != DstTy.isScalable()) {
+ report("Vector types must both be fixed or both be scalable", MI);
break;
}
- if (Src0Ty.getElementType() != Src1Ty.getElementType()) {
- report("Element type of source vectors must be the same", MI);
+ if (ElementCount::isKnownGT(Src1Ty.getElementCount(),
+ DstTy.getElementCount())) {
+ report("Second source must be smaller than destination vector", MI);
break;
}
- if (IndexOp.getImm() != 0 &&
- IndexOp.getImm() % Src1Ty.getElementCount().getKnownMinValue() != 0) {
+ uint64_t Idx = IndexOp.getImm();
+ uint64_t Src1MinLen = Src1Ty.getElementCount().getKnownMinValue();
+ if (IndexOp.getImm() % Src1MinLen != 0) {
report("Index must be a multiple of the second source vector's "
"minimum vector length",
MI);
break;
}
+
+ uint64_t DstMinLen = DstTy.getElementCount().getKnownMinValue();
+ if (Idx >= DstMinLen || Idx + Src1MinLen > DstMinLen) {
+ report("Subvector type and index must not cause insert to overrun the "
+ "vector being inserted into",
+ MI);
+ break;
+ }
+
break;
}
case TargetOpcode::G_EXTRACT_SUBVECTOR: {