[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / master_taskloop_reduction_codegen.cpp
blobb0652c843845c75bea7879308f326aaef7d01dc6
1 // RUN: %clang_cc1 -fopenmp -x c++ %s -verify -Wno-vla -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -fnoopenmp-use-tls -std=c++98 | FileCheck %s
3 // RUN: %clang_cc1 -fopenmp-simd -x c++ %s -verify -Wno-vla -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -fnoopenmp-use-tls -std=c++98 | FileCheck --check-prefix SIMD-ONLY0 %s
4 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
5 // expected-no-diagnostics
7 struct S {
8 float a;
9 S() : a(0.0f) {}
10 ~S() {}
13 #pragma omp declare reduction(+:S:omp_out.a += omp_in.a) initializer(omp_priv = omp_orig)
15 float g;
17 int a;
18 #pragma omp threadprivate(a)
19 int main (int argc, char *argv[])
21 int i, n;
22 float a[100], b[100], sum, e[argc + 100];
23 S c[100];
24 float &d = g;
26 /* Some initializations */
27 n = 100;
28 for (i=0; i < n; i++)
29 a[i] = b[i] = i * 1.0;
30 sum = 0.0;
32 #pragma omp master taskloop reduction(+:sum, c[:n], d, e)
33 for (i=0; i < n; i++) {
34 sum = sum + (a[i] * b[i]);
35 c[i].a = i*i;
36 d += i*i;
37 e[i] = i;
42 // CHECK-LABEL: @main(
43 // CHECK: [[RETVAL:%.*]] = alloca i32,
44 // CHECK: [[ARGC_ADDR:%.*]] = alloca i32,
45 // CHECK: [[ARGV_ADDR:%.*]] = alloca ptr,
46 // CHECK: [[I:%.*]] = alloca i32,
47 // CHECK: [[N:%.*]] = alloca i32,
48 // CHECK: [[A:%.*]] = alloca [100 x float],
49 // CHECK: [[B:%.*]] = alloca [100 x float],
50 // CHECK: [[SUM:%.*]] = alloca float,
51 // CHECK: [[SAVED_STACK:%.*]] = alloca ptr,
52 // CHECK: [[C:%.*]] = alloca [100 x %struct.S],
53 // CHECK: [[D:%.*]] = alloca ptr,
54 // CHECK: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]],
55 // CHECK: [[DOTRD_INPUT_:%.*]] = alloca [4 x %struct.kmp_taskred_input_t],
56 // CHECK: alloca i32,
57 // CHECK: [[DOTCAPTURE_EXPR_:%.*]] = alloca i32,
58 // CHECK: [[DOTCAPTURE_EXPR_9:%.*]] = alloca i32,
59 // CHECK: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(ptr
60 // CHECK: store i32 0, ptr [[RETVAL]],
61 // CHECK: store i32 [[ARGC:%.*]], ptr [[ARGC_ADDR]],
62 // CHECK: store ptr [[ARGV:%.*]], ptr [[ARGV_ADDR]],
63 // CHECK: [[TMP1:%.*]] = load i32, ptr [[ARGC_ADDR]],
64 // CHECK: [[ADD:%.*]] = add nsw i32 [[TMP1]], 100
65 // CHECK: [[TMP2:%.*]] = zext i32 [[ADD]] to i64
66 // CHECK: [[VLA:%.+]] = alloca float, i64 %
68 // CHECK: [[RES:%.+]] = call {{.*}}i32 @__kmpc_master(
69 // CHECK-NEXT: [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
70 // CHECK-NEXT: br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:[^,]+]]
71 // CHECK: [[THEN]]
72 // CHECK: call void @__kmpc_taskgroup(ptr
73 // CHECK-DAG: store ptr [[SUM]], ptr [[TMP20:%[^,]+]],
74 // CHECK-DAG: [[TMP20]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_:%.+]], i32 0, i32 0
75 // CHECK-DAG: store ptr [[SUM]], ptr [[TMP20:%[^,]+]],
76 // CHECK-DAG: [[TMP20]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_]], i32 0, i32 1
77 // CHECK-DAG: [[TMP22:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_]], i32 0, i32 2
78 // CHECK-DAG: store i64 4, ptr [[TMP22]],
79 // CHECK-DAG: [[TMP23:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_]], i32 0, i32 3
80 // CHECK-DAG: store ptr @[[RED_INIT1:.+]], ptr [[TMP23]],
81 // CHECK-DAG: [[TMP24:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_]], i32 0, i32 4
82 // CHECK-DAG: store ptr null, ptr [[TMP24]],
83 // CHECK-DAG: [[TMP25:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_]], i32 0, i32 5
84 // CHECK-DAG: store ptr @[[RED_COMB1:.+]], ptr [[TMP25]],
85 // CHECK-DAG: [[TMP26:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_]], i32 0, i32 6
86 // CHECK-DAG: call void @llvm.memset.p0.i64(ptr align 8 [[TMP26]], i8 0, i64 4, i1 false)
87 // CHECK-DAG: [[ARRAYIDX5:%.*]] = getelementptr inbounds nuw [100 x %struct.S], ptr [[C]], i64 0, i64 0
88 // CHECK-DAG: [[LB_ADD_LEN:%.*]] = add nsw i64 -1, %
89 // CHECK-DAG: [[ARRAYIDX6:%.*]] = getelementptr inbounds nuw [100 x %struct.S], ptr [[C]], i64 0, i64 [[LB_ADD_LEN]]
90 // CHECK-DAG: store ptr [[ARRAYIDX5]], ptr [[TMP28:%[^,]+]],
91 // CHECK-DAG: [[TMP28]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_4:%.+]], i32 0, i32 0
92 // CHECK-DAG: store ptr [[ARRAYIDX5]], ptr [[TMP28:%[^,]+]],
93 // CHECK-DAG: [[TMP28]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_4]], i32 0, i32 1
94 // CHECK-DAG: [[TMP32:%.*]] = ptrtoint ptr [[ARRAYIDX6]] to i64
95 // CHECK-DAG: [[TMP33:%.*]] = ptrtoint ptr [[ARRAYIDX5]] to i64
96 // CHECK-DAG: [[TMP34:%.*]] = sub i64 [[TMP32]], [[TMP33]]
97 // CHECK-DAG: [[TMP35:%.*]] = sdiv exact i64 [[TMP34]], ptrtoint (ptr getelementptr (%struct.S, ptr null, i32 1) to i64)
98 // CHECK-DAG: [[TMP36:%.*]] = add nuw i64 [[TMP35]], 1
99 // CHECK-DAG: [[TMP37:%.*]] = mul nuw i64 [[TMP36]], ptrtoint (ptr getelementptr (%struct.S, ptr null, i32 1) to i64)
100 // CHECK-DAG: store i64 [[TMP37]], ptr [[TMP38:%[^,]+]],
101 // CHECK-DAG: [[TMP38]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_4]], i32 0, i32 2
102 // CHECK-DAG: [[TMP39:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_4]], i32 0, i32 3
103 // CHECK-DAG: store ptr @[[RED_INIT2:.+]], ptr [[TMP39]],
104 // CHECK-DAG: [[TMP40:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_4]], i32 0, i32 4
105 // CHECK-DAG: store ptr @[[RED_FINI2:.+]], ptr [[TMP40]],
106 // CHECK-DAG: [[TMP41:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_4]], i32 0, i32 5
107 // CHECK-DAG: store ptr @[[RED_COMB2:.+]], ptr [[TMP41]],
108 // CHECK-DAG: [[TMP42:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_4]], i32 0, i32 6
109 // CHECK-DAG: store i32 1, ptr [[TMP42]],
110 // CHECK-DAG: [[TMP44:%.*]] = load ptr, ptr [[D]],
111 // CHECK-DAG: store ptr [[TMP44]], ptr [[TMP43:%[^,]+]],
112 // CHECK-DAG: [[TMP43]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_7:%.+]], i32 0, i32 0
113 // CHECK-DAG: store ptr [[TMP44]], ptr [[TMP43:%[^,]+]],
114 // CHECK-DAG: [[TMP43]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_7]], i32 0, i32 1
115 // CHECK-DAG: [[TMP46:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_7]], i32 0, i32 2
116 // CHECK-DAG: store i64 4, ptr [[TMP46]],
117 // CHECK-DAG: [[TMP47:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_7]], i32 0, i32 3
118 // CHECK-DAG: store ptr @[[RED_INIT3:.+]], ptr [[TMP47]],
119 // CHECK-DAG: [[TMP48:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_7]], i32 0, i32 4
120 // CHECK-DAG: store ptr null, ptr [[TMP48]],
121 // CHECK-DAG: [[TMP49:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_7]], i32 0, i32 5
122 // CHECK-DAG: store ptr @[[RED_COMB3:.+]], ptr [[TMP49]],
123 // CHECK-DAG: [[TMP50:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_7]], i32 0, i32 6
124 // CHECK-DAG: call void @llvm.memset.p0.i64(ptr align 8 [[TMP50]], i8 0, i64 4, i1 false)
125 // CHECK-DAG: store ptr [[VLA]], ptr [[TMP52:%[^,]+]],
126 // CHECK-DAG: [[TMP52]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_8:%.+]], i32 0, i32 0
127 // CHECK-DAG: store ptr [[VLA]], ptr [[TMP52:%[^,]+]],
128 // CHECK-DAG: [[TMP52]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_8]], i32 0, i32 1
129 // CHECK-DAG: [[TMP54:%.*]] = mul nuw i64 [[TMP2]], 4
130 // CHECK-DAG: [[TMP55:%.*]] = udiv exact i64 [[TMP54]], ptrtoint (ptr getelementptr (float, ptr null, i32 1) to i64)
131 // CHECK-DAG: store i64 [[TMP54]], ptr [[TMP56:%[^,]+]],
132 // CHECK-DAG: [[TMP56]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_8]], i32 0, i32 2
133 // CHECK-DAG: [[TMP57:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_8]], i32 0, i32 3
134 // CHECK-DAG: store ptr @[[RED_INIT4:.+]], ptr [[TMP57]],
135 // CHECK-DAG: [[TMP58:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_8]], i32 0, i32 4
136 // CHECK-DAG: store ptr null, ptr [[TMP58]],
137 // CHECK-DAG: [[TMP59:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_8]], i32 0, i32 5
138 // CHECK-DAG: store ptr @[[RED_COMB4:.+]], ptr [[TMP59]],
139 // CHECK-DAG: [[TMP60:%.*]] = getelementptr inbounds nuw %struct.kmp_taskred_input_t, ptr [[DOTRD_INPUT_GEP_8]], i32 0, i32 6
140 // CHECK-DAG: store i32 1, ptr [[TMP60]],
141 // CHECK-DAG: [[DOTRD_INPUT_GEP_]] = getelementptr inbounds nuw [4 x %struct.kmp_taskred_input_t], ptr [[DOTRD_INPUT_]], i64 0, i64
142 // CHECK-DAG: [[DOTRD_INPUT_GEP_4]] = getelementptr inbounds nuw [4 x %struct.kmp_taskred_input_t], ptr [[DOTRD_INPUT_]], i64 0, i64
143 // CHECK-DAG: [[DOTRD_INPUT_GEP_7]] = getelementptr inbounds nuw [4 x %struct.kmp_taskred_input_t], ptr [[DOTRD_INPUT_]], i64 0, i64
144 // CHECK-DAG: [[DOTRD_INPUT_GEP_8]] = getelementptr inbounds nuw [4 x %struct.kmp_taskred_input_t], ptr [[DOTRD_INPUT_]], i64 0, i64
145 // CHECK: [[TMP62:%.*]] = call ptr @__kmpc_taskred_init(i32 [[TMP0]], i32 4, ptr [[DOTRD_INPUT_]])
146 // CHECK: [[TMP63:%.*]] = load i32, ptr [[N]],
147 // CHECK: store i32 [[TMP63]], ptr [[DOTCAPTURE_EXPR_]],
148 // CHECK: [[TMP64:%.*]] = load i32, ptr [[DOTCAPTURE_EXPR_]],
149 // CHECK: [[SUB:%.*]] = sub nsw i32 [[TMP64]], 0
150 // CHECK: [[DIV:%.*]] = sdiv i32 [[SUB]], 1
151 // CHECK: [[SUB12:%.*]] = sub nsw i32 [[DIV]], 1
152 // CHECK: store i32 [[SUB12]], ptr [[DOTCAPTURE_EXPR_9]],
153 // CHECK: [[TMP65:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr {{.+}}, i32 [[TMP0]], i32 1, i64 888, i64 40, ptr @[[TASK:.+]])
154 // CHECK: call void @__kmpc_taskloop(ptr {{.+}}, i32 [[TMP0]], ptr [[TMP65]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr null)
155 // CHECK: call void @__kmpc_end_taskgroup(ptr
156 // CHECK: call {{.*}}void @__kmpc_end_master(
157 // CHECK-NEXT: br label {{%?}}[[EXIT]]
158 // CHECK: [[EXIT]]
160 // CHECK: ret i32
162 // CHECK: define internal void @[[RED_INIT1]](ptr noalias noundef %{{.+}}, ptr noalias noundef %{{.+}})
163 // CHECK: store float 0.000000e+00, ptr %
164 // CHECK: ret void
166 // CHECK: define internal void @[[RED_COMB1]](ptr noundef %0, ptr noundef %1)
167 // CHECK: fadd float %
168 // CHECK: store float %{{.+}}, ptr %
169 // CHECK: ret void
171 // CHECK: define internal void @[[RED_INIT2]](ptr noalias noundef %{{.+}}, ptr noalias noundef %{{.+}})
172 // CHECK: call ptr @__kmpc_threadprivate_cached(
173 // CHECK-NOT: call ptr @__kmpc_threadprivate_cached(
174 // CHECK: call void [[OMP_INIT1:@.+]](
175 // CHECK: ret void
177 // CHECK: define internal void [[OMP_COMB1:@.+]](ptr noalias noundef %0, ptr noalias noundef %1)
178 // CHECK: fadd float %
180 // CHECK: define internal void [[OMP_INIT1]](ptr noalias noundef %0, ptr noalias noundef %1)
181 // CHECK: call void @llvm.memcpy.p0.p0.i64(
183 // CHECK: define internal void @[[RED_FINI2]](ptr noundef %0)
184 // CHECK: call ptr @__kmpc_threadprivate_cached(
185 // CHECK: call void @
186 // CHECK: ret void
188 // CHECK: define internal void @[[RED_COMB2]](ptr noundef %0, ptr noundef %1)
189 // CHECK: call ptr @__kmpc_threadprivate_cached(
190 // CHECK: call void [[OMP_COMB1]](
191 // CHECK: ret void
193 // CHECK: define internal void @[[RED_INIT3]](ptr noalias noundef %{{.+}}, ptr noalias noundef %{{.+}})
194 // CHECK: store float 0.000000e+00, ptr %
195 // CHECK: ret void
197 // CHECK: define internal void @[[RED_COMB3]](ptr noundef %0, ptr noundef %1)
198 // CHECK: fadd float %
199 // CHECK: store float %{{.+}}, ptr %
200 // CHECK: ret void
202 // CHECK: define internal void @[[RED_INIT4]](ptr noalias noundef %{{.+}}, ptr noalias noundef %{{.+}})
203 // CHECK: call ptr @__kmpc_threadprivate_cached(
204 // CHECK: store float 0.000000e+00, ptr %
205 // CHECK: ret void
207 // CHECK: define internal void @[[RED_COMB4]](ptr noundef %0, ptr noundef %1)
208 // CHECK: call ptr @__kmpc_threadprivate_cached(
209 // CHECK: fadd float %
210 // CHECK: store float %{{.+}}, ptr %
211 // CHECK: ret void
213 // CHECK-NOT: call ptr @__kmpc_threadprivate_cached(
214 // CHECK: call ptr @__kmpc_task_reduction_get_th_data(
215 // CHECK: call ptr @__kmpc_threadprivate_cached(
216 // CHECK: call ptr @__kmpc_task_reduction_get_th_data(
217 // CHECK-NOT: call ptr @__kmpc_threadprivate_cached(
218 // CHECK: call ptr @__kmpc_task_reduction_get_th_data(
219 // CHECK: call ptr @__kmpc_threadprivate_cached(
220 // CHECK: call ptr @__kmpc_task_reduction_get_th_data(
221 // CHECK-NOT: call ptr @__kmpc_threadprivate_cached(
223 // CHECK-DAG: distinct !DISubprogram(linkageName: "[[TASK]]", scope: !
224 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]"
225 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]"
226 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]"
227 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]"
228 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]"
229 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]"
230 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]"
231 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]"
232 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]"