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
4;; void unknown(void);
5;; void spmd_amenable(void) __attribute__((assume("ompx_spmd_amenable")));
6;;
7;; void sequential_loop() {
8;;   #pragma omp target teams
9;;   {
10;;     for (int i = 0; i < 100; ++i) {
11;;       #pragma omp parallel
12;;       {
13;;         unknown();
14;;       }
15;;     }
16;;     spmd_amenable();
17;;   }
18;; }
19;;
20;; void use(__attribute__((noescape)) int *) __attribute__((assume("ompx_spmd_amenable")));
21;;
22;; void sequential_loop_to_stack_var() {
23;;   #pragma omp target teams
24;;   {
25;;     int x;
26;;     use(&x);
27;;     for (int i = 0; i < 100; ++i) {
28;;       #pragma omp parallel
29;;       {
30;;         unknown();
31;;       }
32;;     }
33;;     spmd_amenable();
34;;   }
35;; }
36;;
37;; void sequential_loop_to_shared_var() {
38;;   #pragma omp target teams
39;;   {
40;;     int x;
41;;     for (int i = 0; i < 100; ++i) {
42;;       #pragma omp parallel
43;;       {
44;;         x++;
45;;         unknown();
46;;       }
47;;     }
48;;     spmd_amenable();
49;;   }
50;; }
51
52target triple = "nvptx64"
53
54%struct.ident_t = type { i32, i32, i32, i32, i8* }
55
56@0 = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1
57@1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @0, i32 0, i32 0) }, align 8
58@__omp_offloading_14_5896c35_sequential_loop_l5_exec_mode = weak constant i8 1
59@__omp_offloading_14_5896c35_sequential_loop_to_stack_var_l20_exec_mode = weak constant i8 1
60@__omp_offloading_14_5896c35_sequential_loop_to_shared_var_l35_exec_mode = weak constant i8 1
61@llvm.compiler.used = appending global [3 x i8*] [i8* @__omp_offloading_14_5896c35_sequential_loop_l5_exec_mode, i8* @__omp_offloading_14_5896c35_sequential_loop_to_stack_var_l20_exec_mode, i8* @__omp_offloading_14_5896c35_sequential_loop_to_shared_var_l35_exec_mode], section "llvm.metadata"
62
63;.
64; CHECK: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
65; CHECK: @[[GLOB1:[0-9]+]] = private unnamed_addr constant [[STRUCT_IDENT_T:%.*]] { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @[[GLOB0]], i32 0, i32 0) }, align 8
66; CHECK: @[[__OMP_OFFLOADING_14_5896C35_SEQUENTIAL_LOOP_L5_EXEC_MODE:[a-zA-Z0-9_$"\\.-]+]] = weak constant i8 2
67; CHECK: @[[__OMP_OFFLOADING_14_5896C35_SEQUENTIAL_LOOP_TO_STACK_VAR_L20_EXEC_MODE:[a-zA-Z0-9_$"\\.-]+]] = weak constant i8 2
68; CHECK: @[[__OMP_OFFLOADING_14_5896C35_SEQUENTIAL_LOOP_TO_SHARED_VAR_L35_EXEC_MODE:[a-zA-Z0-9_$"\\.-]+]] = weak constant i8 2
69; CHECK: @[[LLVM_COMPILER_USED:[a-zA-Z0-9_$"\\.-]+]] = appending global [3 x i8*] [i8* @__omp_offloading_14_5896c35_sequential_loop_l5_exec_mode, i8* @__omp_offloading_14_5896c35_sequential_loop_to_stack_var_l20_exec_mode, i8* @__omp_offloading_14_5896c35_sequential_loop_to_shared_var_l35_exec_mode], section "llvm.metadata"
70; CHECK: @[[X:[a-zA-Z0-9_$"\\.-]+]] = internal addrspace(3) global [4 x i8] undef, align 32
71;.
72define weak void @__omp_offloading_14_5896c35_sequential_loop_l5() #0 {
73; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_14_5896c35_sequential_loop_l5
74; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
75; CHECK-NEXT:  entry:
76; CHECK-NEXT:    [[DOTZERO_ADDR:%.*]] = alloca i32, align 4
77; CHECK-NEXT:    [[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4
78; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i1 true, i1 false, i1 false)
79; CHECK-NEXT:    [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
80; CHECK-NEXT:    br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
81; CHECK:       user_code.entry:
82; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) #[[ATTR3:[0-9]+]]
83; CHECK-NEXT:    store i32 [[TMP1]], i32* [[DOTTHREADID_TEMP_]], align 4
84; CHECK-NEXT:    call void @__omp_outlined__(i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(4) [[DOTTHREADID_TEMP_]], i32* noalias nocapture noundef nonnull readnone align 4 dereferenceable(4) [[DOTZERO_ADDR]]) #[[ATTR3]]
85; CHECK-NEXT:    call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i1 true, i1 false)
86; CHECK-NEXT:    ret void
87; CHECK:       worker.exit:
88; CHECK-NEXT:    ret void
89;
90entry:
91  %.zero.addr = alloca i32, align 4
92  %.threadid_temp. = alloca i32, align 4
93  store i32 0, i32* %.zero.addr, align 4
94  %0 = call i32 @__kmpc_target_init(%struct.ident_t* @1, i1 false, i1 true, i1 true)
95  %exec_user_code = icmp eq i32 %0, -1
96  br i1 %exec_user_code, label %user_code.entry, label %worker.exit
97
98user_code.entry:                                  ; preds = %entry
99  %1 = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1)
100  store i32 %1, i32* %.threadid_temp., align 4
101  call void @__omp_outlined__(i32* %.threadid_temp., i32* %.zero.addr) #3
102  call void @__kmpc_target_deinit(%struct.ident_t* @1, i1 false, i1 true)
103  ret void
104
105worker.exit:                                      ; preds = %entry
106  ret void
107}
108
109declare i32 @__kmpc_target_init(%struct.ident_t*, i1, i1, i1)
110
111define internal void @__omp_outlined__(i32* noalias %.global_tid., i32* noalias %.bound_tid.) #0 {
112; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__
113; CHECK-SAME: (i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[DOTGLOBAL_TID_:%.*]], i32* noalias nocapture nofree nonnull readnone align 4 dereferenceable(4) [[DOTBOUND_TID_:%.*]]) #[[ATTR0]] {
114; CHECK-NEXT:  entry:
115; CHECK-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
116; CHECK-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
117; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
118; CHECK-NEXT:    [[CAPTURED_VARS_ADDRS:%.*]] = alloca [0 x i8*], align 8
119; CHECK-NEXT:    store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
120; CHECK-NEXT:    store i32 0, i32* [[I]], align 4
121; CHECK-NEXT:    br label [[FOR_COND:%.*]]
122; CHECK:       for.cond:
123; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[I]], align 4
124; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], 100
125; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
126; CHECK:       for.body:
127; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[DOTGLOBAL_TID_]], align 4
128; CHECK-NEXT:    [[TMP2:%.*]] = bitcast [0 x i8*]* [[CAPTURED_VARS_ADDRS]] to i8**
129; CHECK-NEXT:    call void @__kmpc_parallel_51(%struct.ident_t* noundef @[[GLOB1]], i32 [[TMP1]], i32 noundef 1, i32 noundef -1, i32 noundef -1, i8* noundef bitcast (void (i32*, i32*)* @__omp_outlined__1 to i8*), i8* noundef bitcast (void (i16, i32)* @__omp_outlined__1_wrapper to i8*), i8** noundef [[TMP2]], i64 noundef 0)
130; CHECK-NEXT:    br label [[FOR_INC:%.*]]
131; CHECK:       for.inc:
132; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* [[I]], align 4
133; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP3]], 1
134; CHECK-NEXT:    store i32 [[INC]], i32* [[I]], align 4
135; CHECK-NEXT:    br label [[FOR_COND]], !llvm.loop [[LOOP9:![0-9]+]]
136; CHECK:       for.end:
137; CHECK-NEXT:    call void @spmd_amenable() #[[ATTR4:[0-9]+]]
138; CHECK-NEXT:    ret void
139;
140entry:
141  %.global_tid..addr = alloca i32*, align 8
142  %.bound_tid..addr = alloca i32*, align 8
143  %i = alloca i32, align 4
144  %captured_vars_addrs = alloca [0 x i8*], align 8
145  store i32* %.global_tid., i32** %.global_tid..addr, align 8
146  store i32* %.bound_tid., i32** %.bound_tid..addr, align 8
147  store i32 0, i32* %i, align 4
148  br label %for.cond
149
150for.cond:                                         ; preds = %for.inc, %entry
151  %0 = load i32, i32* %i, align 4
152  %cmp = icmp slt i32 %0, 100
153  br i1 %cmp, label %for.body, label %for.end
154
155for.body:                                         ; preds = %for.cond
156  %1 = load i32*, i32** %.global_tid..addr, align 8
157  %2 = load i32, i32* %1, align 4
158  %3 = bitcast [0 x i8*]* %captured_vars_addrs to i8**
159  call void @__kmpc_parallel_51(%struct.ident_t* @1, i32 %2, i32 1, i32 -1, i32 -1, i8* bitcast (void (i32*, i32*)* @__omp_outlined__1 to i8*), i8* bitcast (void (i16, i32)* @__omp_outlined__1_wrapper to i8*), i8** %3, i64 0)
160  br label %for.inc
161
162for.inc:                                          ; preds = %for.body
163  %4 = load i32, i32* %i, align 4
164  %inc = add nsw i32 %4, 1
165  store i32 %inc, i32* %i, align 4
166  br label %for.cond, !llvm.loop !9
167
168for.end:                                          ; preds = %for.cond
169  call void @spmd_amenable() #4
170  ret void
171}
172
173define internal void @__omp_outlined__1(i32* noalias %.global_tid., i32* noalias %.bound_tid.) #0 {
174; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__1
175; CHECK-SAME: (i32* noalias nocapture nofree readnone [[DOTGLOBAL_TID_:%.*]], i32* noalias nocapture nofree readnone [[DOTBOUND_TID_:%.*]]) #[[ATTR0]] {
176; CHECK-NEXT:  entry:
177; CHECK-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
178; CHECK-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
179; CHECK-NEXT:    call void @unknown() #[[ATTR5:[0-9]+]]
180; CHECK-NEXT:    ret void
181;
182entry:
183  %.global_tid..addr = alloca i32*, align 8
184  %.bound_tid..addr = alloca i32*, align 8
185  store i32* %.global_tid., i32** %.global_tid..addr, align 8
186  store i32* %.bound_tid., i32** %.bound_tid..addr, align 8
187  call void @unknown() #5
188  ret void
189}
190
191declare void @unknown() #1
192
193define internal void @__omp_outlined__1_wrapper(i16 zeroext %0, i32 %1) #0 {
194; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__1_wrapper
195; CHECK-SAME: (i16 zeroext [[TMP0:%.*]], i32 [[TMP1:%.*]]) #[[ATTR0]] {
196; CHECK-NEXT:  entry:
197; CHECK-NEXT:    [[DOTADDR:%.*]] = alloca i16, align 2
198; CHECK-NEXT:    [[DOTADDR1:%.*]] = alloca i32, align 4
199; CHECK-NEXT:    [[DOTZERO_ADDR:%.*]] = alloca i32, align 4
200; CHECK-NEXT:    [[GLOBAL_ARGS:%.*]] = alloca i8**, align 8
201; CHECK-NEXT:    store i32 0, i32* [[DOTZERO_ADDR]], align 4
202; CHECK-NEXT:    store i16 [[TMP0]], i16* [[DOTADDR]], align 2
203; CHECK-NEXT:    store i32 [[TMP1]], i32* [[DOTADDR1]], align 4
204; CHECK-NEXT:    call void @__kmpc_get_shared_variables(i8*** [[GLOBAL_ARGS]])
205; CHECK-NEXT:    call void @__omp_outlined__1(i32* [[DOTADDR1]], i32* [[DOTZERO_ADDR]]) #[[ATTR3]]
206; CHECK-NEXT:    ret void
207;
208entry:
209  %.addr = alloca i16, align 2
210  %.addr1 = alloca i32, align 4
211  %.zero.addr = alloca i32, align 4
212  %global_args = alloca i8**, align 8
213  store i32 0, i32* %.zero.addr, align 4
214  store i16 %0, i16* %.addr, align 2
215  store i32 %1, i32* %.addr1, align 4
216  call void @__kmpc_get_shared_variables(i8*** %global_args)
217  call void @__omp_outlined__1(i32* %.addr1, i32* %.zero.addr) #3
218  ret void
219}
220
221declare void @__kmpc_get_shared_variables(i8***)
222
223declare void @__kmpc_parallel_51(%struct.ident_t*, i32, i32, i32, i32, i8*, i8*, i8**, i64)
224
225declare void @spmd_amenable() #2
226
227declare i32 @__kmpc_global_thread_num(%struct.ident_t*) #3
228
229declare void @__kmpc_target_deinit(%struct.ident_t*, i1, i1)
230
231define weak void @__omp_offloading_14_5896c35_sequential_loop_to_stack_var_l20() #0 {
232; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_14_5896c35_sequential_loop_to_stack_var_l20
233; CHECK-SAME: () #[[ATTR0]] {
234; CHECK-NEXT:  entry:
235; CHECK-NEXT:    [[DOTZERO_ADDR:%.*]] = alloca i32, align 4
236; CHECK-NEXT:    [[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4
237; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i1 true, i1 false, i1 false)
238; CHECK-NEXT:    [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
239; CHECK-NEXT:    br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
240; CHECK:       user_code.entry:
241; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) #[[ATTR3]]
242; CHECK-NEXT:    store i32 [[TMP1]], i32* [[DOTTHREADID_TEMP_]], align 4
243; CHECK-NEXT:    call void @__omp_outlined__2(i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(4) [[DOTTHREADID_TEMP_]], i32* noalias nocapture noundef nonnull readnone align 4 dereferenceable(4) [[DOTZERO_ADDR]]) #[[ATTR3]]
244; CHECK-NEXT:    call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i1 true, i1 false)
245; CHECK-NEXT:    ret void
246; CHECK:       worker.exit:
247; CHECK-NEXT:    ret void
248;
249entry:
250  %.zero.addr = alloca i32, align 4
251  %.threadid_temp. = alloca i32, align 4
252  store i32 0, i32* %.zero.addr, align 4
253  %0 = call i32 @__kmpc_target_init(%struct.ident_t* @1, i1 false, i1 true, i1 true)
254  %exec_user_code = icmp eq i32 %0, -1
255  br i1 %exec_user_code, label %user_code.entry, label %worker.exit
256
257user_code.entry:                                  ; preds = %entry
258  %1 = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1)
259  store i32 %1, i32* %.threadid_temp., align 4
260  call void @__omp_outlined__2(i32* %.threadid_temp., i32* %.zero.addr) #3
261  call void @__kmpc_target_deinit(%struct.ident_t* @1, i1 false, i1 true)
262  ret void
263
264worker.exit:                                      ; preds = %entry
265  ret void
266}
267
268define internal void @__omp_outlined__2(i32* noalias %.global_tid., i32* noalias %.bound_tid.) #0 {
269; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__2
270; CHECK-SAME: (i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[DOTGLOBAL_TID_:%.*]], i32* noalias nocapture nofree nonnull readnone align 4 dereferenceable(4) [[DOTBOUND_TID_:%.*]]) #[[ATTR0]] {
271; CHECK-NEXT:  entry:
272; CHECK-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
273; CHECK-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
274; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
275; CHECK-NEXT:    [[CAPTURED_VARS_ADDRS:%.*]] = alloca [0 x i8*], align 8
276; CHECK-NEXT:    store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
277; CHECK-NEXT:    [[TMP0:%.*]] = alloca i8, i64 4, align 1
278; CHECK-NEXT:    [[X_ON_STACK:%.*]] = bitcast i8* [[TMP0]] to i32*
279; CHECK-NEXT:    call void @use(i32* nocapture [[X_ON_STACK]]) #[[ATTR4]]
280; CHECK-NEXT:    store i32 0, i32* [[I]], align 4
281; CHECK-NEXT:    br label [[FOR_COND:%.*]]
282; CHECK:       for.cond:
283; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[I]], align 4
284; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP1]], 100
285; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
286; CHECK:       for.body:
287; CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* [[DOTGLOBAL_TID_]], align 4
288; CHECK-NEXT:    [[TMP3:%.*]] = bitcast [0 x i8*]* [[CAPTURED_VARS_ADDRS]] to i8**
289; CHECK-NEXT:    call void @__kmpc_parallel_51(%struct.ident_t* noundef @[[GLOB1]], i32 [[TMP2]], i32 noundef 1, i32 noundef -1, i32 noundef -1, i8* noundef bitcast (void (i32*, i32*)* @__omp_outlined__3 to i8*), i8* noundef bitcast (void (i16, i32)* @__omp_outlined__3_wrapper to i8*), i8** noundef [[TMP3]], i64 noundef 0)
290; CHECK-NEXT:    br label [[FOR_INC:%.*]]
291; CHECK:       for.inc:
292; CHECK-NEXT:    [[TMP4:%.*]] = load i32, i32* [[I]], align 4
293; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP4]], 1
294; CHECK-NEXT:    store i32 [[INC]], i32* [[I]], align 4
295; CHECK-NEXT:    br label [[FOR_COND]], !llvm.loop [[LOOP11:![0-9]+]]
296; CHECK:       for.end:
297; CHECK-NEXT:    call void @spmd_amenable() #[[ATTR4]]
298; CHECK-NEXT:    ret void
299;
300entry:
301  %.global_tid..addr = alloca i32*, align 8
302  %.bound_tid..addr = alloca i32*, align 8
303  %i = alloca i32, align 4
304  %captured_vars_addrs = alloca [0 x i8*], align 8
305  store i32* %.global_tid., i32** %.global_tid..addr, align 8
306  store i32* %.bound_tid., i32** %.bound_tid..addr, align 8
307  %x = call i8* @__kmpc_alloc_shared(i64 4)
308  %x_on_stack = bitcast i8* %x to i32*
309  call void @use(i32* nocapture %x_on_stack) #4
310  store i32 0, i32* %i, align 4
311  br label %for.cond
312
313for.cond:                                         ; preds = %for.inc, %entry
314  %0 = load i32, i32* %i, align 4
315  %cmp = icmp slt i32 %0, 100
316  br i1 %cmp, label %for.body, label %for.end
317
318for.body:                                         ; preds = %for.cond
319  %1 = load i32*, i32** %.global_tid..addr, align 8
320  %2 = load i32, i32* %1, align 4
321  %3 = bitcast [0 x i8*]* %captured_vars_addrs to i8**
322  call void @__kmpc_parallel_51(%struct.ident_t* @1, i32 %2, i32 1, i32 -1, i32 -1, i8* bitcast (void (i32*, i32*)* @__omp_outlined__3 to i8*), i8* bitcast (void (i16, i32)* @__omp_outlined__3_wrapper to i8*), i8** %3, i64 0)
323  br label %for.inc
324
325for.inc:                                          ; preds = %for.body
326  %4 = load i32, i32* %i, align 4
327  %inc = add nsw i32 %4, 1
328  store i32 %inc, i32* %i, align 4
329  br label %for.cond, !llvm.loop !11
330
331for.end:                                          ; preds = %for.cond
332  call void @spmd_amenable() #4
333  call void @__kmpc_free_shared(i8* %x, i64 4)
334  ret void
335}
336
337declare i8* @__kmpc_alloc_shared(i64) #3
338
339declare void @use(i32* nocapture) #2
340
341define internal void @__omp_outlined__3(i32* noalias %.global_tid., i32* noalias %.bound_tid.) #0 {
342; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__3
343; CHECK-SAME: (i32* noalias nocapture nofree readnone [[DOTGLOBAL_TID_:%.*]], i32* noalias nocapture nofree readnone [[DOTBOUND_TID_:%.*]]) #[[ATTR0]] {
344; CHECK-NEXT:  entry:
345; CHECK-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
346; CHECK-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
347; CHECK-NEXT:    call void @unknown() #[[ATTR5]]
348; CHECK-NEXT:    ret void
349;
350entry:
351  %.global_tid..addr = alloca i32*, align 8
352  %.bound_tid..addr = alloca i32*, align 8
353  store i32* %.global_tid., i32** %.global_tid..addr, align 8
354  store i32* %.bound_tid., i32** %.bound_tid..addr, align 8
355  call void @unknown() #5
356  ret void
357}
358
359define internal void @__omp_outlined__3_wrapper(i16 zeroext %0, i32 %1) #0 {
360; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__3_wrapper
361; CHECK-SAME: (i16 zeroext [[TMP0:%.*]], i32 [[TMP1:%.*]]) #[[ATTR0]] {
362; CHECK-NEXT:  entry:
363; CHECK-NEXT:    [[DOTADDR:%.*]] = alloca i16, align 2
364; CHECK-NEXT:    [[DOTADDR1:%.*]] = alloca i32, align 4
365; CHECK-NEXT:    [[DOTZERO_ADDR:%.*]] = alloca i32, align 4
366; CHECK-NEXT:    [[GLOBAL_ARGS:%.*]] = alloca i8**, align 8
367; CHECK-NEXT:    store i32 0, i32* [[DOTZERO_ADDR]], align 4
368; CHECK-NEXT:    store i16 [[TMP0]], i16* [[DOTADDR]], align 2
369; CHECK-NEXT:    store i32 [[TMP1]], i32* [[DOTADDR1]], align 4
370; CHECK-NEXT:    call void @__kmpc_get_shared_variables(i8*** [[GLOBAL_ARGS]])
371; CHECK-NEXT:    call void @__omp_outlined__3(i32* [[DOTADDR1]], i32* [[DOTZERO_ADDR]]) #[[ATTR3]]
372; CHECK-NEXT:    ret void
373;
374entry:
375  %.addr = alloca i16, align 2
376  %.addr1 = alloca i32, align 4
377  %.zero.addr = alloca i32, align 4
378  %global_args = alloca i8**, align 8
379  store i32 0, i32* %.zero.addr, align 4
380  store i16 %0, i16* %.addr, align 2
381  store i32 %1, i32* %.addr1, align 4
382  call void @__kmpc_get_shared_variables(i8*** %global_args)
383  call void @__omp_outlined__3(i32* %.addr1, i32* %.zero.addr) #3
384  ret void
385}
386
387declare void @__kmpc_free_shared(i8* nocapture, i64) #3
388
389define weak void @__omp_offloading_14_5896c35_sequential_loop_to_shared_var_l35() #0 {
390; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_14_5896c35_sequential_loop_to_shared_var_l35
391; CHECK-SAME: () #[[ATTR0]] {
392; CHECK-NEXT:  entry:
393; CHECK-NEXT:    [[DOTZERO_ADDR:%.*]] = alloca i32, align 4
394; CHECK-NEXT:    [[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4
395; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i1 true, i1 false, i1 false)
396; CHECK-NEXT:    [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
397; CHECK-NEXT:    br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
398; CHECK:       user_code.entry:
399; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) #[[ATTR3]]
400; CHECK-NEXT:    store i32 [[TMP1]], i32* [[DOTTHREADID_TEMP_]], align 4
401; CHECK-NEXT:    call void @__omp_outlined__4(i32* noalias nocapture noundef nonnull readonly align 4 dereferenceable(4) [[DOTTHREADID_TEMP_]], i32* noalias nocapture noundef nonnull readnone align 4 dereferenceable(4) [[DOTZERO_ADDR]]) #[[ATTR3]]
402; CHECK-NEXT:    call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i1 true, i1 false)
403; CHECK-NEXT:    ret void
404; CHECK:       worker.exit:
405; CHECK-NEXT:    ret void
406;
407entry:
408  %.zero.addr = alloca i32, align 4
409  %.threadid_temp. = alloca i32, align 4
410  store i32 0, i32* %.zero.addr, align 4
411  %0 = call i32 @__kmpc_target_init(%struct.ident_t* @1, i1 false, i1 true, i1 true)
412  %exec_user_code = icmp eq i32 %0, -1
413  br i1 %exec_user_code, label %user_code.entry, label %worker.exit
414
415user_code.entry:                                  ; preds = %entry
416  %1 = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1)
417  store i32 %1, i32* %.threadid_temp., align 4
418  call void @__omp_outlined__4(i32* %.threadid_temp., i32* %.zero.addr) #3
419  call void @__kmpc_target_deinit(%struct.ident_t* @1, i1 false, i1 true)
420  ret void
421
422worker.exit:                                      ; preds = %entry
423  ret void
424}
425
426define internal void @__omp_outlined__4(i32* noalias %.global_tid., i32* noalias %.bound_tid.) #0 {
427; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__4
428; CHECK-SAME: (i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[DOTGLOBAL_TID_:%.*]], i32* noalias nocapture nofree nonnull readnone align 4 dereferenceable(4) [[DOTBOUND_TID_:%.*]]) #[[ATTR0]] {
429; CHECK-NEXT:  entry:
430; CHECK-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
431; CHECK-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
432; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
433; CHECK-NEXT:    [[CAPTURED_VARS_ADDRS:%.*]] = alloca [1 x i8*], align 8
434; CHECK-NEXT:    store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
435; CHECK-NEXT:    store i32 0, i32* [[I]], align 4
436; CHECK-NEXT:    br label [[FOR_COND:%.*]]
437; CHECK:       for.cond:
438; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[I]], align 4
439; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], 100
440; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
441; CHECK:       for.body:
442; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[CAPTURED_VARS_ADDRS]], i64 0, i64 0
443; CHECK-NEXT:    store i8* addrspacecast (i8 addrspace(3)* getelementptr inbounds ([4 x i8], [4 x i8] addrspace(3)* @x, i32 0, i32 0) to i8*), i8** [[TMP1]], align 8
444; CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* [[DOTGLOBAL_TID_]], align 4
445; CHECK-NEXT:    [[TMP3:%.*]] = bitcast [1 x i8*]* [[CAPTURED_VARS_ADDRS]] to i8**
446; CHECK-NEXT:    call void @__kmpc_parallel_51(%struct.ident_t* noundef @[[GLOB1]], i32 [[TMP2]], i32 noundef 1, i32 noundef -1, i32 noundef -1, i8* noundef bitcast (void (i32*, i32*, i32*)* @__omp_outlined__5 to i8*), i8* noundef bitcast (void (i16, i32)* @__omp_outlined__5_wrapper to i8*), i8** noundef [[TMP3]], i64 noundef 1)
447; CHECK-NEXT:    br label [[FOR_INC:%.*]]
448; CHECK:       for.inc:
449; CHECK-NEXT:    [[TMP4:%.*]] = load i32, i32* [[I]], align 4
450; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP4]], 1
451; CHECK-NEXT:    store i32 [[INC]], i32* [[I]], align 4
452; CHECK-NEXT:    br label [[FOR_COND]], !llvm.loop [[LOOP12:![0-9]+]]
453; CHECK:       for.end:
454; CHECK-NEXT:    call void @spmd_amenable() #[[ATTR4]]
455; CHECK-NEXT:    ret void
456;
457entry:
458  %.global_tid..addr = alloca i32*, align 8
459  %.bound_tid..addr = alloca i32*, align 8
460  %i = alloca i32, align 4
461  %captured_vars_addrs = alloca [1 x i8*], align 8
462  store i32* %.global_tid., i32** %.global_tid..addr, align 8
463  store i32* %.bound_tid., i32** %.bound_tid..addr, align 8
464  %x = call i8* @__kmpc_alloc_shared(i64 4)
465  %x_on_stack = bitcast i8* %x to i32*
466  store i32 0, i32* %i, align 4
467  br label %for.cond
468
469for.cond:                                         ; preds = %for.inc, %entry
470  %0 = load i32, i32* %i, align 4
471  %cmp = icmp slt i32 %0, 100
472  br i1 %cmp, label %for.body, label %for.end
473
474for.body:                                         ; preds = %for.cond
475  %1 = getelementptr inbounds [1 x i8*], [1 x i8*]* %captured_vars_addrs, i64 0, i64 0
476  %2 = bitcast i32* %x_on_stack to i8*
477  store i8* %2, i8** %1, align 8
478  %3 = load i32*, i32** %.global_tid..addr, align 8
479  %4 = load i32, i32* %3, align 4
480  %5 = bitcast [1 x i8*]* %captured_vars_addrs to i8**
481  call void @__kmpc_parallel_51(%struct.ident_t* @1, i32 %4, i32 1, i32 -1, i32 -1, i8* bitcast (void (i32*, i32*, i32*)* @__omp_outlined__5 to i8*), i8* bitcast (void (i16, i32)* @__omp_outlined__5_wrapper to i8*), i8** %5, i64 1)
482  br label %for.inc
483
484for.inc:                                          ; preds = %for.body
485  %6 = load i32, i32* %i, align 4
486  %inc = add nsw i32 %6, 1
487  store i32 %inc, i32* %i, align 4
488  br label %for.cond, !llvm.loop !12
489
490for.end:                                          ; preds = %for.cond
491  call void @spmd_amenable() #4
492  call void @__kmpc_free_shared(i8* %x, i64 4)
493  ret void
494}
495
496define internal void @__omp_outlined__5(i32* noalias %.global_tid., i32* noalias %.bound_tid., i32* nonnull align 4 dereferenceable(4) %x) #0 {
497; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__5
498; CHECK-SAME: (i32* noalias nocapture nofree readnone [[DOTGLOBAL_TID_:%.*]], i32* noalias nocapture nofree readnone [[DOTBOUND_TID_:%.*]], i32* nocapture nofree nonnull align 4 dereferenceable(4) [[X:%.*]]) #[[ATTR0]] {
499; CHECK-NEXT:  entry:
500; CHECK-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
501; CHECK-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
502; CHECK-NEXT:    [[X_ADDR:%.*]] = alloca i32*, align 8
503; CHECK-NEXT:    store i32* [[X]], i32** [[X_ADDR]], align 8
504; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[X]], align 4
505; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP0]], 1
506; CHECK-NEXT:    store i32 [[INC]], i32* [[X]], align 4
507; CHECK-NEXT:    call void @unknown() #[[ATTR5]]
508; CHECK-NEXT:    ret void
509;
510entry:
511  %.global_tid..addr = alloca i32*, align 8
512  %.bound_tid..addr = alloca i32*, align 8
513  %x.addr = alloca i32*, align 8
514  store i32* %.global_tid., i32** %.global_tid..addr, align 8
515  store i32* %.bound_tid., i32** %.bound_tid..addr, align 8
516  store i32* %x, i32** %x.addr, align 8
517  %0 = load i32*, i32** %x.addr, align 8
518  %1 = load i32, i32* %0, align 4
519  %inc = add nsw i32 %1, 1
520  store i32 %inc, i32* %0, align 4
521  call void @unknown() #5
522  ret void
523}
524
525define internal void @__omp_outlined__5_wrapper(i16 zeroext %0, i32 %1) #0 {
526; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__5_wrapper
527; CHECK-SAME: (i16 zeroext [[TMP0:%.*]], i32 [[TMP1:%.*]]) #[[ATTR0]] {
528; CHECK-NEXT:  entry:
529; CHECK-NEXT:    [[DOTADDR:%.*]] = alloca i16, align 2
530; CHECK-NEXT:    [[DOTADDR1:%.*]] = alloca i32, align 4
531; CHECK-NEXT:    [[DOTZERO_ADDR:%.*]] = alloca i32, align 4
532; CHECK-NEXT:    [[GLOBAL_ARGS:%.*]] = alloca i8**, align 8
533; CHECK-NEXT:    store i32 0, i32* [[DOTZERO_ADDR]], align 4
534; CHECK-NEXT:    store i16 [[TMP0]], i16* [[DOTADDR]], align 2
535; CHECK-NEXT:    store i32 [[TMP1]], i32* [[DOTADDR1]], align 4
536; CHECK-NEXT:    call void @__kmpc_get_shared_variables(i8*** [[GLOBAL_ARGS]])
537; CHECK-NEXT:    [[TMP2:%.*]] = load i8**, i8*** [[GLOBAL_ARGS]], align 8
538; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i8*, i8** [[TMP2]], i64 0
539; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i8** [[TMP3]] to i32**
540; CHECK-NEXT:    [[TMP5:%.*]] = load i32*, i32** [[TMP4]], align 8
541; CHECK-NEXT:    call void @__omp_outlined__5(i32* [[DOTADDR1]], i32* [[DOTZERO_ADDR]], i32* [[TMP5]]) #[[ATTR3]]
542; CHECK-NEXT:    ret void
543;
544entry:
545  %.addr = alloca i16, align 2
546  %.addr1 = alloca i32, align 4
547  %.zero.addr = alloca i32, align 4
548  %global_args = alloca i8**, align 8
549  store i32 0, i32* %.zero.addr, align 4
550  store i16 %0, i16* %.addr, align 2
551  store i32 %1, i32* %.addr1, align 4
552  call void @__kmpc_get_shared_variables(i8*** %global_args)
553  %2 = load i8**, i8*** %global_args, align 8
554  %3 = getelementptr inbounds i8*, i8** %2, i64 0
555  %4 = bitcast i8** %3 to i32**
556  %5 = load i32*, i32** %4, align 8
557  call void @__omp_outlined__5(i32* %.addr1, i32* %.zero.addr, i32* %5) #3
558  ret void
559}
560
561attributes #0 = { convergent noinline norecurse nounwind "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+ptx32,+sm_20" }
562attributes #1 = { convergent "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+ptx32,+sm_20" }
563attributes #2 = { convergent "frame-pointer"="none" "llvm.assume"="ompx_spmd_amenable" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+ptx32,+sm_20" }
564attributes #3 = { nounwind }
565attributes #4 = { convergent "llvm.assume"="ompx_spmd_amenable" }
566attributes #5 = { convergent }
567
568!omp_offload.info = !{!0, !1, !2}
569!nvvm.annotations = !{!3, !4, !5}
570!llvm.module.flags = !{!6, !7, !8}
571
572!0 = !{i32 0, i32 20, i32 92892213, !"sequential_loop_to_stack_var", i32 20, i32 1}
573!1 = !{i32 0, i32 20, i32 92892213, !"sequential_loop", i32 5, i32 0}
574!2 = !{i32 0, i32 20, i32 92892213, !"sequential_loop_to_shared_var", i32 35, i32 2}
575!3 = !{void ()* @__omp_offloading_14_5896c35_sequential_loop_l5, !"kernel", i32 1}
576!4 = !{void ()* @__omp_offloading_14_5896c35_sequential_loop_to_stack_var_l20, !"kernel", i32 1}
577!5 = !{void ()* @__omp_offloading_14_5896c35_sequential_loop_to_shared_var_l35, !"kernel", i32 1}
578!6 = !{i32 1, !"wchar_size", i32 4}
579!7 = !{i32 7, !"openmp", i32 50}
580!8 = !{i32 7, !"openmp-device", i32 50}
581!9 = distinct !{!9, !10}
582!10 = !{!"llvm.loop.mustprogress"}
583!11 = distinct !{!11, !10}
584!12 = distinct !{!12, !10}
585;.
586; CHECK: attributes #[[ATTR0]] = { convergent noinline norecurse nounwind "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+ptx32,+sm_20" }
587; CHECK: attributes #[[ATTR1:[0-9]+]] = { convergent "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+ptx32,+sm_20" }
588; CHECK: attributes #[[ATTR2:[0-9]+]] = { convergent "frame-pointer"="none" "llvm.assume"="ompx_spmd_amenable" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+ptx32,+sm_20" }
589; CHECK: attributes #[[ATTR3]] = { nounwind }
590; CHECK: attributes #[[ATTR4]] = { convergent "llvm.assume"="ompx_spmd_amenable" }
591; CHECK: attributes #[[ATTR5]] = { convergent }
592;.
593; CHECK: [[META0:![0-9]+]] = !{i32 0, i32 20, i32 92892213, !"sequential_loop_to_stack_var", i32 20, i32 1}
594; CHECK: [[META1:![0-9]+]] = !{i32 0, i32 20, i32 92892213, !"sequential_loop", i32 5, i32 0}
595; CHECK: [[META2:![0-9]+]] = !{i32 0, i32 20, i32 92892213, !"sequential_loop_to_shared_var", i32 35, i32 2}
596; CHECK: [[META3:![0-9]+]] = !{void ()* @__omp_offloading_14_5896c35_sequential_loop_l5, !"kernel", i32 1}
597; CHECK: [[META4:![0-9]+]] = !{void ()* @__omp_offloading_14_5896c35_sequential_loop_to_stack_var_l20, !"kernel", i32 1}
598; CHECK: [[META5:![0-9]+]] = !{void ()* @__omp_offloading_14_5896c35_sequential_loop_to_shared_var_l35, !"kernel", i32 1}
599; CHECK: [[META6:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
600; CHECK: [[META7:![0-9]+]] = !{i32 7, !"openmp", i32 50}
601; CHECK: [[META8:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
602; CHECK: [[LOOP9]] = distinct !{!9, !10}
603; CHECK: [[META10:![0-9]+]] = !{!"llvm.loop.mustprogress"}
604; CHECK: [[LOOP11]] = distinct !{!11, !10}
605; CHECK: [[LOOP12]] = distinct !{!12, !10}
606;.
607