blob: 619b09082d0cf7fdebd2d20abe5eae891136cbe2 [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(
40// CHECK: [[RETVAL:%.*]] = alloca i32, align 4
41// CHECK: [[ARGC_ADDR:%.*]] = alloca i32, align 4
42// CHECK: [[ARGV_ADDR:%.*]] = alloca i8**, align 8
43// CHECK: [[I:%.*]] = alloca i32, align 4
44// CHECK: [[N:%.*]] = alloca i32, align 4
45// CHECK: [[A:%.*]] = alloca [100 x float], align 4
46// CHECK: [[B:%.*]] = alloca [100 x float], align 4
47// CHECK: [[SUM:%.*]] = alloca float, align 4
48// CHECK: [[SAVED_STACK:%.*]] = alloca i8*, align 8
49// CHECK: [[C:%.*]] = alloca [100 x %struct.S], align 4
50// CHECK: [[D:%.*]] = alloca float*, align 8
51// CHECK: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 8
52// CHECK: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%ident_t*
53// CHECK: [[DOTRD_INPUT_:%.*]] = alloca [4 x %struct.kmp_task_red_input_t], align 8
54// CHECK: [[DOTCAPTURE_EXPR_:%.*]] = alloca i32, align 4
55// CHECK: [[DOTCAPTURE_EXPR_9:%.*]] = alloca i32, align 4
56// CHECK: store i32 0, i32* [[RETVAL]], align 4
57// CHECK: store i32 [[ARGC:%.*]], i32* [[ARGC_ADDR]], align 4
58// CHECK: store i8** [[ARGV:%.*]], i8*** [[ARGV_ADDR]], align 8
59// CHECK: [[TMP1:%.*]] = load i32, i32* [[ARGC_ADDR]], align 4
60// 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*
65// CHECK: [[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 0
66// CHECK: [[TMP20:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T:%.*]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 0
67// CHECK: [[TMP21:%.*]] = bitcast float* [[SUM]] to i8*
68// CHECK: store i8* [[TMP21]], i8** [[TMP20]], align 8
69// CHECK: [[TMP22:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 1
70// CHECK: store i64 4, i64* [[TMP22]], align 8
71// CHECK: [[TMP23:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 2
72// CHECK: store i8* bitcast (void (i8*)* [[RED_INIT1:@.+]] to i8*), i8** [[TMP23]], align 8
73// CHECK: [[TMP24:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 3
74// CHECK: store i8* null, i8** [[TMP24]], align 8
75// CHECK: [[TMP25:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 4
76// CHECK: store i8* bitcast (void (i8*, i8*)* [[RED_COMB1:@.+]] to i8*), i8** [[TMP25]], align 8
77// CHECK: [[TMP26:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 5
78// CHECK: [[TMP27:%.*]] = bitcast i32* [[TMP26]] to i8*
79// CHECK: call void @llvm.memset.p0i8.i64(i8* [[TMP27]], i8 0, i64 4, i32 8, i1 false)
80// CHECK: [[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 1
81// CHECK: [[TMP28:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 0
82// CHECK: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 0
Alexey Bataeva2a814f2017-07-17 14:06:41 +000083// CHECK: [[LB_ADD_LEN:%.*]] = add nsw i64 -1, %
Alexey Bataevbe5a8b42017-07-17 13:30:36 +000084// CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 [[LB_ADD_LEN]]
85// CHECK: [[TMP31:%.*]] = bitcast %struct.S* [[ARRAYIDX5]] to i8*
86// CHECK: store i8* [[TMP31]], i8** [[TMP28]], align 8
87// CHECK: [[TMP32:%.*]] = ptrtoint %struct.S* [[ARRAYIDX6]] to i64
88// CHECK: [[TMP33:%.*]] = ptrtoint %struct.S* [[ARRAYIDX5]] to i64
89// CHECK: [[TMP34:%.*]] = sub i64 [[TMP32]], [[TMP33]]
90// CHECK: [[TMP35:%.*]] = sdiv exact i64 [[TMP34]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
91// CHECK: [[TMP36:%.*]] = add nuw i64 [[TMP35]], 1
92// CHECK: [[TMP37:%.*]] = mul nuw i64 [[TMP36]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
93// CHECK: [[TMP38:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 1
94// CHECK: store i64 [[TMP37]], i64* [[TMP38]], align 8
95// CHECK: [[TMP39:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 2
96// CHECK: store i8* bitcast (void (i8*)* [[RED_INIT2:@.+]] to i8*), i8** [[TMP39]], align 8
97// CHECK: [[TMP40:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 3
98// CHECK: store i8* bitcast (void (i8*)* [[RED_FINI2:@.+]] to i8*), i8** [[TMP40]], align 8
99// CHECK: [[TMP41:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 4
100// CHECK: store i8* bitcast (void (i8*, i8*)* [[RED_COMB2:@.+]] to i8*), i8** [[TMP41]], align 8
101// CHECK: [[TMP42:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 5
102// CHECK: store i32 1, i32* [[TMP42]], align 8
103// CHECK: [[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 2
104// CHECK: [[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: [[TMP44:%.*]] = load float*, float** [[D]], align 8
106// CHECK: [[TMP45:%.*]] = bitcast float* [[TMP44]] to i8*
107// CHECK: store i8* [[TMP45]], i8** [[TMP43]], align 8
108// CHECK: [[TMP46:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 1
109// CHECK: store i64 4, i64* [[TMP46]], align 8
110// CHECK: [[TMP47:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 2
111// CHECK: store i8* bitcast (void (i8*)* [[RED_INIT3:@.+]] to i8*), i8** [[TMP47]], align 8
112// CHECK: [[TMP48:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 3
113// CHECK: store i8* null, i8** [[TMP48]], align 8
114// CHECK: [[TMP49:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 4
115// CHECK: store i8* bitcast (void (i8*, i8*)* [[RED_COMB3:@.+]] to i8*), i8** [[TMP49]], align 8
116// CHECK: [[TMP50:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 5
117// CHECK: [[TMP51:%.*]] = bitcast i32* [[TMP50]] to i8*
118// CHECK: call void @llvm.memset.p0i8.i64(i8* [[TMP51]], i8 0, i64 4, i32 8, i1 false)
119// CHECK: [[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 3
120// CHECK: [[TMP52:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 0
121// CHECK: [[TMP53:%.*]] = bitcast float* [[VLA]] to i8*
122// CHECK: store i8* [[TMP53]], i8** [[TMP52]], align 8
123// CHECK: [[TMP54:%.*]] = mul nuw i64 [[TMP2]], 4
124// CHECK: [[TMP55:%.*]] = udiv exact i64 [[TMP54]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
125// CHECK: [[TMP56:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 1
126// CHECK: store i64 [[TMP54]], i64* [[TMP56]], align 8
127// CHECK: [[TMP57:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 2
128// CHECK: store i8* bitcast (void (i8*)* [[RED_INIT4:@.+]] to i8*), i8** [[TMP57]], align 8
129// CHECK: [[TMP58:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 3
130// CHECK: store i8* null, i8** [[TMP58]], align 8
131// CHECK: [[TMP59:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 4
132// CHECK: store i8* bitcast (void (i8*, i8*)* [[RED_COMB4:@.+]] to i8*), i8** [[TMP59]], align 8
133// CHECK: [[TMP60:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 5
134// CHECK: store i32 1, i32* [[TMP60]], align 8
135// 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]])
137// CHECK: [[TMP63:%.*]] = load i32, i32* [[N]], align 4
138// CHECK: store i32 [[TMP63]], i32* [[DOTCAPTURE_EXPR_]], align 4
139// CHECK: [[TMP64:%.*]] = load i32, i32* [[DOTCAPTURE_EXPR_]], align 4
140// 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
145// CHECK: store i32 [[SUB12]], i32* [[DOTCAPTURE_EXPR_9]], align 4
146// 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*)*))
147// CHECK: [[TMP66:%.*]] = bitcast i8* [[TMP65]] to %struct.kmp_task_t_with_privates*
148// CHECK: [[TMP67:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], %struct.kmp_task_t_with_privates* [[TMP66]], i32 0, i32 0
149// CHECK: [[TMP68:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T:%.*]], %struct.kmp_task_t* [[TMP67]], i32 0, i32 0
150// CHECK: [[TMP69:%.*]] = load i8*, i8** [[TMP68]], align 8
151// CHECK: [[TMP70:%.*]] = bitcast %struct.anon* [[AGG_CAPTURED]] to i8*
152// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP69]], i8* [[TMP70]], i64 72, i32 8, i1 false)
153// CHECK: [[TMP71:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES]], %struct.kmp_task_t_with_privates* [[TMP66]], i32 0, i32 1
154// CHECK: [[TMP72:%.*]] = bitcast i8* [[TMP69]] to %struct.anon*
155// CHECK: [[TMP73:%.*]] = getelementptr inbounds [[STRUCT__KMP_PRIVATES_T:%.*]], %struct..kmp_privates.t* [[TMP71]], i32 0, i32 0
156// CHECK: [[TMP74:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[TMP72]], i32 0, i32 1
157// CHECK: [[REF:%.*]] = load i32*, i32** [[TMP74]], align 8
158// CHECK: [[TMP75:%.*]] = load i32, i32* [[REF]], align 4
159// CHECK: store i32 [[TMP75]], i32* [[TMP73]], align 8
160// CHECK: [[TMP76:%.*]] = getelementptr inbounds [[STRUCT__KMP_PRIVATES_T]], %struct..kmp_privates.t* [[TMP71]], i32 0, i32 1
161// CHECK: [[TMP77:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[TMP72]], i32 0, i32 3
162// CHECK: [[REF13:%.*]] = load [100 x float]*, [100 x float]** [[TMP77]], align 8
163// CHECK: [[TMP78:%.*]] = bitcast [100 x float]* [[TMP76]] to i8*
164// CHECK: [[TMP79:%.*]] = bitcast [100 x float]* [[REF13]] to i8*
165// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP78]], i8* [[TMP79]], i64 400, i32 4, i1 false)
166// CHECK: [[TMP80:%.*]] = getelementptr inbounds [[STRUCT__KMP_PRIVATES_T]], %struct..kmp_privates.t* [[TMP71]], i32 0, i32 2
167// CHECK: [[TMP81:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[TMP72]], i32 0, i32 4
168// CHECK: [[REF14:%.*]] = load [100 x float]*, [100 x float]** [[TMP81]], align 8
169// CHECK: [[TMP82:%.*]] = bitcast [100 x float]* [[TMP80]] to i8*
170// CHECK: [[TMP83:%.*]] = bitcast [100 x float]* [[REF14]] to i8*
171// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP82]], i8* [[TMP83]], i64 400, i32 4, i1 false)
172// CHECK: [[TMP84:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T]], %struct.kmp_task_t* [[TMP67]], i32 0, i32 5
173// CHECK: store i64 0, i64* [[TMP84]], align 8
174// CHECK: [[TMP85:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T]], %struct.kmp_task_t* [[TMP67]], i32 0, i32 6
175// CHECK: [[TMP86:%.*]] = load i32, i32* [[DOTCAPTURE_EXPR_9]], align 4
176// CHECK: [[CONV15:%.*]] = sext i32 [[TMP86]] to i64
177// CHECK: store i64 [[CONV15]], i64* [[TMP85]], align 8
178// CHECK: [[TMP87:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T]], %struct.kmp_task_t* [[TMP67]], i32 0, i32 7
179// CHECK: store i64 1, i64* [[TMP87]], align 8
180// CHECK: [[TMP88:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T]], %struct.kmp_task_t* [[TMP67]], i32 0, i32 9
181// CHECK: store i8* [[TMP62]], i8** [[TMP88]], align 8
182// CHECK: [[TMP89:%.*]] = load i64, i64* [[TMP87]], align 8
183// CHECK: call void @__kmpc_taskloop(%ident_t* %{{.+}}, i32 [[TMP0]], i8* [[TMP65]], i32 1, i64* [[TMP84]], i64* [[TMP85]], i64 [[TMP89]], i32 0, i32 0, i64 0, i8* null)
184// CHECK: call void @__kmpc_end_taskgroup(%ident_t*
185
186// CHECK: ret i32
187
188// CHECK: define internal void [[RED_INIT1]](i8*)
189// CHECK: store float 0.000000e+00, float* %
190// CHECK: ret void
191
192// CHECK: define internal void [[RED_COMB1]](i8*, i8*)
193// CHECK: fadd float %6, %7
194// CHECK: store float %{{.+}}, float* %
195// CHECK: ret void
196
197// CHECK: define internal void [[RED_INIT2]](i8*)
198// CHECK: call i8* @__kmpc_threadprivate_cached(
199// CHECK: call i8* @__kmpc_threadprivate_cached(
200// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(
201// CHECK: ret void
202
203// CHECK: define internal void [[RED_FINI2]](i8*)
204// CHECK: call i8* @__kmpc_threadprivate_cached(
205// CHECK: call void @
206// CHECK: ret void
207
208// CHECK: define internal void [[RED_COMB2]](i8*, i8*)
209// CHECK: call i8* @__kmpc_threadprivate_cached(
210// CHECK: fadd float %
211// CHECK: store float %{{.+}}, float* %
212// CHECK: ret void
213
214// CHECK: define internal void [[RED_INIT3]](i8*)
215// CHECK: store float 0.000000e+00, float* %
216// CHECK: ret void
217
218// CHECK: define internal void [[RED_COMB3]](i8*, i8*)
219// CHECK: fadd float %
220// CHECK: store float %{{.+}}, float* %
221// CHECK: ret void
222
223// CHECK: define internal void [[RED_INIT4]](i8*)
224// CHECK: call i8* @__kmpc_threadprivate_cached(
225// CHECK: store float 0.000000e+00, float* %
226// CHECK: ret void
227
228// CHECK: define internal void [[RED_COMB4]](i8*, i8*)
229// CHECK: call i8* @__kmpc_threadprivate_cached(
230// CHECK: fadd float %
231// CHECK: store float %{{.+}}, float* %
232// CHECK: ret void
233