blob: b96c8d50a3ffa3244720df70ab412a7312365867 [file] [log] [blame]
Alexey Bataevbe5a8b42017-07-17 13:30:36 +00001// RUN: %clang_cc1 -fopenmp -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu | FileCheck %s
2// expected-no-diagnostics
3
4struct S {
5 float a;
6 S() : a(0.0f) {}
7 ~S() {}
8};
9
10#pragma omp declare reduction(+:S:omp_out.a += omp_in.a) initializer(omp_priv = omp_orig)
11
12float g;
13
14int a;
15#pragma omp threadprivate(a)
16int main (int argc, char *argv[])
17{
18int i, n;
19float a[100], b[100], sum, e[argc + 100];
20S c[100];
21float &d = g;
22
23/* Some initializations */
24n = 100;
25for (i=0; i < n; i++)
26 a[i] = b[i] = i * 1.0;
27sum = 0.0;
28
29#pragma omp taskloop simd reduction(+:sum, c[:n], d, e)
30 for (i=0; i < n; i++) {
31 sum = sum + (a[i] * b[i]);
32 c[i].a = i*i;
33 d += i*i;
34 e[i] = i;
35 }
36
37}
38
39// CHECK-LABEL: @main(
Alexey Bataev7766e512017-07-17 14:22:34 +000040// CHECK: [[RETVAL:%.*]] = alloca i32,
41// CHECK: [[ARGC_ADDR:%.*]] = alloca i32,
42// CHECK: [[ARGV_ADDR:%.*]] = alloca i8**,
43// CHECK: [[I:%.*]] = alloca i32,
44// CHECK: [[N:%.*]] = alloca i32,
45// CHECK: [[A:%.*]] = alloca [100 x float],
46// CHECK: [[B:%.*]] = alloca [100 x float],
47// CHECK: [[SUM:%.*]] = alloca float,
48// CHECK: [[SAVED_STACK:%.*]] = alloca i8*,
49// CHECK: [[C:%.*]] = alloca [100 x %struct.S],
50// CHECK: [[D:%.*]] = alloca float*,
51// CHECK: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]],
Alexey Bataevbe5a8b42017-07-17 13:30:36 +000052// CHECK: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%ident_t*
Alexey Bataev7766e512017-07-17 14:22:34 +000053// CHECK: [[DOTRD_INPUT_:%.*]] = alloca [4 x %struct.kmp_task_red_input_t],
54// CHECK: [[DOTCAPTURE_EXPR_:%.*]] = alloca i32,
55// CHECK: [[DOTCAPTURE_EXPR_9:%.*]] = alloca i32,
56// CHECK: store i32 0, i32* [[RETVAL]],
57// CHECK: store i32 [[ARGC:%.*]], i32* [[ARGC_ADDR]],
58// CHECK: store i8** [[ARGV:%.*]], i8*** [[ARGV_ADDR]],
59// CHECK: [[TMP1:%.*]] = load i32, i32* [[ARGC_ADDR]],
Alexey Bataevbe5a8b42017-07-17 13:30:36 +000060// CHECK: [[ADD:%.*]] = add nsw i32 [[TMP1]], 100
61// CHECK: [[TMP2:%.*]] = zext i32 [[ADD]] to i64
62// CHECK: [[VLA:%.+]] = alloca float, i64 %
63
64// CHECK: call void @__kmpc_taskgroup(%ident_t*
Alexey Bataev55c2a962017-07-17 14:47:59 +000065// CHECK-DAG: [[TMP21:%.*]] = bitcast float* [[SUM]] to i8*
66// CHECK-DAG: store i8* [[TMP21]], i8** [[TMP20:%[^,]+]],
67// CHECK-DAG: [[TMP20]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T:%.+]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_:%.+]], i32 0, i32 0
68// CHECK-DAG: [[TMP22:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 1
69// CHECK-DAG: store i64 4, i64* [[TMP22]],
70// CHECK-DAG: [[TMP23:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 2
71// CHECK-DAG: store i8* bitcast (void (i8*)* [[RED_INIT1:@.+]] to i8*), i8** [[TMP23]],
72// CHECK-DAG: [[TMP24:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 3
73// CHECK-DAG: store i8* null, i8** [[TMP24]],
74// CHECK-DAG: [[TMP25:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 4
75// CHECK-DAG: store i8* bitcast (void (i8*, i8*)* [[RED_COMB1:@.+]] to i8*), i8** [[TMP25]],
76// CHECK-DAG: [[TMP26:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 5
77// CHECK-DAG: [[TMP27:%.*]] = bitcast i32* [[TMP26]] to i8*
78// CHECK-DAG: call void @llvm.memset.p0i8.i64(i8* [[TMP27]], i8 0, i64 4, i32 8, i1 false)
79// CHECK-DAG: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 0
80// CHECK-DAG: [[LB_ADD_LEN:%.*]] = add nsw i64 -1, %
81// CHECK-DAG: [[ARRAYIDX6:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 [[LB_ADD_LEN]]
82// CHECK-DAG: [[TMP31:%.*]] = bitcast %struct.S* [[ARRAYIDX5]] to i8*
83// CHECK-DAG: store i8* [[TMP31]], i8** [[TMP28:%[^,]+]],
84// CHECK-DAG: [[TMP28]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4:%.+]], i32 0, i32 0
85// CHECK-DAG: [[TMP32:%.*]] = ptrtoint %struct.S* [[ARRAYIDX6]] to i64
86// CHECK-DAG: [[TMP33:%.*]] = ptrtoint %struct.S* [[ARRAYIDX5]] to i64
87// CHECK-DAG: [[TMP34:%.*]] = sub i64 [[TMP32]], [[TMP33]]
88// CHECK-DAG: [[TMP35:%.*]] = sdiv exact i64 [[TMP34]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
89// CHECK-DAG: [[TMP36:%.*]] = add nuw i64 [[TMP35]], 1
90// CHECK-DAG: [[TMP37:%.*]] = mul nuw i64 [[TMP36]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
91// CHECK-DAG: store i64 [[TMP37]], i64* [[TMP38:%[^,]+]],
92// CHECK-DAG: [[TMP38]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 1
93// CHECK-DAG: [[TMP39:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 2
94// CHECK-DAG: store i8* bitcast (void (i8*)* [[RED_INIT2:@.+]] to i8*), i8** [[TMP39]],
95// CHECK-DAG: [[TMP40:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 3
96// CHECK-DAG: store i8* bitcast (void (i8*)* [[RED_FINI2:@.+]] to i8*), i8** [[TMP40]],
97// CHECK-DAG: [[TMP41:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 4
98// CHECK-DAG: store i8* bitcast (void (i8*, i8*)* [[RED_COMB2:@.+]] to i8*), i8** [[TMP41]],
99// CHECK-DAG: [[TMP42:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 5
100// CHECK-DAG: store i32 1, i32* [[TMP42]],
101// CHECK-DAG: [[TMP44:%.*]] = load float*, float** [[D]],
102// CHECK-DAG: [[TMP45:%.*]] = bitcast float* [[TMP44]] to i8*
103// CHECK-DAG: store i8* [[TMP45]], i8** [[TMP43:%[^,]+]],
104// CHECK-DAG: [[TMP43]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7:%.+]], i32 0, i32 0
105// CHECK-DAG: [[TMP46:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 1
106// CHECK-DAG: store i64 4, i64* [[TMP46]],
107// CHECK-DAG: [[TMP47:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 2
108// CHECK-DAG: store i8* bitcast (void (i8*)* [[RED_INIT3:@.+]] to i8*), i8** [[TMP47]],
109// CHECK-DAG: [[TMP48:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 3
110// CHECK-DAG: store i8* null, i8** [[TMP48]],
111// CHECK-DAG: [[TMP49:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 4
112// CHECK-DAG: store i8* bitcast (void (i8*, i8*)* [[RED_COMB3:@.+]] to i8*), i8** [[TMP49]],
113// CHECK-DAG: [[TMP50:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 5
114// CHECK-DAG: [[TMP51:%.*]] = bitcast i32* [[TMP50]] to i8*
115// CHECK-DAG: call void @llvm.memset.p0i8.i64(i8* [[TMP51]], i8 0, i64 4, i32 8, i1 false)
116// CHECK-DAG: [[TMP53:%.*]] = bitcast float* [[VLA]] to i8*
117// CHECK-DAG: store i8* [[TMP53]], i8** [[TMP52:%[^,]+]],
118// CHECK-DAG: [[TMP52]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8:%.+]], i32 0, i32 0
119// CHECK-DAG: [[TMP54:%.*]] = mul nuw i64 [[TMP2]], 4
120// CHECK-DAG: [[TMP55:%.*]] = udiv exact i64 [[TMP54]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
121// CHECK-DAG: store i64 [[TMP54]], i64* [[TMP56:%[^,]+]],
122// CHECK-DAG: [[TMP56]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 1
123// CHECK-DAG: [[TMP57:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 2
124// CHECK-DAG: store i8* bitcast (void (i8*)* [[RED_INIT4:@.+]] to i8*), i8** [[TMP57]],
125// CHECK-DAG: [[TMP58:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 3
126// CHECK-DAG: store i8* null, i8** [[TMP58]],
127// CHECK-DAG: [[TMP59:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 4
128// CHECK-DAG: store i8* bitcast (void (i8*, i8*)* [[RED_COMB4:@.+]] to i8*), i8** [[TMP59]],
129// CHECK-DAG: [[TMP60:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 5
130// CHECK-DAG: store i32 1, i32* [[TMP60]],
131// CHECK-DAG: [[DOTRD_INPUT_GEP_]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
132// CHECK-DAG: [[DOTRD_INPUT_GEP_4]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
133// CHECK-DAG: [[DOTRD_INPUT_GEP_7]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
134// CHECK-DAG: [[DOTRD_INPUT_GEP_8]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000135// CHECK: [[TMP61:%.*]] = bitcast [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]] to i8*
136// CHECK: [[TMP62:%.*]] = call i8* @__kmpc_task_reduction_init(i32 [[TMP0]], i32 4, i8* [[TMP61]])
Alexey Bataev7766e512017-07-17 14:22:34 +0000137// CHECK: [[TMP63:%.*]] = load i32, i32* [[N]],
138// CHECK: store i32 [[TMP63]], i32* [[DOTCAPTURE_EXPR_]],
139// CHECK: [[TMP64:%.*]] = load i32, i32* [[DOTCAPTURE_EXPR_]],
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000140// CHECK: [[SUB:%.*]] = sub nsw i32 [[TMP64]], 0
141// CHECK: [[SUB10:%.*]] = sub nsw i32 [[SUB]], 1
142// CHECK: [[ADD11:%.*]] = add nsw i32 [[SUB10]], 1
143// CHECK: [[DIV:%.*]] = sdiv i32 [[ADD11]], 1
144// CHECK: [[SUB12:%.*]] = sub nsw i32 [[DIV]], 1
Alexey Bataev7766e512017-07-17 14:22:34 +0000145// CHECK: store i32 [[SUB12]], i32* [[DOTCAPTURE_EXPR_9]],
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000146// CHECK: [[TMP65:%.*]] = call i8* @__kmpc_omp_task_alloc(%ident_t* %{{.+}}, i32 [[TMP0]], i32 1, i64 888, i64 72, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* @{{.+}} to i32 (i32, i8*)*))
Alexey Bataev6e7f49f2017-07-18 00:42:35 +0000147// CHECK: call void @__kmpc_taskloop(%ident_t* %{{.+}}, i32 [[TMP0]], i8* [[TMP65]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 0, i32 0, i64 0, i8* null)
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000148// CHECK: call void @__kmpc_end_taskgroup(%ident_t*
149
150// CHECK: ret i32
151
152// CHECK: define internal void [[RED_INIT1]](i8*)
153// CHECK: store float 0.000000e+00, float* %
154// CHECK: ret void
155
156// CHECK: define internal void [[RED_COMB1]](i8*, i8*)
Alexey Bataevec8c9f82017-07-17 14:53:02 +0000157// CHECK: fadd float %
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000158// CHECK: store float %{{.+}}, float* %
159// CHECK: ret void
160
161// CHECK: define internal void [[RED_INIT2]](i8*)
162// CHECK: call i8* @__kmpc_threadprivate_cached(
163// CHECK: call i8* @__kmpc_threadprivate_cached(
164// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(
165// CHECK: ret void
166
167// CHECK: define internal void [[RED_FINI2]](i8*)
168// CHECK: call i8* @__kmpc_threadprivate_cached(
169// CHECK: call void @
170// CHECK: ret void
171
172// CHECK: define internal void [[RED_COMB2]](i8*, i8*)
173// CHECK: call i8* @__kmpc_threadprivate_cached(
174// CHECK: fadd float %
175// CHECK: store float %{{.+}}, float* %
176// CHECK: ret void
177
178// CHECK: define internal void [[RED_INIT3]](i8*)
179// CHECK: store float 0.000000e+00, float* %
180// CHECK: ret void
181
182// CHECK: define internal void [[RED_COMB3]](i8*, i8*)
183// CHECK: fadd float %
184// CHECK: store float %{{.+}}, float* %
185// CHECK: ret void
186
187// CHECK: define internal void [[RED_INIT4]](i8*)
188// CHECK: call i8* @__kmpc_threadprivate_cached(
189// CHECK: store float 0.000000e+00, float* %
190// CHECK: ret void
191
192// CHECK: define internal void [[RED_COMB4]](i8*, i8*)
193// CHECK: call i8* @__kmpc_threadprivate_cached(
194// CHECK: fadd float %
195// CHECK: store float %{{.+}}, float* %
196// CHECK: ret void
197