• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm -fexceptions -fcxx-exceptions -o - < %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t < %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify -emit-llvm -o - < %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=45 -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm -o - < %s | FileCheck %s --check-prefix=TERM_DEBUG
5 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm -fexceptions -fcxx-exceptions -o - < %s -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
6 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t < %s -DOMP5
7 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify -emit-llvm -o - -DOMP5 < %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
8 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm -o - < %s -DOMP5 | FileCheck %s --check-prefix=TERM_DEBUG
9 
10 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm -fexceptions -fcxx-exceptions -o - < %s | FileCheck --check-prefix SIMD-ONLY0 %s
11 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t < %s
12 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify -emit-llvm -o - < %s | FileCheck --check-prefix SIMD-ONLY0 %s
13 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fopenmp-version=45 -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm -o - < %s | FileCheck --check-prefix SIMD-ONLY0 %s
14 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm -fexceptions -fcxx-exceptions -o - < %s -DOMP5 | FileCheck --check-prefix SIMD-ONLY0 %s
15 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t < %s -DOMP5
16 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify -DOMP5 -emit-llvm -o - < %s | FileCheck --check-prefix SIMD-ONLY0 %s
17 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm -o - < %s -DOMP5 | FileCheck --check-prefix SIMD-ONLY0 %s
18 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
19 // expected-no-diagnostics
20 #ifndef HEADER
21 #define HEADER
22 
get_val()23 long long get_val() { extern void mayThrow(); mayThrow(); return 0; }
24 double *g_ptr;
25 
26 // CHECK-LABEL: define {{.*void}} @{{.*}}simple{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
simple(float * a,float * b,float * c,float * d)27 void simple(float *a, float *b, float *c, float *d) {
28 #ifdef OMP5
29   #pragma omp for simd if (true)
30 #else
31   #pragma omp for simd
32 #endif
33 // CHECK: call void @__kmpc_for_static_init_4(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i32* [[LB:%[^,]+]], i32* [[UB:%[^,]+]], i32* [[STRIDE:%[^,]+]], i32 1, i32 1)
34 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
35 // CHECK: [[CMP:%.+]] = icmp sgt i32 [[UB_VAL]], 5
36 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
37 // CHECK: [[TRUE]]:
38 // CHECK: br label %[[SWITCH:[^,]+]]
39 // CHECK: [[FALSE]]:
40 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
41 // CHECK: br label %[[SWITCH]]
42 // CHECK: [[SWITCH]]:
43 // CHECK: [[UP:%.+]] = phi i32 [ 5, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
44 // CHECK: store i32 [[UP]], i32* [[UB]],
45 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
46 // CHECK: store i32 [[LB_VAL]], i32* [[OMP_IV:%[^,]+]],
47 
48 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]
49 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]]
50 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB_VAL]]
51 // CHECK-NEXT: br i1 [[CMP]], label %[[SIMPLE_LOOP1_BODY:.+]], label %[[SIMPLE_LOOP1_END:[^,]+]]
52   for (int i = 3; i < 32; i += 5) {
53 // CHECK: [[SIMPLE_LOOP1_BODY]]:
54 // Start of body: calculate i from IV:
55 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}
56 // CHECK: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 5
57 // CHECK-NEXT: [[CALC_I_2:%.+]] = add nsw i32 3, [[CALC_I_1]]
58 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
59 // ... loop body ...
60 // End of body: store into a[i]:
61 // CHECK: store float [[RESULT:%.+]], float*
62     a[i] = b[i] * c[i] * d[i];
63 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]
64 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
65 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
66 // br label %{{.+}}, !llvm.loop !{{.+}}
67   }
68 // CHECK: [[SIMPLE_LOOP1_END]]:
69 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
70 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
71 
72   long long k = get_val();
73 
74   #pragma omp for simd linear(k : 3) schedule(simd, nonmonotonic: dynamic)
75 // CHECK: [[K0:%.+]] = call {{.*}}i64 @{{.*}}get_val
76 // CHECK-NEXT: store i64 [[K0]], i64* [[K_VAR:%[^,]+]]
77 // CHECK: [[K0LOAD:%.+]] = load i64, i64* [[K_VAR]]
78 // CHECK-NEXT: store i64 [[K0LOAD]], i64* [[LIN0:%[^,]+]]
79 
80 // CHECK: call void @__kmpc_dispatch_init_4(%struct.ident_t* {{.+}}, i32 %{{.+}}, i32 1073741859, i32 0, i32 8, i32 1, i32 1)
81 // CHECK: [[NEXT:%.+]] = call i32 @__kmpc_dispatch_next_4(%struct.ident_t* {{.+}}, i32 %{{.+}}, i32* %{{.+}}, i32* [[LB:%.+]], i32* [[UB:%.+]], i32* %{{.+}})
82 // CHECK: [[COND:%.+]] = icmp ne i32 [[NEXT]], 0
83 // CHECK: br i1 [[COND]], label %[[CONT:.+]], label %[[END:.+]]
84 // CHECK: [[CONT]]:
85 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
86 // CHECK: store i32 [[LB_VAL]], i32* [[OMP_IV2:%[^,]+]],
87 
88 // CHECK: [[IV2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
89 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]]{{.*}}!llvm.access.group
90 // CHECK-NEXT: [[CMP2:%.+]] = icmp sle i32 [[IV2]], [[UB_VAL]]
91 // CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP2_BODY:.+]], label %[[SIMPLE_LOOP2_END:[^,]+]]
92   for (int i = 10; i > 1; i--) {
93 // CHECK: [[SIMPLE_LOOP2_BODY]]:
94 // Start of body: calculate i from IV:
95 // CHECK: [[IV2_0:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
96 // FIXME: It is interesting, why the following "mul 1" was not constant folded?
97 // CHECK-NEXT: [[IV2_1:%.+]] = mul nsw i32 [[IV2_0]], 1
98 // CHECK-NEXT: [[LC_I_1:%.+]] = sub nsw i32 10, [[IV2_1]]
99 // CHECK-NEXT: store i32 [[LC_I_1]], i32* {{.+}}, !llvm.access.group
100 //
101 // CHECK-NEXT: [[LIN0_1:%.+]] = load i64, i64* [[LIN0]]{{.*}}!llvm.access.group
102 // CHECK-NEXT: [[IV2_2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
103 // CHECK-NEXT: [[LIN_MUL1:%.+]] = mul nsw i32 [[IV2_2]], 3
104 // CHECK-NEXT: [[LIN_EXT1:%.+]] = sext i32 [[LIN_MUL1]] to i64
105 // CHECK-NEXT: [[LIN_ADD1:%.+]] = add nsw i64 [[LIN0_1]], [[LIN_EXT1]]
106 // Update of the privatized version of linear variable!
107 // CHECK-NEXT: store i64 [[LIN_ADD1]], i64* [[K_PRIVATIZED:%[^,]+]]
108     a[k]++;
109     k = k + 3;
110 // CHECK: [[IV2_2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
111 // CHECK-NEXT: [[ADD2_2:%.+]] = add nsw i32 [[IV2_2]], 1
112 // CHECK-NEXT: store i32 [[ADD2_2]], i32* [[OMP_IV2]]{{.*}}!llvm.access.group
113 // br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP2_ID]]
114   }
115 // CHECK: [[SIMPLE_LOOP2_END]]:
116 //
117 // Update linear vars after loop, as the loop was operating on a private version.
118 // CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
119 // CHECK-NEXT: [[LIN_ADD2:%.+]] = add nsw i64 [[LIN0_2]], 27
120 // CHECK-NEXT: store i64 [[LIN_ADD2]], i64* [[K_VAR]]
121 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
122 
123   int lin = 12;
124   #pragma omp for simd linear(lin : get_val()), linear(g_ptr)
125 
126 // Init linear private var.
127 // CHECK: store i32 12, i32* [[LIN_VAR:%[^,]+]]
128 // CHECK: [[LIN_LOAD:%.+]] = load i32, i32* [[LIN_VAR]]
129 // CHECK-NEXT: store i32 [[LIN_LOAD]], i32* [[LIN_START:%[^,]+]]
130 // Remember linear step.
131 // CHECK: [[CALL_VAL:%.+]] = invoke
132 // CHECK: store i64 [[CALL_VAL]], i64* [[LIN_STEP:%[^,]+]]
133 
134 // CHECK: [[GLIN_LOAD:%.+]] = load double*, double** [[GLIN_VAR:@[^,]+]]
135 // CHECK-NEXT: store double* [[GLIN_LOAD]], double** [[GLIN_START:%[^,]+]]
136 
137 // CHECK: call void @__kmpc_for_static_init_8u(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i64* [[LB:%[^,]+]], i64* [[UB:%[^,]+]], i64* [[STRIDE:%[^,]+]], i64 1, i64 1)
138 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
139 // CHECK: [[CMP:%.+]] = icmp ugt i64 [[UB_VAL]], 3
140 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
141 // CHECK: [[TRUE]]:
142 // CHECK: br label %[[SWITCH:[^,]+]]
143 // CHECK: [[FALSE]]:
144 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
145 // CHECK: br label %[[SWITCH]]
146 // CHECK: [[SWITCH]]:
147 // CHECK: [[UP:%.+]] = phi i64 [ 3, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
148 // CHECK: store i64 [[UP]], i64* [[UB]],
149 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
150 // CHECK: store i64 [[LB_VAL]], i64* [[OMP_IV3:%[^,]+]],
151 
152 // CHECK: [[IV3:%.+]] = load i64, i64* [[OMP_IV3]]
153 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]]
154 // CHECK-NEXT: [[CMP3:%.+]] = icmp ule i64 [[IV3]], [[UB_VAL]]
155 // CHECK-NEXT: br i1 [[CMP3]], label %[[SIMPLE_LOOP3_BODY:.+]], label %[[SIMPLE_LOOP3_END:[^,]+]]
156   for (unsigned long long it = 2000; it >= 600; it-=400) {
157 // CHECK: [[SIMPLE_LOOP3_BODY]]:
158 // Start of body: calculate it from IV:
159 // CHECK: [[IV3_0:%.+]] = load i64, i64* [[OMP_IV3]]
160 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul i64 [[IV3_0]], 400
161 // CHECK-NEXT: [[LC_IT_2:%.+]] = sub i64 2000, [[LC_IT_1]]
162 // CHECK-NEXT: store i64 [[LC_IT_2]], i64*
163 //
164 // Linear start and step are used to calculate current value of the linear variable.
165 // CHECK: [[LINSTART:.+]] = load i32, i32* [[LIN_START]]
166 // CHECK: [[LINSTEP:.+]] = load i64, i64* [[LIN_STEP]]
167 // CHECK-NOT: store i32 {{.+}}, i32* [[LIN_VAR]],
168 // CHECK: [[GLINSTART:.+]] = load double*, double** [[GLIN_START]]
169 // CHECK-NEXT: [[IV3_1:%.+]] = load i64, i64* [[OMP_IV3]]
170 // CHECK-NEXT: [[MUL:%.+]] = mul i64 [[IV3_1]], 1
171 // CHECK: [[GEP:%.+]] = getelementptr{{.*}}[[GLINSTART]]
172 // CHECK-NEXT: store double* [[GEP]], double** [[G_PTR_CUR:%[^,]+]]
173     *g_ptr++ = 0.0;
174 // CHECK: [[GEP_VAL:%.+]] = load double{{.*}}[[G_PTR_CUR]]
175 // CHECK: store double{{.*}}[[GEP_VAL]]
176     a[it + lin]++;
177 // CHECK: [[FLT_INC:%.+]] = fadd float
178 // CHECK-NEXT: store float [[FLT_INC]],
179 // CHECK: [[IV3_2:%.+]] = load i64, i64* [[OMP_IV3]]
180 // CHECK-NEXT: [[ADD3_2:%.+]] = add i64 [[IV3_2]], 1
181 // CHECK-NEXT: store i64 [[ADD3_2]], i64* [[OMP_IV3]]
182   }
183 // CHECK: [[SIMPLE_LOOP3_END]]:
184 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
185 //
186 // Linear start and step are used to calculate final value of the linear variables.
187 // CHECK: [[LINSTART:.+]] = load i32, i32* [[LIN_START]]
188 // CHECK: [[LINSTEP:.+]] = load i64, i64* [[LIN_STEP]]
189 // CHECK: store i32 {{.+}}, i32* [[LIN_VAR]],
190 // CHECK: [[GLINSTART:.+]] = load double*, double** [[GLIN_START]]
191 // CHECK: store double* {{.*}}[[GLIN_VAR]]
192 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
193 
194   #pragma omp for simd
195 // CHECK: call void @__kmpc_for_static_init_4(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i32* [[LB:%[^,]+]], i32* [[UB:%[^,]+]], i32* [[STRIDE:%[^,]+]], i32 1, i32 1)
196 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
197 // CHECK: [[CMP:%.+]] = icmp sgt i32 [[UB_VAL]], 3
198 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
199 // CHECK: [[TRUE]]:
200 // CHECK: br label %[[SWITCH:[^,]+]]
201 // CHECK: [[FALSE]]:
202 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
203 // CHECK: br label %[[SWITCH]]
204 // CHECK: [[SWITCH]]:
205 // CHECK: [[UP:%.+]] = phi i32 [ 3, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
206 // CHECK: store i32 [[UP]], i32* [[UB]],
207 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
208 // CHECK: store i32 [[LB_VAL]], i32* [[OMP_IV4:%[^,]+]],
209 
210 // CHECK: [[IV4:%.+]] = load i32, i32* [[OMP_IV4]]
211 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]]
212 // CHECK-NEXT: [[CMP4:%.+]] = icmp sle i32 [[IV4]], [[UB_VAL]]
213 // CHECK-NEXT: br i1 [[CMP4]], label %[[SIMPLE_LOOP4_BODY:.+]], label %[[SIMPLE_LOOP4_END:[^,]+]]
214   for (short it = 6; it <= 20; it-=-4) {
215 // CHECK: [[SIMPLE_LOOP4_BODY]]:
216 // Start of body: calculate it from IV:
217 // CHECK: [[IV4_0:%.+]] = load i32, i32* [[OMP_IV4]]
218 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i32 [[IV4_0]], 4
219 // CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i32 6, [[LC_IT_1]]
220 // CHECK-NEXT: [[LC_IT_3:%.+]] = trunc i32 [[LC_IT_2]] to i16
221 // CHECK-NEXT: store i16 [[LC_IT_3]], i16*
222 
223 // CHECK: [[IV4_2:%.+]] = load i32, i32* [[OMP_IV4]]
224 // CHECK-NEXT: [[ADD4_2:%.+]] = add nsw i32 [[IV4_2]], 1
225 // CHECK-NEXT: store i32 [[ADD4_2]], i32* [[OMP_IV4]]
226   }
227 // CHECK: [[SIMPLE_LOOP4_END]]:
228 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
229 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
230 
231   #pragma omp for simd
232 // CHECK: call void @__kmpc_for_static_init_4(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i32* [[LB:%[^,]+]], i32* [[UB:%[^,]+]], i32* [[STRIDE:%[^,]+]], i32 1, i32 1)
233 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
234 // CHECK: [[CMP:%.+]] = icmp sgt i32 [[UB_VAL]], 25
235 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
236 // CHECK: [[TRUE]]:
237 // CHECK: br label %[[SWITCH:[^,]+]]
238 // CHECK: [[FALSE]]:
239 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
240 // CHECK: br label %[[SWITCH]]
241 // CHECK: [[SWITCH]]:
242 // CHECK: [[UP:%.+]] = phi i32 [ 25, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
243 // CHECK: store i32 [[UP]], i32* [[UB]],
244 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
245 // CHECK: store i32 [[LB_VAL]], i32* [[OMP_IV5:%[^,]+]],
246 
247 // CHECK: [[IV5:%.+]] = load i32, i32* [[OMP_IV5]]
248 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]]
249 // CHECK-NEXT: [[CMP5:%.+]] = icmp sle i32 [[IV5]], [[UB_VAL]]
250 // CHECK-NEXT: br i1 [[CMP5]], label %[[SIMPLE_LOOP5_BODY:.+]], label %[[SIMPLE_LOOP5_END:[^,]+]]
251   for (unsigned char it = 'z'; it >= 'a'; it+=-1) {
252 // CHECK: [[SIMPLE_LOOP5_BODY]]:
253 // Start of body: calculate it from IV:
254 // CHECK: [[IV5_0:%.+]] = load i32, i32* [[OMP_IV5]]
255 // CHECK-NEXT: [[IV5_1:%.+]] = mul nsw i32 [[IV5_0]], 1
256 // CHECK-NEXT: [[LC_IT_1:%.+]] = sub nsw i32 122, [[IV5_1]]
257 // CHECK-NEXT: [[LC_IT_2:%.+]] = trunc i32 [[LC_IT_1]] to i8
258 // CHECK-NEXT: store i8 [[LC_IT_2]], i8*
259 
260 // CHECK: [[IV5_2:%.+]] = load i32, i32* [[OMP_IV5]]
261 // CHECK-NEXT: [[ADD5_2:%.+]] = add nsw i32 [[IV5_2]], 1
262 // CHECK-NEXT: store i32 [[ADD5_2]], i32* [[OMP_IV5]]
263   }
264 // CHECK: [[SIMPLE_LOOP5_END]]:
265 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
266 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
267 
268 // CHECK-NOT: mul i32 %{{.+}}, 10
269   #pragma omp for simd
270   for (unsigned i=100; i<10; i+=10) {
271   }
272 
273   int A;
274   #pragma omp parallel
275   {
276   // CHECK: store i32 -1, i32* [[A:%.+]],
277   A = -1;
278   #pragma omp for simd lastprivate(A)
279 // CHECK: call void @__kmpc_for_static_init_8(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i64* [[LB:%[^,]+]], i64* [[UB:%[^,]+]], i64* [[STRIDE:%[^,]+]], i64 1, i64 1)
280 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
281 // CHECK: [[CMP:%.+]] = icmp sgt i64 [[UB_VAL]], 6
282 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
283 // CHECK: [[TRUE]]:
284 // CHECK: br label %[[SWITCH:[^,]+]]
285 // CHECK: [[FALSE]]:
286 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
287 // CHECK: br label %[[SWITCH]]
288 // CHECK: [[SWITCH]]:
289 // CHECK: [[UP:%.+]] = phi i64 [ 6, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
290 // CHECK: store i64 [[UP]], i64* [[UB]],
291 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
292 // CHECK: store i64 [[LB_VAL]], i64* [[OMP_IV7:%[^,]+]],
293 
294 // CHECK: br label %[[SIMD_LOOP7_COND:[^,]+]]
295 // CHECK: [[SIMD_LOOP7_COND]]:
296 // CHECK-NEXT: [[IV7:%.+]] = load i64, i64* [[OMP_IV7]]
297 // CHECK-NEXT: [[UB_VAL:%.+]] = load i64, i64* [[UB]]
298 // CHECK-NEXT: [[CMP7:%.+]] = icmp sle i64 [[IV7]], [[UB_VAL]]
299 // CHECK-NEXT: br i1 [[CMP7]], label %[[SIMPLE_LOOP7_BODY:.+]], label %[[SIMPLE_LOOP7_END:[^,]+]]
300   for (long long i = -10; i < 10; i += 3) {
301 // CHECK: [[SIMPLE_LOOP7_BODY]]:
302 // Start of body: calculate i from IV:
303 // CHECK: [[IV7_0:%.+]] = load i64, i64* [[OMP_IV7]]
304 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i64 [[IV7_0]], 3
305 // CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i64 -10, [[LC_IT_1]]
306 // CHECK-NEXT: store i64 [[LC_IT_2]], i64* [[LC:%[^,]+]],
307 // CHECK-NEXT: [[LC_VAL:%.+]] = load i64, i64* [[LC]]
308 // CHECK-NEXT: [[CONV:%.+]] = trunc i64 [[LC_VAL]] to i32
309 // CHECK-NEXT: store i32 [[CONV]], i32* [[A_PRIV:%[^,]+]],
310     A = i;
311 // CHECK: [[IV7_2:%.+]] = load i64, i64* [[OMP_IV7]]
312 // CHECK-NEXT: [[ADD7_2:%.+]] = add nsw i64 [[IV7_2]], 1
313 // CHECK-NEXT: store i64 [[ADD7_2]], i64* [[OMP_IV7]]
314   }
315 // CHECK: [[SIMPLE_LOOP7_END]]:
316 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
317 // CHECK: load i32, i32*
318 // CHECK: icmp ne i32 %{{.+}}, 0
319 // CHECK: br i1 %{{.+}}, label
320 // CHECK: [[A_PRIV_VAL:%.+]] = load i32, i32* [[A_PRIV]],
321 // CHECK-NEXT: store i32 [[A_PRIV_VAL]], i32* %{{.+}},
322 // CHECK-NEXT: br label
323 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
324   }
325   int R;
326   #pragma omp parallel
327   {
328   // CHECK: store i32 -1, i32* [[R:%[^,]+]],
329   R = -1;
330 // CHECK: store i32 1, i32* [[R_PRIV:%[^,]+]],
331 // OMP50: [[A_VAL:%.+]] = load i32, i32* %
332 // OMP50: [[COND:%.+]] = icmp ne i32 [[A_VAL]], 0
333 // OMP50: br i1 [[COND]], label {{%?}}[[THEN:[^,]+]], label {{%?}}[[ELSE:[^,]+]]
334 // OMP50: [[THEN]]:
335 #ifdef OMP5
336   #pragma omp for simd reduction(*:R) if (simd:A) nontemporal(R)
337 #else
338   #pragma omp for simd reduction(*:R)
339 #endif
340 // CHECK: call void @__kmpc_for_static_init_8(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i64* [[LB:%[^,]+]], i64* [[UB:%[^,]+]], i64* [[STRIDE:%[^,]+]], i64 1, i64 1)
341 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
342 // CHECK: [[CMP:%.+]] = icmp sgt i64 [[UB_VAL]], 6
343 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
344 // CHECK: [[TRUE]]:
345 // CHECK: br label %[[SWITCH:[^,]+]]
346 // CHECK: [[FALSE]]:
347 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
348 // CHECK: br label %[[SWITCH]]
349 // CHECK: [[SWITCH]]:
350 // CHECK: [[UP:%.+]] = phi i64 [ 6, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
351 // CHECK: store i64 [[UP]], i64* [[UB]],
352 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
353 // CHECK: store i64 [[LB_VAL]], i64* [[OMP_IV8:%[^,]+]],
354 
355 // CHECK: br label %[[SIMD_LOOP8_COND:[^,]+]]
356 // CHECK: [[SIMD_LOOP8_COND]]:
357 // CHECK-NEXT: [[IV8:%.+]] = load i64, i64* [[OMP_IV8]]
358 // CHECK-NEXT: [[UB_VAL:%.+]] = load i64, i64* [[UB]]
359 // CHECK-NEXT: [[CMP8:%.+]] = icmp sle i64 [[IV8]], [[UB_VAL]]
360 // CHECK-NEXT: br i1 [[CMP8]], label %[[SIMPLE_LOOP8_BODY:.+]], label %[[SIMPLE_LOOP8_END:[^,]+]]
361   for (long long i = -10; i < 10; i += 3) {
362 // CHECK: [[SIMPLE_LOOP8_BODY]]:
363 // Start of body: calculate i from IV:
364 // CHECK: [[IV8_0:%.+]] = load i64, i64* [[OMP_IV8]]
365 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i64 [[IV8_0]], 3
366 // CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i64 -10, [[LC_IT_1]]
367 // CHECK-NEXT: store i64 [[LC_IT_2]], i64* [[LC:%[^,]+]],
368 // CHECK-NEXT: [[LC_VAL:%.+]] = load i64, i64* [[LC]]
369 // OMP45: store i32 %{{.+}}, i32* [[R_PRIV]],
370 // OMP50: store i32 %{{.+}}, i32* [[R_PRIV]],{{.*}}!nontemporal
371     R *= i;
372 // CHECK: [[IV8_2:%.+]] = load i64, i64* [[OMP_IV8]]
373 // CHECK-NEXT: [[ADD8_2:%.+]] = add nsw i64 [[IV8_2]], 1
374 // CHECK-NEXT: store i64 [[ADD8_2]], i64* [[OMP_IV8]]
375 // CHECK-NEXT: br label {{%?}}[[SIMD_LOOP8_COND]], {{.*}}!llvm.loop ![[SIMD_LOOP:.+]]
376   }
377 // CHECK: [[SIMPLE_LOOP8_END]]:
378 // OMP50:  br label {{%?}}[[IF_EXIT:[^,]+]]
379 // OMP50:  [[ELSE]]:
380 // OMP50: call void @__kmpc_for_static_init_8(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i64* [[LB:%[^,]+]], i64* [[UB:%[^,]+]], i64* [[STRIDE:%[^,]+]], i64 1, i64 1)
381 // OMP50: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
382 // OMP50: [[CMP:%.+]] = icmp sgt i64 [[UB_VAL]], 6
383 // OMP50: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
384 // OMP50: [[TRUE]]:
385 // OMP50: br label %[[SWITCH:[^,]+]]
386 // OMP50: [[FALSE]]:
387 // OMP50: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
388 // OMP50: br label %[[SWITCH]]
389 // OMP50: [[SWITCH]]:
390 // OMP50: [[UP:%.+]] = phi i64 [ 6, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
391 // OMP50: store i64 [[UP]], i64* [[UB]],
392 // OMP50: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
393 // OMP50: store i64 [[LB_VAL]], i64* [[OMP_IV8:%[^,]+]],
394 
395 // OMP50: br label %[[SIMD_LOOP8_COND:[^,]+]]
396 // OMP50: [[SIMD_LOOP8_COND]]:
397 // OMP50-NEXT: [[IV8:%.+]] = load i64, i64* [[OMP_IV8]]
398 // OMP50-NEXT: [[UB_VAL:%.+]] = load i64, i64* [[UB]]
399 // OMP50-NEXT: [[CMP8:%.+]] = icmp sle i64 [[IV8]], [[UB_VAL]]
400 // OMP50-NEXT: br i1 [[CMP8]], label %[[SIMPLE_LOOP8_BODY:.+]], label %[[SIMPLE_LOOP8_END:[^,]+]]
401 // OMP50: [[SIMPLE_LOOP8_BODY]]:
402 // Start of body: calculate i from IV:
403 // OMP50: [[IV8_0:%.+]] = load i64, i64* [[OMP_IV8]]
404 // OMP50-NEXT: [[LC_IT_1:%.+]] = mul nsw i64 [[IV8_0]], 3
405 // OMP50-NEXT: [[LC_IT_2:%.+]] = add nsw i64 -10, [[LC_IT_1]]
406 // OMP50-NEXT: store i64 [[LC_IT_2]], i64* [[LC:%[^,]+]],
407 // OMP50-NEXT: [[LC_VAL:%.+]] = load i64, i64* [[LC]]
408 // OMP50: store i32 %{{.+}}, i32* [[R_PRIV]],
409 // OMP50: [[IV8_2:%.+]] = load i64, i64* [[OMP_IV8]]
410 // OMP50-NEXT: [[ADD8_2:%.+]] = add nsw i64 [[IV8_2]], 1
411 // OMP50-NEXT: store i64 [[ADD8_2]], i64* [[OMP_IV8]]
412 // OMP50-NEXT: br label {{%?}}[[SIMD_LOOP8_COND]], {{.*}}!llvm.loop ![[NOSIMD_LOOP:.+]]
413 // OMP50: [[SIMPLE_LOOP8_END]]:
414 // OMP50:  br label {{%?}}[[IF_EXIT]]
415 // OMP50:  [[IF_EXIT]]:
416 
417 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
418 // CHECK: call i32 @__kmpc_reduce(
419 // CHECK: [[R_PRIV_VAL:%.+]] = load i32, i32* [[R_PRIV]],
420 // CHECK: [[RED:%.+]] = mul nsw i32 %{{.+}}, [[R_PRIV_VAL]]
421 // CHECK-NEXT: store i32 [[RED]], i32* %{{.+}},
422 // CHECK-NEXT: call void @__kmpc_end_reduce(
423 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
424   }
425 }
426 
tfoo(T a)427 template <class T, unsigned K> T tfoo(T a) { return a + K; }
428 
429 template <typename T, unsigned N>
templ1(T a,T * z)430 int templ1(T a, T *z) {
431   #pragma omp for simd collapse(N) schedule(simd: static, N)
432   for (int i = 0; i < N * 2; i++) {
433     for (long long j = 0; j < (N + N + N + N); j += 2) {
434       z[i + j] = a + tfoo<T, N>(i + j);
435     }
436   }
437   return 0;
438 }
439 
440 // Instatiation templ1<float,2>
441 // CHECK-LABEL: define {{.*i32}} @{{.*}}templ1{{.*}}(float {{.+}}, float* {{.+}})
442 // CHECK: call void @__kmpc_for_static_init_8(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 45, i32* %{{[^,]+}}, i64* [[LB:%[^,]+]], i64* [[UB:%[^,]+]], i64* [[STRIDE:%[^,]+]], i64 1, i64 2)
443 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
444 // CHECK: [[CMP:%.+]] = icmp sgt i64 [[UB_VAL]], 15
445 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
446 // CHECK: [[TRUE]]:
447 // CHECK: br label %[[SWITCH:[^,]+]]
448 // CHECK: [[FALSE]]:
449 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
450 // CHECK: br label %[[SWITCH]]
451 // CHECK: [[SWITCH]]:
452 // CHECK: [[UP:%.+]] = phi i64 [ 15, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
453 // CHECK: store i64 [[UP]], i64* [[UB]],
454 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
455 // CHECK: store i64 [[LB_VAL]], i64* [[T1_OMP_IV:%[^,]+]],
456 
457 // ...
458 // CHECK: icmp sle i64
459 // CHECK: [[IV:%.+]] = load i64, i64* [[T1_OMP_IV]]
460 // CHECK-NEXT: [[UB_VAL:%.+]] = load i64, i64* [[UB]]
461 // CHECK-NEXT: [[CMP1:%.+]] = icmp sle i64 [[IV]], [[UB_VAL]]
462 // CHECK-NEXT: br i1 [[CMP1]], label %[[T1_BODY:.+]], label %[[T1_END:[^,]+]]
463 // CHECK: [[T1_BODY]]:
464 // Loop counters i and j updates:
465 // CHECK: [[IV1:%.+]] = load i64, i64* [[T1_OMP_IV]]
466 // CHECK-NEXT: [[I_1:%.+]] = sdiv i64 [[IV1]], 4
467 // CHECK-NEXT: [[I_1_MUL1:%.+]] = mul nsw i64 [[I_1]], 1
468 // CHECK-NEXT: [[I_1_ADD0:%.+]] = add nsw i64 0, [[I_1_MUL1]]
469 // CHECK-NEXT: [[I_2:%.+]] = trunc i64 [[I_1_ADD0]] to i32
470 // CHECK-NEXT: store i32 [[I_2]], i32*
471 // CHECK: [[IV2:%.+]] = load i64, i64* [[T1_OMP_IV]]
472 // CHECK-NEXT: [[IV2_1:%.+]] = load i64, i64* [[T1_OMP_IV]]
473 // CHECK-NEXT: [[DIV_2:%.+]] = sdiv i64 [[IV2_1]], 4
474 // CHECK-NEXT: [[MUL_2:%.+]] = mul nsw i64 [[DIV_2]], 4
475 // CHECK-NEXT: [[J_1:%.+]] = sub nsw i64 [[IV2]], [[MUL_2]]
476 // CHECK-NEXT: [[J_2:%.+]] = mul nsw i64 [[J_1]], 2
477 // CHECK-NEXT: [[J_2_ADD0:%.+]] = add nsw i64 0, [[J_2]]
478 // CHECK-NEXT: store i64 [[J_2_ADD0]], i64*
479 // simd.for.inc:
480 // CHECK: [[IV3:%.+]] = load i64, i64* [[T1_OMP_IV]]
481 // CHECK-NEXT: [[INC:%.+]] = add nsw i64 [[IV3]], 1
482 // CHECK-NEXT: store i64 [[INC]], i64* [[T1_OMP_IV]]
483 // CHECK-NEXT: br label {{%.+}}
484 // CHECK: [[T1_END]]:
485 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
486 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
487 // CHECK: ret i32 0
488 //
inst_templ1()489 void inst_templ1() {
490   float a;
491   float z[100];
492   templ1<float,2> (a, z);
493 }
494 
495 
496 typedef int MyIdx;
497 
498 class IterDouble {
499   double *Ptr;
500 public:
operator ++() const501   IterDouble operator++ () const {
502     IterDouble n;
503     n.Ptr = Ptr + 1;
504     return n;
505   }
operator <(const IterDouble & that) const506   bool operator < (const IterDouble &that) const {
507     return Ptr < that.Ptr;
508   }
operator *() const509   double & operator *() const {
510     return *Ptr;
511   }
operator -(const IterDouble & that) const512   MyIdx operator - (const IterDouble &that) const {
513     return (MyIdx) (Ptr - that.Ptr);
514   }
operator +(int Delta)515   IterDouble operator + (int Delta) {
516     IterDouble re;
517     re.Ptr = Ptr + Delta;
518     return re;
519   }
520 
521   ///~IterDouble() {}
522 };
523 
524 // CHECK-LABEL: define {{.*void}} @{{.*}}iter_simple{{.*}}
iter_simple(IterDouble ia,IterDouble ib,IterDouble ic)525 void iter_simple(IterDouble ia, IterDouble ib, IterDouble ic) {
526 //
527 // Calculate number of iterations before the loop body.
528 // CHECK: [[DIFF1:%.+]] = invoke {{.*}}i32 @{{.*}}IterDouble{{.*}}
529 // CHECK: [[DIFF2:%.+]] = sub nsw i32 [[DIFF1]], 1
530 // CHECK-NEXT: [[DIFF3:%.+]] = add nsw i32 [[DIFF2]], 1
531 // CHECK-NEXT: [[DIFF4:%.+]] = sdiv i32 [[DIFF3]], 1
532 // CHECK-NEXT: [[DIFF5:%.+]] = sub nsw i32 [[DIFF4]], 1
533 // CHECK-NEXT: store i32 [[DIFF5]], i32* [[OMP_LAST_IT:%[^,]+]]{{.+}}
534   #pragma omp for simd
535 
536 // CHECK: call void @__kmpc_for_static_init_4(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i32* [[LB:%[^,]+]], i32* [[UB:%[^,]+]], i32* [[STRIDE:%[^,]+]], i32 1, i32 1)
537 // CHECK-DAG: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
538 // CHECK-DAG: [[OMP_LAST_IT_VAL:%.+]] = load i32, i32* [[OMP_LAST_IT]],
539 // CHECK: [[CMP:%.+]] = icmp sgt i32 [[UB_VAL]], [[OMP_LAST_IT_VAL]]
540 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
541 // CHECK: [[TRUE]]:
542 // CHECK: [[OMP_LAST_IT_VAL:%.+]] = load i32, i32* [[OMP_LAST_IT]],
543 // CHECK: br label %[[SWITCH:[^,]+]]
544 // CHECK: [[FALSE]]:
545 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
546 // CHECK: br label %[[SWITCH]]
547 // CHECK: [[SWITCH]]:
548 // CHECK: [[UP:%.+]] = phi i32 [ [[OMP_LAST_IT_VAL]], %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
549 // CHECK: store i32 [[UP]], i32* [[UB]],
550 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
551 // CHECK: store i32 [[LB_VAL]], i32* [[IT_OMP_IV:%[^,]+]],
552 
553 // CHECK: [[IV:%.+]] = load i32, i32* [[IT_OMP_IV]]
554 // CHECK-NEXT: [[UB_VAL:%.+]] = load i32, i32* [[UB]]
555 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB_VAL]]
556 // CHECK-NEXT: br i1 [[CMP]], label %[[IT_BODY:[^,]+]], label %[[IT_END:[^,]+]]
557   for (IterDouble i = ia; i < ib; ++i) {
558 // CHECK: [[IT_BODY]]:
559 // Start of body: calculate i from index:
560 // CHECK: [[IV1:%.+]] = load i32, i32* [[IT_OMP_IV]]
561 // Call of operator+ (i, IV).
562 // CHECK: {{%.+}} = invoke {{.+}} @{{.*}}IterDouble{{.*}}
563 // ... loop body ...
564    *i = *ic * 0.5;
565 // Float multiply and save result.
566 // CHECK: [[MULR:%.+]] = fmul double {{%.+}}, 5.000000e-01
567 // CHECK-NEXT: invoke {{.+}} @{{.*}}IterDouble{{.*}}
568 // CHECK: store double [[MULR:%.+]], double* [[RESULT_ADDR:%.+]]
569    ++ic;
570 //
571 // CHECK: [[IV2:%.+]] = load i32, i32* [[IT_OMP_IV]]
572 // CHECK-NEXT: [[ADD2:%.+]] = add nsw i32 [[IV2]], 1
573 // CHECK-NEXT: store i32 [[ADD2]], i32* [[IT_OMP_IV]]
574 // br label %{{.*}}, !llvm.loop ![[ITER_LOOP_ID]]
575   }
576 // CHECK: [[IT_END]]:
577 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
578 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
579 // CHECK: ret void
580 }
581 
582 
583 // CHECK-LABEL: define {{.*void}} @{{.*}}collapsed{{.*}}
collapsed(float * a,float * b,float * c,float * d)584 void collapsed(float *a, float *b, float *c, float *d) {
585   int i; // outer loop counter
586   unsigned j; // middle loop couter, leads to unsigned icmp in loop header.
587   // k declared in the loop init below
588   short l; // inner loop counter
589 // CHECK: call void @__kmpc_for_static_init_4u(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i32* [[LB:%[^,]+]], i32* [[UB:%[^,]+]], i32* [[STRIDE:%[^,]+]], i32 1, i32 1)
590 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
591 // CHECK: [[CMP:%.+]] = icmp ugt i32 [[UB_VAL]], 119
592 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
593 // CHECK: [[TRUE]]:
594 // CHECK: br label %[[SWITCH:[^,]+]]
595 // CHECK: [[FALSE]]:
596 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
597 // CHECK: br label %[[SWITCH]]
598 // CHECK: [[SWITCH]]:
599 // CHECK: [[UP:%.+]] = phi i32 [ 119, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
600 // CHECK: store i32 [[UP]], i32* [[UB]],
601 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
602 // CHECK: store i32 [[LB_VAL]], i32* [[OMP_IV:%[^,]+]],
603 //
604   #pragma omp for simd collapse(4)
605 
606 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]
607 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]]
608 // CHECK-NEXT: [[CMP:%.+]] = icmp ule i32 [[IV]], [[UB_VAL]]
609 // CHECK-NEXT: br i1 [[CMP]], label %[[COLL1_BODY:[^,]+]], label %[[COLL1_END:[^,]+]]
610   for (i = 1; i < 3; i++) // 2 iterations
611     for (j = 2u; j < 5u; j++) //3 iterations
612       for (int k = 3; k <= 6; k++) // 4 iterations
613         for (l = 4; l < 9; ++l) // 5 iterations
614         {
615 // CHECK: [[COLL1_BODY]]:
616 // Start of body: calculate i from index:
617 // CHECK: [[IV1:%.+]] = load i32, i32* [[OMP_IV]]
618 // Calculation of the loop counters values.
619 // CHECK: [[CALC_I_1:%.+]] = udiv i32 [[IV1]], 60
620 // CHECK-NEXT: [[CALC_I_1_MUL1:%.+]] = mul i32 [[CALC_I_1]], 1
621 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i32 1, [[CALC_I_1_MUL1]]
622 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
623 
624 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]
625 // CHECK: [[IV1_2_1:%.+]] = load i32, i32* [[OMP_IV]]
626 // CHECK-NEXT: [[CALC_J_1:%.+]] = udiv i32 [[IV1_2_1]], 60
627 // CHECK-NEXT: [[MUL_1:%.+]] = mul i32 [[CALC_J_1]], 60
628 // CHECK-NEXT: [[SUB_3:%.+]] = sub i32 [[IV1_2]], [[MUL_1]]
629 // CHECK-NEXT: [[CALC_J_2:%.+]] = udiv i32 [[SUB_3]], 20
630 // CHECK-NEXT: [[CALC_J_2_MUL1:%.+]] = mul i32 [[CALC_J_2]], 1
631 // CHECK-NEXT: [[CALC_J_3:%.+]] = add i32 2, [[CALC_J_2_MUL1]]
632 // CHECK-NEXT: store i32 [[CALC_J_3]], i32* [[LC_J:.+]]
633 
634 // CHECK: [[IV1_3:%.+]] = load i32, i32* [[OMP_IV]]
635 // CHECK: [[IV1_3_1:%.+]] = load i32, i32* [[OMP_IV]]
636 // CHECK-NEXT: [[DIV_1:%.+]] = udiv i32 [[IV1_3_1]], 60
637 // CHECK-NEXT: [[MUL_2:%.+]] = mul i32 [[DIV_1]], 60
638 // CHECK-NEXT: [[ADD_3:%.+]] = sub i32 [[IV1_3]], [[MUL_2]]
639 
640 // CHECK: [[IV1_4:%.+]] = load i32, i32* [[OMP_IV]]
641 // CHECK: [[IV1_4_1:%.+]] = load i32, i32* [[OMP_IV]]
642 // CHECK-NEXT: [[DIV_2:%.+]] = udiv i32 [[IV1_4_1]], 60
643 // CHECK-NEXT: [[MUL_3:%.+]] = mul i32 [[DIV_2]], 60
644 // CHECK-NEXT: [[SUB_6:%.+]] = sub i32 [[IV1_4]], [[MUL_3]]
645 // CHECK-NEXT: [[DIV_3:%.+]] = udiv i32 [[SUB_6]], 20
646 // CHECK-NEXT: [[MUL_4:%.+]] = mul i32 [[DIV_3]], 20
647 // CHECK-NEXT: [[SUB_7:%.+]] = sub i32 [[ADD_3]], [[MUL_4]]
648 // CHECK-NEXT: [[DIV_4:%.+]] = udiv i32 [[SUB_7]], 5
649 // CHECK-NEXT: [[MUL_5:%.+]] = mul i32 [[DIV_4]], 1
650 // CHECK-NEXT: [[ADD_6:%.+]] = add i32 3, [[MUL_5]]
651 // CHECK-NEXT: store i32 [[ADD_6]], i32* [[LC_K:.+]]
652 
653 // CHECK: [[IV1_5:%.+]] = load i32, i32* [[OMP_IV]]
654 // CHECK: [[IV1_5_1:%.+]] = load i32, i32* [[OMP_IV]]
655 // CHECK-NEXT: [[DIV_5:%.+]] = udiv i32 [[IV1_5_1]], 60
656 // CHECK-NEXT: [[MUL_6:%.+]] = mul i32 [[DIV_5]], 60
657 // CHECK-NEXT: [[ADD_7:%.+]] = sub i32 [[IV1_5]], [[MUL_6]]
658 
659 // CHECK: [[IV1_6:%.+]] = load i32, i32* [[OMP_IV]]
660 // CHECK: [[IV1_6_1:%.+]] = load i32, i32* [[OMP_IV]]
661 // CHECK-NEXT: [[DIV_6:%.+]] = udiv i32 [[IV1_6_1]], 60
662 // CHECK-NEXT: [[MUL_7:%.+]] = mul i32 [[DIV_6]], 60
663 // CHECK-NEXT: [[SUB_10:%.+]] = sub i32 [[IV1_6]], [[MUL_7]]
664 // CHECK-NEXT: [[DIV_7:%.+]] = udiv i32 [[SUB_10]], 20
665 // CHECK-NEXT: [[MUL_8:%.+]] = mul i32 [[DIV_7]], 20
666 // CHECK-NEXT: [[ADD_9:%.+]] = sub i32 [[ADD_7]], [[MUL_8]]
667 
668 // CHECK: [[IV1_7:%.+]] = load i32, i32* [[OMP_IV]]
669 // CHECK: [[IV1_7_1:%.+]] = load i32, i32* [[OMP_IV]]
670 // CHECK-NEXT: [[DIV_8:%.+]] = udiv i32 [[IV1_7_1]], 60
671 // CHECK-NEXT: [[MUL_9:%.+]] = mul i32 [[DIV_8]], 60
672 // CHECK-NEXT: [[ADD_10:%.+]] = sub i32 [[IV1_7]], [[MUL_9]]
673 
674 // CHECK: [[IV1_8:%.+]] = load i32, i32* [[OMP_IV]]
675 // CHECK: [[IV1_8_1:%.+]] = load i32, i32* [[OMP_IV]]
676 // CHECK-NEXT: [[DIV_3:%.+]] = udiv i32 [[IV1_8_1]], 60
677 // CHECK-NEXT: [[MUL_4:%.+]] = mul i32 [[DIV_3]], 60
678 // CHECK-NEXT: [[SUB_7:%.+]] = sub i32 [[IV1_8]], [[MUL_4]]
679 // CHECK-NEXT: [[DIV_4:%.+]] = udiv i32 [[SUB_7]], 20
680 // CHECK-NEXT: [[MUL_5:%.+]] = mul i32 [[DIV_4]], 20
681 // CHECK-NEXT: [[SUB_8:%.+]] = sub i32 [[ADD_10]], [[MUL_5]]
682 // CHECK-NEXT: [[DIV_5:%.+]] = udiv i32 [[SUB_8]], 5
683 // CHECK-NEXT: [[MUL_6:%.+]] = mul i32 [[DIV_5]], 5
684 // CHECK-NEXT: [[SUB_9:%.+]] = sub i32 [[ADD_9]], [[MUL_6]]
685 // CHECK-NEXT: [[MUL_6:%.+]] = mul i32 [[SUB_9]], 1
686 // CHECK-NEXT: [[CALC_L_2:%.+]] = add i32 4, [[MUL_6]]
687 // CHECK-NEXT: [[CALC_L_3:%.+]] = trunc i32 [[CALC_L_2]] to i16
688 // CHECK-NEXT: store i16 [[CALC_L_3]], i16* [[LC_L:.+]]
689 // ... loop body ...
690 // End of body: store into a[i]:
691 // CHECK: store float [[RESULT:%.+]], float* [[RESULT_ADDR:%.+]]
692     float res = b[j] * c[k];
693     a[i] = res * d[l];
694 // CHECK: [[IV2:%.+]] = load i32, i32* [[OMP_IV]]
695 // CHECK-NEXT: [[ADD2:%.+]] = add i32 [[IV2]], 1
696 // CHECK-NEXT: store i32 [[ADD2]], i32* [[OMP_IV]]
697 // br label %{{[^,]+}}, !llvm.loop ![[COLL1_LOOP_ID]]
698 // CHECK: [[COLL1_END]]:
699   }
700 // i,j,l are updated; k is not updated.
701 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* {{.+}}, i32 %{{.+}})
702 // CHECK: br i1
703 // CHECK: store i32 3, i32*
704 // CHECK-NEXT: store i32 5,
705 // CHECK-NEXT: store i32 7,
706 // CHECK-NEXT: store i16 9, i16*
707 // CHECK: call void @__kmpc_barrier(%struct.ident_t* {{.+}}, i32 %{{.+}})
708 // CHECK: ret void
709 }
710 
711 extern char foo();
712 extern double globalfloat;
713 
714 // CHECK-LABEL: define {{.*void}} @{{.*}}widened{{.*}}
widened(float * a,float * b,float * c,float * d)715 void widened(float *a, float *b, float *c, float *d) {
716   int i; // outer loop counter
717   short j; // inner loop counter
718   globalfloat = 1.0;
719   int localint = 1;
720 // CHECK: store double {{.+}}, double* [[GLOBALFLOAT:@.+]]
721 // Counter is widened to 64 bits.
722 // CHECK:     [[MUL:%.+]] = mul nsw i64 2, %{{.+}}
723 // CHECK-NEXT: [[SUB:%.+]] = sub nsw i64 [[MUL]], 1
724 // CHECK-NEXT: store i64 [[SUB]], i64* [[OMP_LAST_IT:%[^,]+]],
725 // CHECK: call void @__kmpc_for_static_init_8(%struct.ident_t* {{[^,]+}}, i32 %{{[^,]+}}, i32 34, i32* %{{[^,]+}}, i64* [[LB:%[^,]+]], i64* [[UB:%[^,]+]], i64* [[STRIDE:%[^,]+]], i64 1, i64 1)
726 // CHECK-DAG: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
727 // CHECK-DAG: [[OMP_LAST_IT_VAL:%.+]] = load i64, i64* [[OMP_LAST_IT]],
728 // CHECK: [[CMP:%.+]] = icmp sgt i64 [[UB_VAL]], [[OMP_LAST_IT_VAL]]
729 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
730 // CHECK: [[TRUE]]:
731 // CHECK: [[OMP_LAST_IT_VAL:%.+]] = load i64, i64* [[OMP_LAST_IT]],
732 // CHECK: br label %[[SWITCH:[^,]+]]
733 // CHECK: [[FALSE]]:
734 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
735 // CHECK: br label %[[SWITCH]]
736 // CHECK: [[SWITCH]]:
737 // CHECK: [[UP:%.+]] = phi i64 [ [[OMP_LAST_IT_VAL]], %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
738 // CHECK: store i64 [[UP]], i64* [[UB]],
739 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
740 // CHECK: store i64 [[LB_VAL]], i64* [[OMP_IV:%[^,]+]],
741 //
742   #pragma omp for simd collapse(2) private(globalfloat, localint)
743 
744 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]]
745 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]]
746 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i64 [[IV]], [[UB_VAL]]
747 // CHECK-NEXT: br i1 [[CMP]], label %[[WIDE1_BODY:[^,]+]], label %[[WIDE1_END:[^,]+]]
748   for (i = 1; i < 3; i++) // 2 iterations
749     for (j = 0; j < foo(); j++) // foo() iterations
750   {
751 // CHECK: [[WIDE1_BODY]]:
752 // Start of body: calculate i from index:
753 // CHECK: [[IV1:%.+]] = load i64, i64* [[OMP_IV]]
754 // Calculation of the loop counters values...
755 // CHECK: store i32 {{[^,]+}}, i32* [[LC_I:.+]]
756 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]
757 // CHECK: store i16 {{[^,]+}}, i16* [[LC_J:.+]]
758 // ... loop body ...
759 //
760 // Here we expect store into private double var, not global
761 // CHECK-NOT: store double {{.+}}, double* [[GLOBALFLOAT]]
762     globalfloat = (float)j/i;
763     float res = b[j] * c[j];
764 // Store into a[i]:
765 // CHECK: store float [[RESULT:%.+]], float* [[RESULT_ADDR:%.+]]
766     a[i] = res * d[i];
767 // Then there's a store into private var localint:
768 // CHECK: store i32 {{.+}}, i32* [[LOCALINT:%[^,]+]]
769     localint = (int)j;
770 // CHECK: [[IV2:%.+]] = load i64, i64* [[OMP_IV]]
771 // CHECK-NEXT: [[ADD2:%.+]] = add nsw i64 [[IV2]], 1
772 // CHECK-NEXT: store i64 [[ADD2]], i64* [[OMP_IV]]
773 //
774 // br label %{{[^,]+}}, !llvm.loop ![[WIDE1_LOOP_ID]]
775 // CHECK: [[WIDE1_END]]:
776   }
777 // i,j are updated.
778 // CHECK: store i32 3, i32* [[I:%[^,]+]]
779 // CHECK: store i16
780 //
781 // Here we expect store into original localint, not its privatized version.
782 // CHECK-NOT: store i32 {{.+}}, i32* [[LOCALINT]]
783   localint = (int)j;
784 // CHECK: ret void
785 }
786 
787 // TERM_DEBUG-LABEL: bar
bar()788 int bar() { extern void mayThrow(); mayThrow(); return 0; };
789 
790 // TERM_DEBUG-LABEL: parallel_simd
parallel_simd(float * a)791 void parallel_simd(float *a) {
792 #pragma omp parallel
793 #pragma omp for simd
794   // TERM_DEBUG-NOT: __kmpc_global_thread_num
795   // TERM_DEBUG:     invoke i32 {{.*}}bar{{.*}}()
796   // TERM_DEBUG:     unwind label %[[TERM_LPAD:.+]],
797   // TERM_DEBUG-NOT: __kmpc_global_thread_num
798   // TERM_DEBUG:     [[TERM_LPAD]]
799   // TERM_DEBUG:     call void @__clang_call_terminate
800   // TERM_DEBUG:     unreachable
801   for (unsigned i = 131071; i <= 2147483647; i += 127)
802     a[i] += bar();
803 }
804 // TERM_DEBUG: !{{[0-9]+}} = !DILocation(line: [[@LINE-11]],
805 // TERM_DEBUG-NOT: line: 0,
806 // OMP45-NOT: !"llvm.loop.vectorize.enable", i1 false
807 // CHECK-DAG: ![[SIMD_LOOP]] = distinct !{![[SIMD_LOOP]], {{.*}}![[VECT_LOOP:[^,]+]]}
808 // CHECK-DAG: ![[VECT_LOOP]] = !{!"llvm.loop.vectorize.enable", i1 true}
809 // OMP45-NOT: !"llvm.loop.vectorize.enable", i1 false
810 // OMP50-DAG: ![[NOSIMD_LOOP]] = distinct !{![[NOSIMD_LOOP]], {{.*}}![[NOVECT_LOOP:[^,]+]]}
811 // OMP50-DAG: ![[NOVECT_LOOP]] = !{!"llvm.loop.vectorize.enable", i1 false}
812 #endif // HEADER
813