From: Matt Arsenault Date: Tue, 20 Jun 2017 18:28:02 +0000 (+0000) Subject: AMDGPU: Fix crash with undef vreg input operand X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cabef582f05e7460269dbb544b63a0362b87f92;p=llvm AMDGPU: Fix crash with undef vreg input operand git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305814 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/AMDGPU/SIFoldOperands.cpp b/lib/Target/AMDGPU/SIFoldOperands.cpp index e10f1ed3762..bf6b7c55a69 100644 --- a/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -470,7 +470,7 @@ static MachineOperand *getImmOrMaterializedImm(MachineRegisterInfo &MRI, return &Op; MachineInstr *Def = MRI.getVRegDef(Op.getReg()); - if (Def->isMoveImmediate()) { + if (Def && Def->isMoveImmediate()) { MachineOperand &ImmSrc = Def->getOperand(1); if (ImmSrc.isImm()) return &ImmSrc; diff --git a/test/CodeGen/AMDGPU/constant-fold-imm-immreg.mir b/test/CodeGen/AMDGPU/constant-fold-imm-immreg.mir index 62b47beb125..4d8e608c947 100644 --- a/test/CodeGen/AMDGPU/constant-fold-imm-immreg.mir +++ b/test/CodeGen/AMDGPU/constant-fold-imm-immreg.mir @@ -68,6 +68,10 @@ ret void } + define amdgpu_kernel void @undefined_vreg_operand() { + unreachable + } + declare i32 @llvm.amdgcn.workitem.id.x() #1 attributes #0 = { nounwind } @@ -856,3 +860,20 @@ body: | S_ENDPGM ... +--- +# There is only an undef use operand for %1, so there is no +# corresponding defining instruction + +name: undefined_vreg_operand +tracksRegLiveness: true +registers: + - { id: 0, class: vgpr_32, preferred-register: '' } + - { id: 1, class: vgpr_32, preferred-register: '' } + - { id: 2, class: vgpr_32, preferred-register: '' } +body: | + bb.0: + %0 = V_MOV_B32_e32 0, implicit %exec + %2 = V_XOR_B32_e64 killed %0, undef %1, implicit %exec + S_ENDPGM + +...