1 ; RUN: llc -mtriple=amdgcn--amdhsa -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN %s
3 ; FIXME: merge with trap.ll
5 ; An s_cbranch_execnz is required to avoid trapping if all lanes are 0
6 ; GCN-LABEL: {{^}}trap_divergent_branch:
7 ; GCN: s_and_saveexec_b64
8 ; GCN: s_cbranch_execnz [[TRAP:.LBB[0-9]+_[0-9]+]]
9 ; GCN: ; %bb.{{[0-9]+}}:
14 define amdgpu_kernel void @trap_divergent_branch(ptr addrspace(1) nocapture readonly %arg) {
15 %id = call i32 @llvm.amdgcn.workitem.id.x()
16 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %id
17 %divergent.val = load i32, ptr addrspace(1) %gep
18 %cmp = icmp eq i32 %divergent.val, 0
19 br i1 %cmp, label %bb, label %end
22 call void @llvm.trap()
29 ; GCN-LABEL: {{^}}debugtrap_divergent_branch:
30 ; GCN: s_and_saveexec_b64
31 ; GCN: s_cbranch_execz [[ENDPGM:.LBB[0-9]+_[0-9]+]]
32 ; GCN: ; %bb.{{[0-9]+}}:
34 ; GCN-NEXT: [[ENDPGM]]:
36 define amdgpu_kernel void @debugtrap_divergent_branch(ptr addrspace(1) nocapture readonly %arg) {
37 %id = call i32 @llvm.amdgcn.workitem.id.x()
38 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %id
39 %divergent.val = load i32, ptr addrspace(1) %gep
40 %cmp = icmp eq i32 %divergent.val, 0
41 br i1 %cmp, label %bb, label %end
44 call void @llvm.debugtrap()
51 declare void @llvm.trap() #0
52 declare void @llvm.debugtrap() #1
53 declare i32 @llvm.amdgcn.workitem.id.x() #2
55 attributes #0 = { nounwind noreturn }
56 attributes #1 = { nounwind }
57 attributes #2 = { nounwind readnone speculatable }