1; RUN: opt -passes=openmp-opt -debug-only=openmp-opt -disable-output < %s 2>&1 | FileCheck %s
2; REQUIRES: asserts
3; ModuleID = 'single_threaded_exeuction.c'
4
5define weak void @kernel() {
6  call void @__kmpc_kernel_init(i32 512, i16 1)
7  call void @nvptx()
8  call void @amdgcn()
9  ret void
10}
11
12; CHECK-NOT: [openmp-opt] Basic block @nvptx entry is executed by a single thread.
13; CHECK: [openmp-opt] Basic block @nvptx if.then is executed by a single thread.
14; CHECK-NOT: [openmp-opt] Basic block @nvptx if.end is executed by a single thread.
15; Function Attrs: noinline
16define internal void @nvptx() {
17entry:
18  %call = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
19  %cmp = icmp eq i32 %call, 0
20  br i1 %cmp, label %if.then, label %if.end
21
22if.then:
23  call void @foo()
24  call void @bar()
25  br label %if.end
26
27if.end:
28  ret void
29}
30
31; CHECK-NOT: [openmp-opt] Basic block @amdgcn entry is executed by a single thread.
32; CHECK: [openmp-opt] Basic block @amdgcn if.then is executed by a single thread.
33; CHECK-NOT: [openmp-opt] Basic block @amdgcn if.end is executed by a single thread.
34; Function Attrs: noinline
35define internal void @amdgcn() {
36entry:
37  %call = call i32 @llvm.amdgcn.workitem.id.x()
38  %cmp = icmp eq i32 %call, 0
39  br i1 %cmp, label %if.then, label %if.end
40
41if.then:
42  call void @foo()
43  call void @bar()
44  br label %if.end
45
46if.end:
47  ret void
48}
49
50; CHECK: [openmp-opt] Basic block @foo entry is executed by a single thread.
51; Function Attrs: noinline
52define internal void @foo() {
53entry:
54  ret void
55}
56
57; CHECK: [openmp-opt] Basic block @bar.internalized entry is executed by a single thread.
58; Function Attrs: noinline
59define void @bar() {
60entry:
61  ret void
62}
63
64declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
65
66declare i32 @llvm.amdgcn.workitem.id.x()
67
68declare void @__kmpc_kernel_init(i32, i16)
69
70!llvm.dbg.cu = !{!0}
71!llvm.module.flags = !{!3, !4, !5, !6}
72!nvvm.annotations = !{!7}
73
74
75!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
76!1 = !DIFile(filename: "single_threaded_execution.c", directory: "/tmp/single_threaded_execution.c")
77!2 = !{}
78!3 = !{i32 2, !"Debug Info Version", i32 3}
79!4 = !{i32 1, !"wchar_size", i32 4}
80!5 = !{i32 7, !"openmp", i32 50}
81!6 = !{i32 7, !"openmp-device", i32 50}
82!7 = !{void ()* @kernel, !"kernel", i32 1}
83