1; RUN: opt -passes=openmp-opt -pass-remarks-analysis=openmp-opt -disable-output < %s 2>&1 | FileCheck %s
2; ModuleID = 'declare_target_codegen_globalization.cpp'
3source_filename = "declare_target_codegen_globalization.cpp"
4target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
5target triple = "nvptx64-nvidia-cuda"
6
7%struct.ident_t = type { i32, i32, i32, i32, i8* }
8%struct._globalized_locals_ty = type { [32 x i32] }
9
10@0 = private unnamed_addr constant [56 x i8] c";declare_target_codegen_globalization.cpp;maini1;17;1;;\00", align 1
11@1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 1, i32 0, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @0, i32 0, i32 0) }, align 8
12@__omp_offloading_801_3022563__Z6maini1v_l17_exec_mode = weak constant i8 0
13@llvm.compiler.used = appending global [1 x i8*] [i8* @__omp_offloading_801_3022563__Z6maini1v_l17_exec_mode], section "llvm.metadata"
14
15; CHECK: remark: declare_target_codegen_globalization.cpp:17:1: Found thread data sharing on the GPU. Expect degraded performance due to data globalization.
16; CHECK: remark: declare_target_codegen_globalization.cpp:10:1: Found thread data sharing on the GPU. Expect degraded performance due to data globalization.
17
18; Function Attrs: norecurse nounwind
19define weak void @__omp_offloading_801_3022563__Z6maini1v_l17(i32* nonnull align 4 dereferenceable(4) %a) local_unnamed_addr #0 !dbg !10 {
20entry:
21  %nvptx_num_threads = tail call i32 @llvm.nvvm.read.ptx.sreg.ntid.x(), !dbg !12, !range !13
22  tail call void @__kmpc_spmd_kernel_init(i32 %nvptx_num_threads, i16 1, i16 0) #4, !dbg !12
23  tail call void @__kmpc_data_sharing_init_stack_spmd() #4, !dbg !12
24  %0 = tail call i32 @__kmpc_global_thread_num(%struct.ident_t* nonnull @1)
25  %1 = tail call i8 @__kmpc_is_spmd_exec_mode() #4
26  %.not.i.i = icmp eq i8 %1, 0
27  br i1 %.not.i.i, label %.non-spmd2.i.i, label %__omp_outlined__.exit
28
29.non-spmd2.i.i:                                   ; preds = %entry
30  %2 = tail call i8* @__kmpc_data_sharing_coalesced_push_stack(i64 128, i16 0) #4, !dbg !12
31  tail call void @__kmpc_data_sharing_pop_stack(i8* %2) #4, !dbg !14
32  br label %__omp_outlined__.exit, !dbg !14
33
34__omp_outlined__.exit:                            ; preds = %entry, %.non-spmd2.i.i
35  tail call void @__kmpc_spmd_kernel_deinit_v2(i16 1) #4, !dbg !19
36  ret void, !dbg !20
37}
38
39; Function Attrs: nounwind readnone
40declare i32 @llvm.nvvm.read.ptx.sreg.ntid.x() #1
41
42declare void @__kmpc_spmd_kernel_init(i32, i16, i16) local_unnamed_addr
43
44declare void @__kmpc_data_sharing_init_stack_spmd() local_unnamed_addr
45
46; Function Attrs: norecurse nounwind readonly
47define hidden i32 @_Z3fooRi(i32* nocapture nonnull readonly align 4 dereferenceable(4) %a) local_unnamed_addr #2 !dbg !21 {
48entry:
49  %0 = load i32, i32* %a, align 4, !dbg !22, !tbaa !23
50  ret i32 %0, !dbg !27
51}
52
53; Function Attrs: nounwind
54define hidden i32 @_Z3barv() local_unnamed_addr #3 !dbg !15 {
55entry:
56  %a1 = alloca i32, align 4
57  %0 = tail call i8 @__kmpc_is_spmd_exec_mode() #4
58  %.not = icmp eq i8 %0, 0
59  br i1 %.not, label %.non-spmd, label %.exit
60
61.non-spmd:                                        ; preds = %entry
62  %1 = tail call i8* @__kmpc_data_sharing_push_stack(i64 128, i16 0) #4, !dbg !31
63  %2 = bitcast i8* %1 to %struct._globalized_locals_ty*
64  br label %.exit
65
66.exit:                                            ; preds = %entry, %.non-spmd
67  %_select_stack = phi %struct._globalized_locals_ty* [ %2, %.non-spmd ], [ null, %entry ]
68  %nvptx_tid = tail call i32 @llvm.nvvm.read.ptx.sreg.tid.x(), !range !28
69  %nvptx_lane_id = and i32 %nvptx_tid, 31
70  %3 = zext i32 %nvptx_lane_id to i64
71  %4 = getelementptr inbounds %struct._globalized_locals_ty, %struct._globalized_locals_ty* %_select_stack, i64 0, i32 0, i64 %3
72  %5 = select i1 %.not, i32* %4, i32* %a1
73  %6 = load i32, i32* %5, align 4, !dbg !29, !tbaa !23
74  br i1 %.not, label %.non-spmd2, label %.exit3, !dbg !31
75
76.non-spmd2:                                       ; preds = %.exit
77  %7 = bitcast %struct._globalized_locals_ty* %_select_stack to i8*, !dbg !31
78  tail call void @__kmpc_data_sharing_pop_stack(i8* %7) #4, !dbg !31
79  br label %.exit3, !dbg !31
80
81.exit3:                                           ; preds = %.non-spmd2, %.exit
82  ret i32 %6, !dbg !31
83}
84
85declare i8 @__kmpc_is_spmd_exec_mode() local_unnamed_addr
86
87declare i8* @__kmpc_data_sharing_coalesced_push_stack(i64, i16) local_unnamed_addr
88
89declare i8* @__kmpc_data_sharing_push_stack(i64, i16) local_unnamed_addr
90
91; Function Attrs: nounwind readnone
92declare i32 @llvm.nvvm.read.ptx.sreg.tid.x() #1
93
94declare void @__kmpc_data_sharing_pop_stack(i8*) local_unnamed_addr
95
96; Function Attrs: nounwind
97declare i32 @__kmpc_global_thread_num(%struct.ident_t*) local_unnamed_addr #4
98
99declare void @__kmpc_spmd_kernel_deinit_v2(i16) local_unnamed_addr
100
101attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_35" "target-features"="+ptx32,+sm_35" "unsafe-fp-math"="false" "use-soft-float"="false" }
102attributes #1 = { nounwind readnone }
103attributes #2 = { norecurse nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_35" "target-features"="+ptx32,+sm_35" "unsafe-fp-math"="false" "use-soft-float"="false" }
104attributes #3 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_35" "target-features"="+ptx32,+sm_35" "unsafe-fp-math"="false" "use-soft-float"="false" }
105attributes #4 = { nounwind }
106
107!llvm.dbg.cu = !{!0}
108!omp_offload.info = !{!3}
109!nvvm.annotations = !{!4}
110!llvm.module.flags = !{!5, !6, !7, !8}
111!llvm.ident = !{!9}
112
113!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: DebugDirectivesOnly, enums: !2, splitDebugInlining: false, nameTableKind: None)
114!1 = !DIFile(filename: "declare_target_codegen_globalization.cpp", directory: "/home/jhuber/Documents/llvm-project/clang/test/OpenMP")
115!2 = !{}
116!3 = !{i32 0, i32 2049, i32 50472291, !"_Z6maini1v", i32 17, i32 0}
117!4 = !{void (i32*)* @__omp_offloading_801_3022563__Z6maini1v_l17, !"kernel", i32 1}
118!5 = !{i32 7, !"Dwarf Version", i32 2}
119!6 = !{i32 2, !"Debug Info Version", i32 3}
120!7 = !{i32 1, !"wchar_size", i32 4}
121!8 = !{i32 7, !"PIC Level", i32 2}
122!9 = !{!"clang version 12.0.0"}
123!10 = distinct !DISubprogram(name: "__omp_offloading_801_3022563__Z6maini1v_l17", scope: !1, file: !1, line: 17, type: !11, scopeLine: 17, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
124!11 = !DISubroutineType(types: !2)
125!12 = !DILocation(line: 17, column: 1, scope: !10)
126!13 = !{i32 1, i32 1025}
127!14 = !DILocation(line: 10, column: 1, scope: !15, inlinedAt: !16)
128!15 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 7, type: !11, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
129!16 = distinct !DILocation(line: 20, column: 18, scope: !17, inlinedAt: !18)
130!17 = distinct !DISubprogram(name: "__omp_outlined__", scope: !1, file: !1, line: 17, type: !11, scopeLine: 17, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
131!18 = distinct !DILocation(line: 17, column: 1, scope: !10)
132!19 = !DILocation(line: 17, column: 40, scope: !10)
133!20 = !DILocation(line: 21, column: 3, scope: !10)
134!21 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !11, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
135!22 = !DILocation(line: 5, column: 26, scope: !21)
136!23 = !{!24, !24, i64 0}
137!24 = !{!"int", !25, i64 0}
138!25 = !{!"omnipotent char", !26, i64 0}
139!26 = !{!"Simple C++ TBAA"}
140!27 = !DILocation(line: 5, column: 19, scope: !21)
141!28 = !{i32 0, i32 1024}
142!29 = !DILocation(line: 5, column: 26, scope: !21, inlinedAt: !30)
143!30 = distinct !DILocation(line: 9, column: 10, scope: !15)
144!31 = !DILocation(line: 10, column: 1, scope: !15)
145
146