From 5a995664f07db36071a2584910c22b150a5370a3 Mon Sep 17 00:00:00 2001 From: Nicolai Haehnle Date: Mon, 23 Apr 2018 13:05:50 +0000 Subject: [PATCH] AMDGPU: Fix a corner case crash in SIOptimizeExecMasking Summary: See the new test case; this is really unlikely to happen with real code, but I ran into this while attempting to bugpoint-reduce a different issue. Change-Id: I9ade1dc1aa8fd9c4d9fc83661d7b80e310b5c4a6 Reviewers: arsenm, rampitec Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, t-tye, llvm-commits Differential Revision: https://reviews.llvm.org/D45885 llvm-svn: 330585 --- llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp | 2 +- llvm/test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp b/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp index 2dc6f27..ddf45bb 100644 --- a/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp +++ b/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp @@ -76,7 +76,7 @@ static unsigned isCopyToExec(const MachineInstr &MI) { case AMDGPU::COPY: case AMDGPU::S_MOV_B64: { const MachineOperand &Dst = MI.getOperand(0); - if (Dst.isReg() && Dst.getReg() == AMDGPU::EXEC) + if (Dst.isReg() && Dst.getReg() == AMDGPU::EXEC && MI.getOperand(1).isReg()) return MI.getOperand(1).getReg(); break; } diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll index 5c4dafa..fb79ba8 100644 --- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll +++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll @@ -74,6 +74,15 @@ main_body: ret float %f } +; GCN-LABEL: {{^}}init_unreachable: +; +; This used to crash. +define amdgpu_ps void @init_unreachable() { +main_body: + call void @llvm.amdgcn.init.exec(i64 -1) + unreachable +} + declare void @llvm.amdgcn.init.exec(i64) #1 declare void @llvm.amdgcn.init.exec.from.input(i32, i32) #1 -- 2.7.4