GlobalISel: Verify G_GEP

llvm-svn: 353209
This commit is contained in:
Matt Arsenault 2019-02-05 20:04:12 +00:00
parent 97bc08ae02
commit a3d0c5adaf
2 changed files with 48 additions and 0 deletions

View File

@ -1100,6 +1100,22 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
break;
}
case TargetOpcode::G_GEP: {
LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
LLT PtrTy = MRI->getType(MI->getOperand(1).getReg());
LLT OffsetTy = MRI->getType(MI->getOperand(2).getReg());
if (!DstTy.isValid() || !PtrTy.isValid() || !OffsetTy.isValid())
break;
if (!PtrTy.getScalarType().isPointer())
report("gep first operand must be a pointer", MI);
if (OffsetTy.getScalarType().isPointer())
report("gep offset operand must not be a pointer", MI);
// TODO: Is the offset allowed to be a scalar with a vector?
break;
}
case TargetOpcode::G_SEXT:
case TargetOpcode::G_ZEXT:
case TargetOpcode::G_ANYEXT:

View File

@ -0,0 +1,32 @@
#RUN: not llc -o - -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
# REQUIRES: global-isel, aarch64-registered-target
---
name: test_gep
legalized: true
regBankSelected: false
selected: false
tracksRegLiveness: true
liveins:
body: |
bb.0:
%0:_(p0) = G_IMPLICIT_DEF
%1:_(s64) = G_IMPLICIT_DEF
; CHECK: Bad machine code: Type mismatch in generic instruction
%2:_(s64) = G_GEP %0, %1
; CHECK: Bad machine code: Type mismatch in generic instruction
%3:_(p0) = G_GEP %1, %1
; CHECK: Bad machine code: gep offset operand must not be a pointer
%4:_(p0) = G_GEP %0, %0
; CHECK: Bad machine code: Type mismatch in generic instruction
%5:_(p1) = G_GEP %0, %1
; CHECK: Bad machine code: gep first operand must be a pointer
%6:_(s64) = G_GEP %1, %1
...