[PATCH] D45885: AMDGPU: Fix a corner case crash in SIOptimizeExecMasking

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 20 08:51:10 PDT 2018


nhaehnle created this revision.
nhaehnle added reviewers: arsenm, rampitec.
Herald added subscribers: t-tye, tpr, dstuttard, yaxunl, wdng, kzhuravl.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D45885

Files:
  lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
  test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll


Index: test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll
===================================================================
--- test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll
+++ test/CodeGen/AMDGPU/llvm.amdgcn.init.exec.ll
@@ -74,6 +74,15 @@
   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
 
Index: lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
===================================================================
--- lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
+++ lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
@@ -76,7 +76,7 @@
   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;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45885.143323.patch
Type: text/x-patch
Size: 1079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180420/aa525eb2/attachment-0001.bin>


More information about the llvm-commits mailing list