GlobalISel: Verify G_EXTRACT

llvm-svn: 353759
This commit is contained in:
Matt Arsenault 2019-02-11 22:12:43 +00:00
parent f4a369596f
commit b2d245771f
3 changed files with 59 additions and 2 deletions

View File

@ -1261,6 +1261,28 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
break;
}
case TargetOpcode::G_EXTRACT: {
const MachineOperand &SrcOp = MI->getOperand(1);
if (!SrcOp.isReg()) {
report("extract source must be a register", MI);
break;
}
const MachineOperand &OffsetOp = MI->getOperand(2);
if (!OffsetOp.isImm()) {
report("extract offset must be a constant", MI);
break;
}
unsigned DstSize = MRI->getType(MI->getOperand(0).getReg()).getSizeInBits();
unsigned SrcSize = MRI->getType(SrcOp.getReg()).getSizeInBits();
if (SrcSize == DstSize)
report("extract source must be larger than result", MI);
if (DstSize + OffsetOp.getImm() > SrcSize)
report("extract reads past end of register", MI);
break;
}
default:
break;
}

View File

@ -216,12 +216,12 @@ body: |
; CHECK: [[TRUNC:%[0-9]+]]:_(<6 x s1>) = G_TRUNC [[DEF]](<6 x s32>)
; CHECK: [[EXTRACT:%[0-9]+]]:_(<5 x s1>) = G_EXTRACT [[TRUNC]](<6 x s1>), 0
; CHECK: [[ANYEXT:%[0-9]+]]:_(<5 x s16>) = G_ANYEXT [[EXTRACT]](<5 x s1>)
; CHECK: [[EXTRACT1:%[0-9]+]]:_(s16) = G_EXTRACT [[ANYEXT]](<5 x s16>), 80
; CHECK: [[EXTRACT1:%[0-9]+]]:_(s16) = G_EXTRACT [[ANYEXT]](<5 x s16>), 64
; CHECK: [[TRUNC1:%[0-9]+]]:_(s1) = G_TRUNC [[EXTRACT1]](s16)
; CHECK: [[ANYEXT1:%[0-9]+]]:_(s32) = G_ANYEXT [[TRUNC1]](s1)
; CHECK: $vgpr0 = COPY [[ANYEXT1]](s32)
%0:_(<5 x s1>) = G_IMPLICIT_DEF
%1:_(s1) = G_EXTRACT %0, 5
%1:_(s1) = G_EXTRACT %0, 4
%2:_(s32) = G_ANYEXT %1
$vgpr0 = COPY %2
...

View File

@ -0,0 +1,35 @@
# RUN: not llc -march=aarch64 -o /dev/null -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
# REQUIRES: global-isel, aarch64-registered-target
---
name: test_extract
legalized: true
regBankSelected: false
selected: false
tracksRegLiveness: true
liveins:
body: |
bb.0:
; CHECK: Bad machine code: Too few operands
%0:_(s32) = G_EXTRACT
; CHECK: Bad machine code: Too few operands
%1:_(s32) = G_EXTRACT 0
; CHECK: Bad machine code: extract source must be a register
%2:_(s32) = G_EXTRACT 0, 1
; CHECK: Bad machine code: extract offset must be a constant
%3:_(s32) = G_IMPLICIT_DEF
%4:_(s32) = G_CONSTANT i32 0
%5:_(s16) = G_EXTRACT %3, %4
; CHECK: Bad machine code: extract source must be larger than result
%6:_(s32) = G_IMPLICIT_DEF
%7:_(s32) = G_EXTRACT %6, 0
; CHECK: Bad machine code: extract reads past end of register
%8:_(s1) = G_EXTRACT %6, 32
...