summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2019-02-15 15:24:34 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2019-02-15 15:24:34 +0000
commit59ecdb0d8be4a84b38c3451812f6c55c10b1cc82 (patch)
tree729883adb9ee49508950a095f69989625ecc7ab9
parent4673fdc5311334da6bd1d0638e2cdb3e1424b0b5 (diff)
downloadbcm5719-llvm-59ecdb0d8be4a84b38c3451812f6c55c10b1cc82.tar.gz
bcm5719-llvm-59ecdb0d8be4a84b38c3451812f6c55c10b1cc82.zip
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
-rw-r--r--llvm/lib/CodeGen/MachineVerifier.cpp17
-rw-r--r--llvm/test/MachineVerifier/test_g_build_vector.mir50
2 files changed, 43 insertions, 24 deletions
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 280283f939f..99cbe6e653f 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: {
diff --git a/llvm/test/MachineVerifier/test_g_build_vector.mir b/llvm/test/MachineVerifier/test_g_build_vector.mir
index ad2742c4dff..6b0836952f1 100644
--- a/llvm/test/MachineVerifier/test_g_build_vector.mir
+++ b/llvm/test/MachineVerifier/test_g_build_vector.mir
@@ -1,27 +1,41 @@
-#RUN: not llc -o - -global-isel -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
+# RUN: not llc -o - -global-isel -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
# REQUIRES: aarch64-registered-target
---- |
- target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
- target triple = "aarch64-unknown-unknown"
-
- define i32 @g_build_vector() {
- ret i32 0
- }
-
-...
---
name: g_build_vector
-legalized: true
-regBankSelected: false
-selected: false
tracksRegLiveness: true
-registers:
- - { id: 0, class: _, preferred-register: '' }
liveins:
body: |
bb.0:
- ; CHECK: Bad machine code: G_BUILD_VECTOR src operands total size don't match dest size
+ %0:_(s32) = IMPLICIT_DEF
+
+ ; CHECK: Bad machine code: G_BUILD_VECTOR must produce a vector from scalar operands
+ %1:_(s32) = G_BUILD_VECTOR %0
+
+ %2:_(<2 x s32>) = IMPLICIT_DEF
+
+ ; CHECK: Bad machine code: G_BUILD_VECTOR must produce a vector from scalar operands
+ %3:_(<2 x s32>) = G_BUILD_VECTOR %2
+
+ ; CHECK: Bad machine code: G_BUILD_VECTOR must have an operand for each elemement
+ %4:_(<2 x s32>) = G_BUILD_VECTOR %0, %0, %0, %0
+
+ ; CHECK: Bad machine code: G_BUILD_VECTOR result element type must match source type
+ ; CHECK: Bad machine code: G_BUILD_VECTOR must have an operand for each elemement
+ %5:_(<4 x s16>) = G_BUILD_VECTOR %0, %0
+
+ %6:_(s16) = IMPLICIT_DEF
+
+ ; CHECK: Bad machine code: G_BUILD_VECTOR result element type must match source type
+ ; CHECK: Bad machine code: G_BUILD_VECTOR must have an operand for each elemement
+ %7:_(<2 x s32>) = G_BUILD_VECTOR %6, %6, %6, %6
+
+ %8:_(p0) = IMPLICIT_DEF
+
+ ; CHECK: Bad machine code: G_BUILD_VECTOR result element type must match source type
+ %9:_(<2 x s64>) = G_BUILD_VECTOR %8, %8
+
+ %10:_(s64) = IMPLICIT_DEF
- %0(s32) = IMPLICIT_DEF
- %1:_(<2 x s32>) = G_BUILD_VECTOR %0, %0, %0, %0
+ ; CHECK: Bad machine code: G_BUILD_VECTOR result element type must match source type
+ %11:_(<2 x p0>) = G_BUILD_VECTOR %10, %10
...
OpenPOWER on IntegriCloud