diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2019-02-15 15:24:34 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2019-02-15 15:24:34 +0000 |
commit | 59ecdb0d8be4a84b38c3451812f6c55c10b1cc82 (patch) | |
tree | 729883adb9ee49508950a095f69989625ecc7ab9 /llvm/lib/CodeGen/MachineVerifier.cpp | |
parent | 4673fdc5311334da6bd1d0638e2cdb3e1424b0b5 (diff) | |
download | llvm-59ecdb0d8be4a84b38c3451812f6c55c10b1cc82.zip llvm-59ecdb0d8be4a84b38c3451812f6c55c10b1cc82.tar.gz llvm-59ecdb0d8be4a84b38c3451812f6c55c10b1cc82.tar.bz2 |
GlobalISel: Fix inadequate verification of g_build_vector
Testing based on the total size of the elements failed to catch a few
invalid scenarios, so explicitly check the number of elements/operands
and types.
This failed to catch situations like
<4 x s16> = G_BUILD_VECTOR s32, s32 since the total size added
up. This also would fail to catch an implicit conversion between
pointers and scalars.
llvm-svn: 354139
Diffstat (limited to 'llvm/lib/CodeGen/MachineVerifier.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineVerifier.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp index 280283f..99cbe6e 100644 --- a/llvm/lib/CodeGen/MachineVerifier.cpp +++ b/llvm/lib/CodeGen/MachineVerifier.cpp @@ -1198,18 +1198,23 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) { // must match the dest vector size. LLT DstTy = MRI->getType(MI->getOperand(0).getReg()); LLT SrcEltTy = MRI->getType(MI->getOperand(1).getReg()); - if (!DstTy.isVector() || SrcEltTy.isVector()) + if (!DstTy.isVector() || SrcEltTy.isVector()) { report("G_BUILD_VECTOR must produce a vector from scalar operands", MI); + break; + } + + if (DstTy.getElementType() != SrcEltTy) + report("G_BUILD_VECTOR result element type must match source type", MI); + + if (DstTy.getNumElements() != MI->getNumOperands() - 1) + report("G_BUILD_VECTOR must have an operand for each elemement", MI); + for (unsigned i = 2; i < MI->getNumOperands(); ++i) { if (MRI->getType(MI->getOperand(1).getReg()) != MRI->getType(MI->getOperand(i).getReg())) report("G_BUILD_VECTOR source operand types are not homogeneous", MI); } - if (DstTy.getSizeInBits() != - SrcEltTy.getSizeInBits() * (MI->getNumOperands() - 1)) - report("G_BUILD_VECTOR src operands total size don't match dest " - "size.", - MI); + break; } case TargetOpcode::G_BUILD_VECTOR_TRUNC: { |