blob: c6381682580eb1a2a90df977f9359c5c6216a088 [file] [log] [blame]
Alexey Bataev9e4b8202015-04-22 12:20:41 +00001// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
Alexander Musmana5f070a2014-10-01 06:03:56 +00002// RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3// RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -g -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
Alexey Bataev36bf0112015-03-10 05:15:26 +00004// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp=libiomp5 -fexceptions -fcxx-exceptions -gline-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
Adrian Prantlcbc368c2015-02-25 02:44:04 +00005//
Alexander Musmana5f070a2014-10-01 06:03:56 +00006// expected-no-diagnostics
7#ifndef HEADER
8#define HEADER
9
Alexander Musman3276a272015-03-21 10:12:56 +000010long long get_val() { return 0; }
11double *g_ptr;
12
Alexander Musmana5f070a2014-10-01 06:03:56 +000013// CHECK-LABEL: define {{.*void}} @{{.*}}simple{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
14void simple(float *a, float *b, float *c, float *d) {
15 #pragma omp simd
16// CHECK: store i32 0, i32* [[OMP_IV:%[^,]+]]
17
David Blaikiea953f282015-02-27 21:19:58 +000018// CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000019// CHECK-NEXT: [[CMP:%.+]] = icmp slt i32 [[IV]], 6
20// CHECK-NEXT: br i1 [[CMP]], label %[[SIMPLE_LOOP1_BODY:.+]], label %[[SIMPLE_LOOP1_END:[^,]+]]
21 for (int i = 3; i < 32; i += 5) {
22// CHECK: [[SIMPLE_LOOP1_BODY]]
23// Start of body: calculate i from IV:
David Blaikiea953f282015-02-27 21:19:58 +000024// CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000025// CHECK: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 5
26// CHECK-NEXT: [[CALC_I_2:%.+]] = add nsw i32 3, [[CALC_I_1]]
27// CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID]]
28// ... loop body ...
29// End of body: store into a[i]:
30// CHECK: store float [[RESULT:%.+]], float* {{%.+}}{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID]]
31 a[i] = b[i] * c[i] * d[i];
David Blaikiea953f282015-02-27 21:19:58 +000032// CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000033// CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
34// CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP1_ID]]
35// br label %{{.+}}, !llvm.loop !{{.+}}
36 }
37// CHECK: [[SIMPLE_LOOP1_END]]
38
Alexander Musman3276a272015-03-21 10:12:56 +000039 long long k = get_val();
40
41 #pragma omp simd linear(k : 3)
42// CHECK: [[K0:%.+]] = call {{.*}}i64 @{{.*}}get_val
43// CHECK-NEXT: store i64 [[K0]], i64* [[K_VAR:%[^,]+]]
44// CHECK: [[K0LOAD:%.+]] = load i64, i64* [[K_VAR]]
45// CHECK-NEXT: store i64 [[K0LOAD]], i64* [[LIN0:%[^,]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000046// CHECK: store i32 0, i32* [[OMP_IV2:%[^,]+]]
47
David Blaikiea953f282015-02-27 21:19:58 +000048// CHECK: [[IV2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000049// CHECK-NEXT: [[CMP2:%.+]] = icmp slt i32 [[IV2]], 9
50// CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP2_BODY:.+]], label %[[SIMPLE_LOOP2_END:[^,]+]]
51 for (int i = 10; i > 1; i--) {
52// CHECK: [[SIMPLE_LOOP2_BODY]]
53// Start of body: calculate i from IV:
David Blaikiea953f282015-02-27 21:19:58 +000054// CHECK: [[IV2_0:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000055// FIXME: It is interesting, why the following "mul 1" was not constant folded?
56// CHECK-NEXT: [[IV2_1:%.+]] = mul nsw i32 [[IV2_0]], 1
57// CHECK-NEXT: [[LC_I_1:%.+]] = sub nsw i32 10, [[IV2_1]]
58// CHECK-NEXT: store i32 [[LC_I_1]], i32* {{.+}}, !llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
Alexander Musman3276a272015-03-21 10:12:56 +000059//
60// CHECK-NEXT: [[LIN0_1:%.+]] = load i64, i64* [[LIN0]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
61// CHECK-NEXT: [[IV2_2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
62// CHECK-NEXT: [[LIN_MUL1:%.+]] = mul nsw i32 [[IV2_2]], 3
63// CHECK-NEXT: [[LIN_EXT1:%.+]] = sext i32 [[LIN_MUL1]] to i64
64// CHECK-NEXT: [[LIN_ADD1:%.+]] = add nsw i64 [[LIN0_1]], [[LIN_EXT1]]
65// Update of the privatized version of linear variable!
66// CHECK-NEXT: store i64 [[LIN_ADD1]], i64* [[K_PRIVATIZED:%[^,]+]]
67 a[k]++;
68 k = k + 3;
David Blaikiea953f282015-02-27 21:19:58 +000069// CHECK: [[IV2_2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000070// CHECK-NEXT: [[ADD2_2:%.+]] = add nsw i32 [[IV2_2]], 1
71// CHECK-NEXT: store i32 [[ADD2_2]], i32* [[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
72// br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP2_ID]]
73 }
74// CHECK: [[SIMPLE_LOOP2_END]]
Alexander Musman3276a272015-03-21 10:12:56 +000075//
76// Update linear vars after loop, as the loop was operating on a private version.
77// CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
78// CHECK-NEXT: [[LIN_ADD2:%.+]] = add nsw i64 [[LIN0_2]], 27
79// CHECK-NEXT: store i64 [[LIN_ADD2]], i64* [[K_VAR]]
80//
Alexander Musmana5f070a2014-10-01 06:03:56 +000081
Alexander Musman3276a272015-03-21 10:12:56 +000082 int lin = 12;
83 #pragma omp simd linear(lin : get_val()), linear(g_ptr)
84
85// Init linear private var.
86// CHECK: store i32 12, i32* [[LIN_VAR:%[^,]+]]
87// CHECK: [[LIN_LOAD:%.+]] = load i32, i32* [[LIN_VAR]]
88// CHECK-NEXT: store i32 [[LIN_LOAD]], i32* [[LIN_START:%[^,]+]]
89// CHECK: [[GLIN_LOAD:%.+]] = load double*, double** [[GLIN_VAR:@[^,]+]]
90// CHECK-NEXT: store double* [[GLIN_LOAD]], double** [[GLIN_START:%[^,]+]]
91
Alexander Musmana5f070a2014-10-01 06:03:56 +000092// CHECK: store i64 0, i64* [[OMP_IV3:%[^,]+]]
93
Alexander Musman3276a272015-03-21 10:12:56 +000094// Remember linear step.
95// CHECK: [[CALL_VAL:%.+]] = invoke
96// CHECK: store i64 [[CALL_VAL]], i64* [[LIN_STEP:%[^,]+]]
97
David Blaikiea953f282015-02-27 21:19:58 +000098// CHECK: [[IV3:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +000099// CHECK-NEXT: [[CMP3:%.+]] = icmp ult i64 [[IV3]], 4
100// CHECK-NEXT: br i1 [[CMP3]], label %[[SIMPLE_LOOP3_BODY:.+]], label %[[SIMPLE_LOOP3_END:[^,]+]]
101 for (unsigned long long it = 2000; it >= 600; it-=400) {
102// CHECK: [[SIMPLE_LOOP3_BODY]]
103// Start of body: calculate it from IV:
David Blaikiea953f282015-02-27 21:19:58 +0000104// CHECK: [[IV3_0:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000105// CHECK-NEXT: [[LC_IT_1:%.+]] = mul i64 [[IV3_0]], 400
106// CHECK-NEXT: [[LC_IT_2:%.+]] = sub i64 2000, [[LC_IT_1]]
107// CHECK-NEXT: store i64 [[LC_IT_2]], i64* {{.+}}, !llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
Alexander Musman3276a272015-03-21 10:12:56 +0000108//
109// Linear start and step are used to calculate current value of the linear variable.
110// CHECK: [[LINSTART:.+]] = load i32, i32* [[LIN_START]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
111// CHECK: [[LINSTEP:.+]] = load i64, i64* [[LIN_STEP]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
112// CHECK-NOT: store i32 {{.+}}, i32* [[LIN_VAR]],{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
113// CHECK: [[GLINSTART:.+]] = load double*, double** [[GLIN_START]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
114// CHECK-NEXT: [[IV3_1:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
115// CHECK-NEXT: [[MUL:%.+]] = mul i64 [[IV3_1]], 1
Alexander Musman04701242015-03-21 11:49:27 +0000116// CHECK: [[GEP:%.+]] = getelementptr{{.*}}[[GLINSTART]]
Alexander Musman3276a272015-03-21 10:12:56 +0000117// CHECK-NEXT: store double* [[GEP]], double** [[G_PTR_CUR:%[^,]+]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
118 *g_ptr++ = 0.0;
119// CHECK: [[GEP_VAL:%.+]] = load double{{.*}}[[G_PTR_CUR]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
120// CHECK: store double{{.*}}[[GEP_VAL]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
121 a[it + lin]++;
122// CHECK: [[FLT_INC:%.+]] = fadd float
123// CHECK-NEXT: store float [[FLT_INC]],{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
David Blaikiea953f282015-02-27 21:19:58 +0000124// CHECK: [[IV3_2:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000125// CHECK-NEXT: [[ADD3_2:%.+]] = add i64 [[IV3_2]], 1
126// CHECK-NEXT: store i64 [[ADD3_2]], i64* [[OMP_IV3]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP3_ID]]
127 }
128// CHECK: [[SIMPLE_LOOP3_END]]
Alexander Musman3276a272015-03-21 10:12:56 +0000129//
130// Linear start and step are used to calculate final value of the linear variables.
131// CHECK: [[LINSTART:.+]] = load i32, i32* [[LIN_START]]
132// CHECK: [[LINSTEP:.+]] = load i64, i64* [[LIN_STEP]]
133// CHECK: store i32 {{.+}}, i32* [[LIN_VAR]],
134// CHECK: [[GLINSTART:.+]] = load double*, double** [[GLIN_START]]
135// CHECK: store double* {{.*}}[[GLIN_VAR]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000136
137 #pragma omp simd
138// CHECK: store i32 0, i32* [[OMP_IV4:%[^,]+]]
139
David Blaikiea953f282015-02-27 21:19:58 +0000140// CHECK: [[IV4:%.+]] = load i32, i32* [[OMP_IV4]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP4_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000141// CHECK-NEXT: [[CMP4:%.+]] = icmp slt i32 [[IV4]], 4
142// CHECK-NEXT: br i1 [[CMP4]], label %[[SIMPLE_LOOP4_BODY:.+]], label %[[SIMPLE_LOOP4_END:[^,]+]]
143 for (short it = 6; it <= 20; it-=-4) {
144// CHECK: [[SIMPLE_LOOP4_BODY]]
145// Start of body: calculate it from IV:
David Blaikiea953f282015-02-27 21:19:58 +0000146// CHECK: [[IV4_0:%.+]] = load i32, i32* [[OMP_IV4]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP4_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000147// CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i32 [[IV4_0]], 4
148// CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i32 6, [[LC_IT_1]]
149// CHECK-NEXT: [[LC_IT_3:%.+]] = trunc i32 [[LC_IT_2]] to i16
150// CHECK-NEXT: store i16 [[LC_IT_3]], i16* {{.+}}, !llvm.mem.parallel_loop_access ![[SIMPLE_LOOP4_ID]]
151
David Blaikiea953f282015-02-27 21:19:58 +0000152// CHECK: [[IV4_2:%.+]] = load i32, i32* [[OMP_IV4]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP4_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000153// CHECK-NEXT: [[ADD4_2:%.+]] = add nsw i32 [[IV4_2]], 1
154// CHECK-NEXT: store i32 [[ADD4_2]], i32* [[OMP_IV4]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP4_ID]]
155 }
156// CHECK: [[SIMPLE_LOOP4_END]]
157
158 #pragma omp simd
159// CHECK: store i32 0, i32* [[OMP_IV5:%[^,]+]]
160
David Blaikiea953f282015-02-27 21:19:58 +0000161// CHECK: [[IV5:%.+]] = load i32, i32* [[OMP_IV5]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP5_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000162// CHECK-NEXT: [[CMP5:%.+]] = icmp slt i32 [[IV5]], 26
163// CHECK-NEXT: br i1 [[CMP5]], label %[[SIMPLE_LOOP5_BODY:.+]], label %[[SIMPLE_LOOP5_END:[^,]+]]
164 for (unsigned char it = 'z'; it >= 'a'; it+=-1) {
165// CHECK: [[SIMPLE_LOOP5_BODY]]
166// Start of body: calculate it from IV:
David Blaikiea953f282015-02-27 21:19:58 +0000167// CHECK: [[IV5_0:%.+]] = load i32, i32* [[OMP_IV5]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP5_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000168// CHECK-NEXT: [[IV5_1:%.+]] = mul nsw i32 [[IV5_0]], 1
169// CHECK-NEXT: [[LC_IT_1:%.+]] = sub nsw i32 122, [[IV5_1]]
170// CHECK-NEXT: [[LC_IT_2:%.+]] = trunc i32 [[LC_IT_1]] to i8
171// CHECK-NEXT: store i8 [[LC_IT_2]], i8* {{.+}}, !llvm.mem.parallel_loop_access ![[SIMPLE_LOOP5_ID]]
172
David Blaikiea953f282015-02-27 21:19:58 +0000173// CHECK: [[IV5_2:%.+]] = load i32, i32* [[OMP_IV5]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP5_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000174// CHECK-NEXT: [[ADD5_2:%.+]] = add nsw i32 [[IV5_2]], 1
175// CHECK-NEXT: store i32 [[ADD5_2]], i32* [[OMP_IV5]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP5_ID]]
176 }
177// CHECK: [[SIMPLE_LOOP5_END]]
178
Alexey Bataev62dbb972015-04-22 11:59:37 +0000179// CHECK-NOT: mul i32 %{{.+}}, 10
Alexander Musmana5f070a2014-10-01 06:03:56 +0000180 #pragma omp simd
Alexey Bataev62dbb972015-04-22 11:59:37 +0000181 for (unsigned i=100; i<10; i+=10) {
Alexander Musmana5f070a2014-10-01 06:03:56 +0000182 }
Alexander Musmana5f070a2014-10-01 06:03:56 +0000183
184 int A;
185 #pragma omp simd lastprivate(A)
186// Clause 'lastprivate' implementation is not completed yet.
187// Test checks that one iteration is separated in presence of lastprivate.
188//
189// CHECK: store i64 0, i64* [[OMP_IV7:%[^,]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000190// CHECK: br label %[[SIMD_LOOP7_COND:[^,]+]]
191// CHECK: [[SIMD_LOOP7_COND]]
David Blaikiea953f282015-02-27 21:19:58 +0000192// CHECK-NEXT: [[IV7:%.+]] = load i64, i64* [[OMP_IV7]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP7_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000193// CHECK-NEXT: [[CMP7:%.+]] = icmp slt i64 [[IV7]], 6
194// CHECK-NEXT: br i1 [[CMP7]], label %[[SIMPLE_LOOP7_BODY:.+]], label %[[SIMPLE_LOOP7_END:[^,]+]]
195 for (long long i = -10; i < 10; i += 3) {
196// CHECK: [[SIMPLE_LOOP7_BODY]]
197// Start of body: calculate i from IV:
David Blaikiea953f282015-02-27 21:19:58 +0000198// CHECK: [[IV7_0:%.+]] = load i64, i64* [[OMP_IV7]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP7_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000199// CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i64 [[IV7_0]], 3
200// CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i64 -10, [[LC_IT_1]]
201// CHECK-NEXT: store i64 [[LC_IT_2]], i64* {{.+}}, !llvm.mem.parallel_loop_access ![[SIMPLE_LOOP7_ID]]
202 A = i;
David Blaikiea953f282015-02-27 21:19:58 +0000203// CHECK: [[IV7_2:%.+]] = load i64, i64* [[OMP_IV7]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP7_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000204// CHECK-NEXT: [[ADD7_2:%.+]] = add nsw i64 [[IV7_2]], 1
205// CHECK-NEXT: store i64 [[ADD7_2]], i64* [[OMP_IV7]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP7_ID]]
206 }
207// CHECK: [[SIMPLE_LOOP7_END]]
208// Separated last iteration.
David Blaikiea953f282015-02-27 21:19:58 +0000209// CHECK: [[IV7_4:%.+]] = load i64, i64* [[OMP_IV7]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000210// CHECK-NEXT: [[LC_FIN_1:%.+]] = mul nsw i64 [[IV7_4]], 3
211// CHECK-NEXT: [[LC_FIN_2:%.+]] = add nsw i64 -10, [[LC_FIN_1]]
212// CHECK-NEXT: store i64 [[LC_FIN_2]], i64* [[ADDR_I:%[^,]+]]
David Blaikiea953f282015-02-27 21:19:58 +0000213// CHECK: [[LOAD_I:%.+]] = load i64, i64* [[ADDR_I]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000214// CHECK-NEXT: [[CONV_I:%.+]] = trunc i64 [[LOAD_I]] to i32
215//
Alexander Musmana5f070a2014-10-01 06:03:56 +0000216
217// CHECK: ret void
218}
219
220template <class T, unsigned K> T tfoo(T a) { return a + K; }
221
222template <typename T, unsigned N>
223int templ1(T a, T *z) {
224 #pragma omp simd collapse(N)
225 for (int i = 0; i < N * 2; i++) {
226 for (long long j = 0; j < (N + N + N + N); j += 2) {
227 z[i + j] = a + tfoo<T, N>(i + j);
228 }
229 }
230 return 0;
231}
232
233// Instatiation templ1<float,2>
234// CHECK-LABEL: define {{.*i32}} @{{.*}}templ1{{.*}}(float {{.+}}, float* {{.+}})
235// CHECK: store i64 0, i64* [[T1_OMP_IV:[^,]+]]
236// ...
David Blaikiea953f282015-02-27 21:19:58 +0000237// CHECK: [[IV:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[T1_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000238// CHECK-NEXT: [[CMP1:%.+]] = icmp slt i64 [[IV]], 16
239// CHECK-NEXT: br i1 [[CMP1]], label %[[T1_BODY:.+]], label %[[T1_END:[^,]+]]
240// CHECK: [[T1_BODY]]
241// Loop counters i and j updates:
David Blaikiea953f282015-02-27 21:19:58 +0000242// CHECK: [[IV1:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[T1_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000243// CHECK-NEXT: [[I_1:%.+]] = sdiv i64 [[IV1]], 4
244// CHECK-NEXT: [[I_1_MUL1:%.+]] = mul nsw i64 [[I_1]], 1
245// CHECK-NEXT: [[I_1_ADD0:%.+]] = add nsw i64 0, [[I_1_MUL1]]
246// CHECK-NEXT: [[I_2:%.+]] = trunc i64 [[I_1_ADD0]] to i32
247// CHECK-NEXT: store i32 [[I_2]], i32* {{%.+}}{{.*}}!llvm.mem.parallel_loop_access ![[T1_ID]]
David Blaikiea953f282015-02-27 21:19:58 +0000248// CHECK: [[IV2:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[T1_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000249// CHECK-NEXT: [[J_1:%.+]] = srem i64 [[IV2]], 4
250// CHECK-NEXT: [[J_2:%.+]] = mul nsw i64 [[J_1]], 2
251// CHECK-NEXT: [[J_2_ADD0:%.+]] = add nsw i64 0, [[J_2]]
252// CHECK-NEXT: store i64 [[J_2_ADD0]], i64* {{%.+}}{{.*}}!llvm.mem.parallel_loop_access ![[T1_ID]]
253// simd.for.inc:
David Blaikiea953f282015-02-27 21:19:58 +0000254// CHECK: [[IV3:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[T1_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000255// CHECK-NEXT: [[INC:%.+]] = add nsw i64 [[IV3]], 1
256// CHECK-NEXT: store i64 [[INC]], i64* [[T1_OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[T1_ID]]
257// CHECK-NEXT: br label {{%.+}}
258// CHECK: [[T1_END]]
259// CHECK: ret i32 0
260//
261void inst_templ1() {
262 float a;
263 float z[100];
264 templ1<float,2> (a, z);
265}
266
267
268typedef int MyIdx;
269
270class IterDouble {
271 double *Ptr;
272public:
273 IterDouble operator++ () const {
274 IterDouble n;
275 n.Ptr = Ptr + 1;
276 return n;
277 }
278 bool operator < (const IterDouble &that) const {
279 return Ptr < that.Ptr;
280 }
281 double & operator *() const {
282 return *Ptr;
283 }
284 MyIdx operator - (const IterDouble &that) const {
285 return (MyIdx) (Ptr - that.Ptr);
286 }
287 IterDouble operator + (int Delta) {
288 IterDouble re;
289 re.Ptr = Ptr + Delta;
290 return re;
291 }
292
293 ///~IterDouble() {}
294};
295
296// CHECK-LABEL: define {{.*void}} @{{.*}}iter_simple{{.*}}
297void iter_simple(IterDouble ia, IterDouble ib, IterDouble ic) {
298//
299// CHECK: store i32 0, i32* [[IT_OMP_IV:%[^,]+]]
300// Calculate number of iterations before the loop body.
Alexey Bataev36bf0112015-03-10 05:15:26 +0000301// CHECK: [[DIFF1:%.+]] = invoke {{.*}}i32 @{{.*}}IterDouble{{.*}}
302// CHECK: [[DIFF2:%.+]] = sub nsw i32 [[DIFF1]], 1
Alexander Musmana5f070a2014-10-01 06:03:56 +0000303// CHECK-NEXT: [[DIFF3:%.+]] = add nsw i32 [[DIFF2]], 1
304// CHECK-NEXT: [[DIFF4:%.+]] = sdiv i32 [[DIFF3]], 1
305// CHECK-NEXT: [[DIFF5:%.+]] = sub nsw i32 [[DIFF4]], 1
306// CHECK-NEXT: store i32 [[DIFF5]], i32* [[OMP_LAST_IT:%[^,]+]]{{.+}}
307 #pragma omp simd
308
David Blaikiea953f282015-02-27 21:19:58 +0000309// CHECK: [[IV:%.+]] = load i32, i32* [[IT_OMP_IV]]{{.+}} !llvm.mem.parallel_loop_access ![[ITER_LOOP_ID:[0-9]+]]
310// CHECK-NEXT: [[LAST_IT:%.+]] = load i32, i32* [[OMP_LAST_IT]]{{.+}}!llvm.mem.parallel_loop_access ![[ITER_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000311// CHECK-NEXT: [[NUM_IT:%.+]] = add nsw i32 [[LAST_IT]], 1
312// CHECK-NEXT: [[CMP:%.+]] = icmp slt i32 [[IV]], [[NUM_IT]]
313// CHECK-NEXT: br i1 [[CMP]], label %[[IT_BODY:[^,]+]], label %[[IT_END:[^,]+]]
314 for (IterDouble i = ia; i < ib; ++i) {
315// CHECK: [[IT_BODY]]
316// Start of body: calculate i from index:
David Blaikiea953f282015-02-27 21:19:58 +0000317// CHECK: [[IV1:%.+]] = load i32, i32* [[IT_OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[ITER_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000318// Call of operator+ (i, IV).
Alexey Bataev36bf0112015-03-10 05:15:26 +0000319// CHECK: {{%.+}} = invoke {{.+}} @{{.*}}IterDouble{{.*}}
Alexander Musmana5f070a2014-10-01 06:03:56 +0000320// ... loop body ...
321 *i = *ic * 0.5;
322// Float multiply and save result.
323// CHECK: [[MULR:%.+]] = fmul double {{%.+}}, 5.000000e-01
Alexey Bataev36bf0112015-03-10 05:15:26 +0000324// CHECK-NEXT: invoke {{.+}} @{{.*}}IterDouble{{.*}}
Alexander Musmana5f070a2014-10-01 06:03:56 +0000325// CHECK: store double [[MULR:%.+]], double* [[RESULT_ADDR:%.+]], !llvm.mem.parallel_loop_access ![[ITER_LOOP_ID]]
326 ++ic;
327//
David Blaikiea953f282015-02-27 21:19:58 +0000328// CHECK: [[IV2:%.+]] = load i32, i32* [[IT_OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[ITER_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000329// CHECK-NEXT: [[ADD2:%.+]] = add nsw i32 [[IV2]], 1
330// CHECK-NEXT: store i32 [[ADD2]], i32* [[IT_OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[ITER_LOOP_ID]]
331// br label %{{.*}}, !llvm.loop ![[ITER_LOOP_ID]]
332 }
333// CHECK: [[IT_END]]
334// CHECK: ret void
335}
336
337
338// CHECK-LABEL: define {{.*void}} @{{.*}}collapsed{{.*}}
339void collapsed(float *a, float *b, float *c, float *d) {
340 int i; // outer loop counter
341 unsigned j; // middle loop couter, leads to unsigned icmp in loop header.
342 // k declared in the loop init below
343 short l; // inner loop counter
344// CHECK: store i32 0, i32* [[OMP_IV:[^,]+]]
345//
346 #pragma omp simd collapse(4)
347
David Blaikiea953f282015-02-27 21:19:58 +0000348// CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID:[0-9]+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000349// CHECK-NEXT: [[CMP:%.+]] = icmp ult i32 [[IV]], 120
350// CHECK-NEXT: br i1 [[CMP]], label %[[COLL1_BODY:[^,]+]], label %[[COLL1_END:[^,]+]]
351 for (i = 1; i < 3; i++) // 2 iterations
352 for (j = 2u; j < 5u; j++) //3 iterations
353 for (int k = 3; k <= 6; k++) // 4 iterations
354 for (l = 4; l < 9; ++l) // 5 iterations
355 {
356// CHECK: [[COLL1_BODY]]
357// Start of body: calculate i from index:
David Blaikiea953f282015-02-27 21:19:58 +0000358// CHECK: [[IV1:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000359// Calculation of the loop counters values.
360// CHECK: [[CALC_I_1:%.+]] = udiv i32 [[IV1]], 60
361// CHECK-NEXT: [[CALC_I_1_MUL1:%.+]] = mul i32 [[CALC_I_1]], 1
362// CHECK-NEXT: [[CALC_I_2:%.+]] = add i32 1, [[CALC_I_1_MUL1]]
363// CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
David Blaikiea953f282015-02-27 21:19:58 +0000364// CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000365// CHECK-NEXT: [[CALC_J_1:%.+]] = udiv i32 [[IV1_2]], 20
366// CHECK-NEXT: [[CALC_J_2:%.+]] = urem i32 [[CALC_J_1]], 3
367// CHECK-NEXT: [[CALC_J_2_MUL1:%.+]] = mul i32 [[CALC_J_2]], 1
368// CHECK-NEXT: [[CALC_J_3:%.+]] = add i32 2, [[CALC_J_2_MUL1]]
369// CHECK-NEXT: store i32 [[CALC_J_3]], i32* [[LC_J:.+]]
David Blaikiea953f282015-02-27 21:19:58 +0000370// CHECK: [[IV1_3:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000371// CHECK-NEXT: [[CALC_K_1:%.+]] = udiv i32 [[IV1_3]], 5
372// CHECK-NEXT: [[CALC_K_2:%.+]] = urem i32 [[CALC_K_1]], 4
373// CHECK-NEXT: [[CALC_K_2_MUL1:%.+]] = mul i32 [[CALC_K_2]], 1
374// CHECK-NEXT: [[CALC_K_3:%.+]] = add i32 3, [[CALC_K_2_MUL1]]
375// CHECK-NEXT: store i32 [[CALC_K_3]], i32* [[LC_K:.+]]
David Blaikiea953f282015-02-27 21:19:58 +0000376// CHECK: [[IV1_4:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000377// CHECK-NEXT: [[CALC_L_1:%.+]] = urem i32 [[IV1_4]], 5
378// CHECK-NEXT: [[CALC_L_1_MUL1:%.+]] = mul i32 [[CALC_L_1]], 1
379// CHECK-NEXT: [[CALC_L_2:%.+]] = add i32 4, [[CALC_L_1_MUL1]]
380// CHECK-NEXT: [[CALC_L_3:%.+]] = trunc i32 [[CALC_L_2]] to i16
381// CHECK-NEXT: store i16 [[CALC_L_3]], i16* [[LC_L:.+]]
382// ... loop body ...
383// End of body: store into a[i]:
384// CHECK: store float [[RESULT:%.+]], float* [[RESULT_ADDR:%.+]]{{.+}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID]]
385 float res = b[j] * c[k];
386 a[i] = res * d[l];
David Blaikiea953f282015-02-27 21:19:58 +0000387// CHECK: [[IV2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000388// CHECK-NEXT: [[ADD2:%.+]] = add i32 [[IV2]], 1
389// CHECK-NEXT: store i32 [[ADD2]], i32* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[COLL1_LOOP_ID]]
390// br label %{{[^,]+}}, !llvm.loop ![[COLL1_LOOP_ID]]
391// CHECK: [[COLL1_END]]
392 }
393// i,j,l are updated; k is not updated.
394// CHECK: store i32 3, i32* [[I:%[^,]+]]
395// CHECK-NEXT: store i32 5, i32* [[I:%[^,]+]]
396// CHECK-NEXT: store i16 9, i16* [[I:%[^,]+]]
397// CHECK: ret void
398}
399
400extern char foo();
Alexander Musman7931b982015-03-16 07:14:41 +0000401extern double globalfloat;
Alexander Musmana5f070a2014-10-01 06:03:56 +0000402
403// CHECK-LABEL: define {{.*void}} @{{.*}}widened{{.*}}
404void widened(float *a, float *b, float *c, float *d) {
405 int i; // outer loop counter
406 short j; // inner loop counter
Alexander Musman7931b982015-03-16 07:14:41 +0000407 globalfloat = 1.0;
408 int localint = 1;
409// CHECK: store double {{.+}}, double* [[GLOBALFLOAT:@.+]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000410// Counter is widened to 64 bits.
411// CHECK: store i64 0, i64* [[OMP_IV:[^,]+]]
412//
Alexander Musman7931b982015-03-16 07:14:41 +0000413 #pragma omp simd collapse(2) private(globalfloat, localint)
Alexander Musmana5f070a2014-10-01 06:03:56 +0000414
David Blaikiea953f282015-02-27 21:19:58 +0000415// CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID:[0-9]+]]
416// CHECK-NEXT: [[LI:%.+]] = load i64, i64* [[OMP_LI:%[^,]+]]{{.+}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000417// CHECK-NEXT: [[NUMIT:%.+]] = add nsw i64 [[LI]], 1
418// CHECK-NEXT: [[CMP:%.+]] = icmp slt i64 [[IV]], [[NUMIT]]
419// CHECK-NEXT: br i1 [[CMP]], label %[[WIDE1_BODY:[^,]+]], label %[[WIDE1_END:[^,]+]]
420 for (i = 1; i < 3; i++) // 2 iterations
421 for (j = 0; j < foo(); j++) // foo() iterations
422 {
423// CHECK: [[WIDE1_BODY]]
424// Start of body: calculate i from index:
David Blaikiea953f282015-02-27 21:19:58 +0000425// CHECK: [[IV1:%.+]] = load i64, i64* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000426// Calculation of the loop counters values...
427// CHECK: store i32 {{[^,]+}}, i32* [[LC_I:.+]]
David Blaikiea953f282015-02-27 21:19:58 +0000428// CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.+}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000429// CHECK: store i16 {{[^,]+}}, i16* [[LC_J:.+]]
430// ... loop body ...
Alexander Musman7931b982015-03-16 07:14:41 +0000431//
432// Here we expect store into private double var, not global
433// CHECK-NOT: store double {{.+}}, double* [[GLOBALFLOAT]]
434 globalfloat = (float)j/i;
Alexander Musmana5f070a2014-10-01 06:03:56 +0000435 float res = b[j] * c[j];
Alexander Musman7931b982015-03-16 07:14:41 +0000436// Store into a[i]:
437// CHECK: store float [[RESULT:%.+]], float* [[RESULT_ADDR:%.+]]{{.+}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000438 a[i] = res * d[i];
Alexander Musman7931b982015-03-16 07:14:41 +0000439// Then there's a store into private var localint:
440// CHECK: store i32 {{.+}}, i32* [[LOCALINT:%[^,]+]]{{.+}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID]]
441 localint = (int)j;
David Blaikiea953f282015-02-27 21:19:58 +0000442// CHECK: [[IV2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID]]
Alexander Musmana5f070a2014-10-01 06:03:56 +0000443// CHECK-NEXT: [[ADD2:%.+]] = add nsw i64 [[IV2]], 1
444// CHECK-NEXT: store i64 [[ADD2]], i64* [[OMP_IV]]{{.*}}!llvm.mem.parallel_loop_access ![[WIDE1_LOOP_ID]]
Alexander Musman7931b982015-03-16 07:14:41 +0000445//
Alexander Musmana5f070a2014-10-01 06:03:56 +0000446// br label %{{[^,]+}}, !llvm.loop ![[WIDE1_LOOP_ID]]
447// CHECK: [[WIDE1_END]]
448 }
449// i,j are updated.
450// CHECK: store i32 3, i32* [[I:%[^,]+]]
451// CHECK: store i16
Alexander Musman7931b982015-03-16 07:14:41 +0000452//
453// Here we expect store into original localint, not its privatized version.
454// CHECK-NOT: store i32 {{.+}}, i32* [[LOCALINT]]
455 localint = (int)j;
Alexander Musmana5f070a2014-10-01 06:03:56 +0000456// CHECK: ret void
457}
458
Alexey Bataev36bf0112015-03-10 05:15:26 +0000459// TERM_DEBUG-LABEL: bar
460int bar() {return 0;};
461
462// TERM_DEBUG-LABEL: parallel_simd
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000463void parallel_simd(float *a) {
464#pragma omp parallel
465#pragma omp simd
Alexey Bataev36bf0112015-03-10 05:15:26 +0000466 // TERM_DEBUG-NOT: __kmpc_global_thread_num
467 // TERM_DEBUG: invoke i32 {{.*}}bar{{.*}}()
468 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
469 // TERM_DEBUG-NOT: __kmpc_global_thread_num
Alexey Bataevda19af42015-03-10 05:28:46 +0000470 // TERM_DEBUG: [[TERM_LPAD]]
Alexey Bataev36bf0112015-03-10 05:15:26 +0000471 // TERM_DEBUG: call void @__clang_call_terminate
472 // TERM_DEBUG: unreachable
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000473 for (unsigned i = 131071; i <= 2147483647; i += 127)
Alexey Bataev36bf0112015-03-10 05:15:26 +0000474 a[i] += bar();
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000475}
Alexander Musman7931b982015-03-16 07:14:41 +0000476// TERM_DEBUG: !{{[0-9]+}} = !MDLocation(line: [[@LINE-11]],
Alexander Musmana5f070a2014-10-01 06:03:56 +0000477#endif // HEADER
478