1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals
2 ; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s
3 ; RUN: opt -passes=openmp-opt -pass-remarks=openmp-opt -pass-remarks-missed=openmp-opt -disable-output < %s 2>&1 | FileCheck %s -check-prefix=CHECK-REMARKS
4 ; RUN: opt -passes=openmp-opt -pass-remarks-missed=openmp-opt -openmp-opt-max-iterations=1 -disable-output < %s 2>&1 | FileCheck %s -check-prefix=CHECK-FIXPOINT
5 ; RUN: opt -openmp-opt-disable-deglobalization -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=CHECK-DISABLED
6 target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
7 target triple = "nvptx64"
10 ; CHECK-REMARKS: remark: remove_globalization.c:4:2: Could not move globalized variable to the stack. Variable is potentially captured in call. Mark parameter as `__attribute__((noescape))` to override.
11 ; CHECK-REMARKS: remark: remove_globalization.c:2:2: Moving globalized variable to the stack.
12 ; CHECK-REMARKS: remark: remove_globalization.c:6:2: Moving globalized variable to the stack.
13 ; CHECK-REMARKS: remark: remove_globalization.c:4:2: Found thread data sharing on the GPU. Expect degraded performance due to data globalization.
14 ; CHECK-FIXPOINT: Attributor did not reach a fixpoint after 1 iterations.
17 @S = external local_unnamed_addr global i8*
19 %struct.ident_t = type { i32, i32, i32, i32, i8* }
21 declare i32 @__kmpc_target_init(%struct.ident_t*, i8, i1, i1)
22 declare void @__kmpc_target_deinit(%struct.ident_t*, i8, i1)
25 ; CHECK: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external local_unnamed_addr global i8*
27 ; CHECK-DISABLED: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external local_unnamed_addr global i8*
29 define void @kernel() {
30 ; CHECK-LABEL: define {{[^@]+}}@kernel() {
32 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i8 1, i1 false, i1 true)
33 ; CHECK-NEXT: call void @foo() #[[ATTR4:[0-9]+]]
34 ; CHECK-NEXT: call void @bar() #[[ATTR4]]
35 ; CHECK-NEXT: call void @unknown_no_openmp() #[[ATTR3:[0-9]+]]
36 ; CHECK-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i8 1, i1 true)
37 ; CHECK-NEXT: ret void
39 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@kernel() {
40 ; CHECK-DISABLED-NEXT: entry:
41 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i8 1, i1 false, i1 true)
42 ; CHECK-DISABLED-NEXT: call void @foo() #[[ATTR4:[0-9]+]]
43 ; CHECK-DISABLED-NEXT: call void @bar() #[[ATTR4]]
44 ; CHECK-DISABLED-NEXT: call void @unknown_no_openmp() #[[ATTR3:[0-9]+]]
45 ; CHECK-DISABLED-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i8 1, i1 true)
46 ; CHECK-DISABLED-NEXT: ret void
49 %0 = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i8 1, i1 true, i1 true)
52 call void @unknown_no_openmp()
53 call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i8 1, i1 true)
57 define internal void @foo() {
58 ; CHECK-LABEL: define {{[^@]+}}@foo
59 ; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
61 ; CHECK-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1
62 ; CHECK-NEXT: ret void
64 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@foo
65 ; CHECK-DISABLED-SAME: () #[[ATTR0:[0-9]+]] {
66 ; CHECK-DISABLED-NEXT: entry:
67 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1
68 ; CHECK-DISABLED-NEXT: ret void
71 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !12
72 call void @use(i8* %0)
73 call void @__kmpc_free_shared(i8* %0, i64 4)
77 define internal void @bar() {
78 ; CHECK-LABEL: define {{[^@]+}}@bar
79 ; CHECK-SAME: () #[[ATTR0]] {
81 ; CHECK-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 noundef 4) #[[ATTR4]], !dbg [[DBG8:![0-9]+]]
82 ; CHECK-NEXT: call void @share(i8* nofree writeonly [[TMP0]]) #[[ATTR5:[0-9]+]]
83 ; CHECK-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 noundef 4) #[[ATTR4]]
84 ; CHECK-NEXT: ret void
86 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@bar
87 ; CHECK-DISABLED-SAME: () #[[ATTR0]] {
88 ; CHECK-DISABLED-NEXT: entry:
89 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 noundef 4) #[[ATTR4]], !dbg [[DBG8:![0-9]+]]
90 ; CHECK-DISABLED-NEXT: call void @share(i8* nofree writeonly [[TMP0]]) #[[ATTR5:[0-9]+]]
91 ; CHECK-DISABLED-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 noundef 4) #[[ATTR4]]
92 ; CHECK-DISABLED-NEXT: ret void
95 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !13
96 call void @share(i8* %0)
97 call void @__kmpc_free_shared(i8* %0, i64 4)
101 define internal void @use(i8* %x) {
102 ; CHECK-LABEL: define {{[^@]+}}@use
103 ; CHECK-SAME: (i8* noalias nocapture nofree readnone [[X:%.*]]) #[[ATTR1:[0-9]+]] {
105 ; CHECK-NEXT: ret void
107 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@use
108 ; CHECK-DISABLED-SAME: (i8* noalias nocapture nofree readnone [[X:%.*]]) #[[ATTR1:[0-9]+]] {
109 ; CHECK-DISABLED-NEXT: entry:
110 ; CHECK-DISABLED-NEXT: ret void
116 define internal void @share(i8* %x) {
117 ; CHECK-LABEL: define {{[^@]+}}@share
118 ; CHECK-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR2:[0-9]+]] {
120 ; CHECK-NEXT: store i8* [[X]], i8** @S, align 8
121 ; CHECK-NEXT: ret void
123 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@share
124 ; CHECK-DISABLED-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR2:[0-9]+]] {
125 ; CHECK-DISABLED-NEXT: entry:
126 ; CHECK-DISABLED-NEXT: store i8* [[X]], i8** @S, align 8
127 ; CHECK-DISABLED-NEXT: ret void
130 store i8* %x, i8** @S
134 define void @unused() {
135 ; CHECK-LABEL: define {{[^@]+}}@unused() {
137 ; CHECK-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1
138 ; CHECK-NEXT: call void @use(i8* noalias readnone undef)
139 ; CHECK-NEXT: ret void
141 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@unused() {
142 ; CHECK-DISABLED-NEXT: entry:
143 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 4), !dbg [[DBG11:![0-9]+]]
144 ; CHECK-DISABLED-NEXT: call void @use(i8* noalias readnone [[TMP0]])
145 ; CHECK-DISABLED-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 4)
146 ; CHECK-DISABLED-NEXT: ret void
149 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !14
150 call void @use(i8* %0)
151 call void @__kmpc_free_shared(i8* %0, i64 4)
155 ; CHECK: declare i8* @__kmpc_alloc_shared(i64)
156 declare i8* @__kmpc_alloc_shared(i64)
158 ; CHECK: declare void @__kmpc_free_shared(i8* nocapture, i64)
159 declare void @__kmpc_free_shared(i8*, i64)
161 declare void @unknown_no_openmp() "llvm.assume"="omp_no_openmp"
164 !llvm.module.flags = !{!3, !4, !6, !7}
165 !nvvm.annotations = !{!5}
167 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
168 !1 = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c")
170 !3 = !{i32 2, !"Debug Info Version", i32 3}
171 !4 = !{i32 1, !"wchar_size", i32 4}
172 !5 = !{void ()* @kernel, !"kernel", i32 1}
173 !6 = !{i32 7, !"openmp", i32 50}
174 !7 = !{i32 7, !"openmp-device", i32 50}
175 !8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
176 !9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
177 !10 = distinct !DISubprogram(name: "unused", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
178 !11 = !DISubroutineType(types: !2)
179 !12 = !DILocation(line: 2, column: 2, scope: !8)
180 !13 = !DILocation(line: 4, column: 2, scope: !9)
181 !14 = !DILocation(line: 6, column: 2, scope: !9)
183 ; CHECK: attributes #[[ATTR0]] = { nosync nounwind }
184 ; CHECK: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn }
185 ; CHECK: attributes #[[ATTR2]] = { nofree nosync nounwind willreturn writeonly }
186 ; CHECK: attributes #[[ATTR3]] = { "llvm.assume"="omp_no_openmp" }
187 ; CHECK: attributes #[[ATTR4]] = { nounwind }
188 ; CHECK: attributes #[[ATTR5]] = { nosync nounwind writeonly }
190 ; CHECK-DISABLED: attributes #[[ATTR0]] = { nosync nounwind }
191 ; CHECK-DISABLED: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn }
192 ; CHECK-DISABLED: attributes #[[ATTR2]] = { nofree nosync nounwind willreturn writeonly }
193 ; CHECK-DISABLED: attributes #[[ATTR3]] = { "llvm.assume"="omp_no_openmp" }
194 ; CHECK-DISABLED: attributes #[[ATTR4]] = { nounwind }
195 ; CHECK-DISABLED: attributes #[[ATTR5]] = { nosync nounwind writeonly }
197 ; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
198 ; CHECK: [[META1:![0-9]+]] = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c")
199 ; CHECK: [[META2:![0-9]+]] = !{}
200 ; CHECK: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
201 ; CHECK: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
202 ; CHECK: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50}
203 ; CHECK: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
204 ; CHECK: [[META7:![0-9]+]] = !{void ()* @kernel, !"kernel", i32 1}
205 ; CHECK: [[DBG8]] = !DILocation(line: 4, column: 2, scope: !9)
206 ; CHECK: [[META9:![0-9]+]] = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
207 ; CHECK: [[META10:![0-9]+]] = !DISubroutineType(types: !2)
209 ; CHECK-DISABLED: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
210 ; CHECK-DISABLED: [[META1:![0-9]+]] = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c")
211 ; CHECK-DISABLED: [[META2:![0-9]+]] = !{}
212 ; CHECK-DISABLED: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
213 ; CHECK-DISABLED: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
214 ; CHECK-DISABLED: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50}
215 ; CHECK-DISABLED: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
216 ; CHECK-DISABLED: [[META7:![0-9]+]] = !{void ()* @kernel, !"kernel", i32 1}
217 ; CHECK-DISABLED: [[DBG8]] = !DILocation(line: 4, column: 2, scope: !9)
218 ; CHECK-DISABLED: [[META9:![0-9]+]] = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
219 ; CHECK-DISABLED: [[META10:![0-9]+]] = !DISubroutineType(types: !2)
220 ; CHECK-DISABLED: [[DBG11]] = !DILocation(line: 6, column: 2, scope: !9)