AMDGPU: Fix a corner case crash in SIOptimizeExecMasking
authorNicolai Haehnle <nhaehnle@gmail.com>
Mon, 23 Apr 2018 13:05:50 +0000 (13:05 +0000)
committerNicolai Haehnle <nhaehnle@gmail.com>
Mon, 23 Apr 2018 13:05:50 +0000 (13:05 +0000)
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
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll

index 2dc6f27..ddf45bb 100644 (file)
@@ -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;
   }
index 5c4dafa..fb79ba8 100644 (file)
@@ -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