1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK --check-prefix=LIFETIME --check-prefix=OMP45
2 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK --check-prefix=LIFETIME --check-prefix=OMP5
3 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
4 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=OMP5
5 // 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
6 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -fopenmp-version=45 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
7 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -gno-column-info -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
8 // RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm -fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | FileCheck %s --check-prefix=PROF-INSTR-PATH
9
10 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
11 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
12 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
13 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
14 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
15 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
16 // RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm -fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | FileCheck --check-prefix SIMD-ONLY0 %s
17 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
18 //
19 // expected-no-diagnostics
20 #ifndef HEADER
21 #define HEADER
22 // PROF-INSTR-PATH: constant [25 x i8] c"for_codegen-test.profraw\00"
23
24 // CHECK: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
25 // CHECK-DAG: [[IMPLICIT_BARRIER_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 66, i32 0, i32 0, i8*
26 // CHECK-DAG: [[LOOP_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 514, i32 0, i32 0, i8*
27 // CHECK-DAG: [[I:@.+]] = global i8 1,
28 // CHECK-DAG: [[J:@.+]] = global i8 2,
29 // CHECK-DAG: [[K:@.+]] = global i8 3,
30
31 // CHECK-LABEL: loop_with_counter_collapse
loop_with_counter_collapse()32 void loop_with_counter_collapse() {
33 // Captured initializations.
34 // CHECK: store i32 0, i32* [[I_TMP:%.+]],
35 // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]],
36 // CHECK: store i32 [[VAL]], i32* [[J_LB_MIN:%.+]],
37 // CHECK: store i32 3, i32* [[I_TMP]],
38 // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]],
39 // CHECK: store i32 [[VAL]], i32* [[J_LB_MAX:%.+]],
40 // CHECK: [[J_LB_MIN_VAL:%.+]] = load i32, i32* [[J_LB_MIN]],
41 // CHECK: [[J_LB_MAX_VAL:%.+]] = load i32, i32* [[J_LB_MAX]],
42 // CHECK: [[CMP:%.+]] = icmp slt i32 [[J_LB_MIN_VAL]], [[J_LB_MAX_VAL]]
43 // CHECK: [[BOOL:%.+]] = zext i1 [[CMP]] to i8
44 // CHECK: store i8 [[BOOL]], i8* [[J_LB_CMP:%.+]],
45 // CHECK: store i32 0, i32* [[I_TMP]],
46 // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]],
47 // CHECK: [[J_UB_MIN_VAL:%.+]] = add nsw i32 4, [[VAL]]
48 // CHECK: store i32 [[J_UB_MIN_VAL]], i32* [[J_UB_MIN:%.+]],
49 // CHECK: store i32 3, i32* [[I_TMP]],
50 // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]],
51 // CHECK: [[J_UB_MAX_VAL:%.+]] = add nsw i32 4, [[VAL]]
52 // CHECK: store i32 [[J_UB_MAX_VAL]], i32* [[J_UB_MAX:%.+]],
53 // CHECK: [[J_UB_MIN_VAL:%.+]] = load i32, i32* [[J_UB_MIN]],
54 // CHECK: [[J_UB_MAX_VAL:%.+]] = load i32, i32* [[J_UB_MAX]],
55 // CHECK: [[CMP:%.+]] = icmp sgt i32 [[J_UB_MIN_VAL]], [[J_UB_MAX_VAL]]
56 // CHECK: [[BOOL:%.+]] = zext i1 [[CMP]] to i8
57 // CHECK: store i8 [[BOOL]], i8* [[J_UB_CMP:%.+]],
58 // CHECK: [[J_UB_CMP_VAL:%.+]] = load i8, i8* [[J_UB_CMP]],
59 // CHECK: [[BOOL:%.+]] = trunc i8 [[J_UB_CMP_VAL]] to i1
60 // CHECK: br i1 [[BOOL]], label %[[TRUE:[^,]+]], label %[[FALSE:[^,]+]]
61 // CHECK: [[TRUE]]:
62 // CHECK: [[J_UB_MIN_VAL:%.+]] = load i32, i32* [[J_UB_MIN]],
63 // CHECK: br label %[[EXIT:[^,]+]]
64 // CHECK: [[FALSE]]:
65 // CHECK: [[J_UB_MAX_VAL:%.+]] = load i32, i32* [[J_UB_MAX]],
66 // CHECK: br label %[[EXIT]]
67 // CHECK: [[EXIT]]:
68 // CHECK: [[J_UB_VAL:%.+]] = phi i32 [ [[J_UB_MIN_VAL]], %[[TRUE]] ], [ [[J_UB_MAX_VAL]], %[[FALSE]] ]
69 // CHECK: store i32 [[J_UB_VAL]], i32* [[J_UB:%.+]],
70 // CHECK: [[J_LB_CMP_VAL:%.+]] = load i8, i8* [[J_LB_CMP]],
71 // CHECK: [[BOOL:%.+]] = trunc i8 [[J_LB_CMP_VAL]] to i1
72 // CHECK: br i1 [[BOOL]], label %[[TRUE:[^,]+]], label %[[FALSE:[^,]+]]
73 // CHECK: [[TRUE]]:
74 // CHECK: [[J_LB_MIN_VAL:%.+]] = load i32, i32* [[J_LB_MIN]],
75 // CHECK: br label %[[EXIT:[^,]+]]
76 // CHECK: [[FALSE]]:
77 // CHECK: [[J_LB_MAX_VAL:%.+]] = load i32, i32* [[J_LB_MAX]],
78 // CHECK: br label %[[EXIT]]
79 // CHECK: [[EXIT]]:
80 // CHECK: [[J_LB_VAL:%.+]] = phi i32 [ [[J_LB_MIN_VAL]], %[[TRUE]] ], [ [[J_LB_MAX_VAL]], %[[FALSE]] ]
81 // CHECK: store i32 [[J_LB_VAL]], i32* [[J_LB:%.+]],
82 // CHECK: [[J_UB_VAL:%.+]] = load i32, i32* [[J_UB]],
83 // CHECK: [[J_LB_VAL:%.+]] = load i32, i32* [[J_LB]],
84 // CHECK: [[SUB:%.+]] = sub i32 [[J_UB_VAL]], [[J_LB_VAL]]
85 // CHECK: [[SUB_ST:%.+]] = sub i32 [[SUB]], 1
86 // CHECK: [[ADD_ST:%.+]] = add i32 [[SUB_ST]], 1
87 // CHECK: [[DIV_ST:%.+]] = udiv i32 [[ADD_ST]], 1
88 // CHECK: [[CAST:%.+]] = zext i32 [[DIV_ST]] to i64
89 // CHECK: [[MUL:%.+]] = mul nsw i64 4, [[CAST]]
90 // CHECK: [[NUM_ITERS_VAL:%.+]] = sub nsw i64 [[MUL]], 1
91 // CHECK: store i64 [[NUM_ITERS_VAL]], i64* [[NUM_ITERS:%.+]],
92
93 // CHECK: store i64 0, i64* [[LB:%.+]],
94 // CHECK: [[NUM_ITERS_VAL:%.+]] = load i64, i64* [[NUM_ITERS]],
95 // CHECK: store i64 [[NUM_ITERS_VAL]], i64* [[UB:%.+]],
96 // CHECK: store i64 1, i64* [[STRIDE:%.+]],
97 // CHECK: store i32 0, i32* [[IS_LAST:%.+]],
98 // CHECK: call void @__kmpc_for_static_init_8(%struct.ident_t* @{{.+}}, i32 %{{.+}}, i32 34, i32* [[IS_LAST]], i64* [[LB]], i64* [[UB]], i64* [[STRIDE]], i64 1, i64 1)
99 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
100 // CHECK: [[NUM_ITERS_VAL:%.+]] = load i64, i64* [[NUM_ITERS]],
101 // CHECK: [[CMP:%.+]] = icmp sgt i64 [[UB_VAL]], [[NUM_ITERS_VAL]]
102 // CHECK: br i1 [[CMP]], label %[[TRUE:[^,]+]], label %[[FALSE:[^,]+]]
103 // CHECK: [[TRUE]]:
104 // CHECK: [[NUM_ITERS_VAL:%.+]] = load i64, i64* [[NUM_ITERS]],
105 // CHECK: br label %[[DONE:[^,]+]]
106 // CHECK: [[FALSE]]:
107 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
108 // CHECK: br label %[[DONE]]
109 // CHECK: [[DONE]]:
110 // CHECK: [[TOP:%.+]] = phi i64 [ [[NUM_ITERS_VAL]], %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
111 // CHECK: store i64 [[TOP]], i64* [[UB]],
112 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
113 // CHECK: store i64 [[LB_VAL]], i64* [[IV:%.+]],
114 // CHECK: br label %[[COND:[^,]+]]
115 // CHECK: [[COND]]:
116 // CHECK: [[IV_VAL:%.+]] = load i64, i64* [[IV]],
117 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
118 // CHECK: [[CMP:%.+]] = icmp sle i64 [[IV_VAL]], [[UB_VAL]]
119 // CHECK: br i1 [[CMP]], label %[[BODY:[^,]+]], label %[[CLEANUP:[^,]+]]
120 // LIFETIME: [[CLEANUP]]:
121 // LIFETIME: br label %[[CLEANUP:[^,]+]]
122 // CHECK: [[BODY]]:
123 // CHECK: [[IV_VAL:%.+]] = load i64, i64* [[IV]],
124 // CHECK: [[J_UB_VAL:%.+]] = load i32, i32* [[J_UB]],
125 // CHECK: [[J_LB_VAL:%.+]] = load i32, i32* [[J_LB]],
126 // CHECK: [[SUB:%.+]] = sub i32 [[J_UB_VAL]], [[J_LB_VAL]]
127 // CHECK: [[SUB_ST:%.+]] = sub i32 [[SUB]], 1
128 // CHECK: [[ADD_ST:%.+]] = add i32 [[SUB_ST]], 1
129 // CHECK: [[DIV_ST:%.+]] = udiv i32 [[ADD_ST]], 1
130 // CHECK: [[MUL:%.+]] = mul i32 1, [[DIV_ST]]
131 // CHECK: [[CAST:%.+]] = zext i32 [[MUL]] to i64
132 // CHECK: [[DIV:%.+]] = sdiv i64 [[IV_VAL]], [[CAST]]
133 // CHECK: [[MUL:%.+]] = mul nsw i64 [[DIV]], 1
134 // CHECK: [[ADD:%.+]] = add nsw i64 0, [[MUL]]
135 // CHECK: [[CAST:%.+]] = trunc i64 [[ADD]] to i32
136 // CHECK: store i32 [[CAST]], i32* [[I_PRIV:%.+]],
137 // CHECK: [[I_VAL:%.+]] = load i32, i32* [[I_PRIV]],
138 // CHECK: [[CONV:%.+]] = sext i32 [[I_VAL]] to i64
139 // CHECK: [[IV_VAL:%.+]] = load i64, i64* [[IV]],
140 // CHECK: [[IV_VAL1:%.+]] = load i64, i64* [[IV]],
141 // CHECK: [[J_UB_VAL:%.+]] = load i32, i32* [[J_UB]],
142 // CHECK: [[J_LB_VAL:%.+]] = load i32, i32* [[J_LB]],
143 // CHECK: [[SUB:%.+]] = sub i32 [[J_UB_VAL]], [[J_LB_VAL]]
144 // CHECK: [[SUB_ST:%.+]] = sub i32 [[SUB]], 1
145 // CHECK: [[ADD_ST:%.+]] = add i32 [[SUB_ST]], 1
146 // CHECK: [[DIV_ST:%.+]] = udiv i32 [[ADD_ST]], 1
147 // CHECK: [[MUL:%.+]] = mul i32 1, [[DIV_ST]]
148 // CHECK: [[CAST:%.+]] = zext i32 [[MUL]] to i64
149 // CHECK: [[DIV:%.+]] = sdiv i64 [[IV_VAL1]], [[CAST]]
150 // CHECK: [[J_UB_VAL:%.+]] = load i32, i32* [[J_UB]],
151 // CHECK: [[J_LB_VAL:%.+]] = load i32, i32* [[J_LB]],
152 // CHECK: [[SUB:%.+]] = sub i32 [[J_UB_VAL]], [[J_LB_VAL]]
153 // CHECK: [[SUB_ST:%.+]] = sub i32 [[SUB]], 1
154 // CHECK: [[ADD_ST:%.+]] = add i32 [[SUB_ST]], 1
155 // CHECK: [[DIV_ST:%.+]] = udiv i32 [[ADD_ST]], 1
156 // CHECK: [[MUL:%.+]] = mul i32 1, [[DIV_ST]]
157 // CHECK: [[CAST:%.+]] = zext i32 [[MUL]] to i64
158 // CHECK: [[MUL:%.+]] = mul nsw i64 [[DIV]], [[CAST]]
159 // CHECK: [[SUB:%.+]] = sub nsw i64 [[IV_VAL]], [[MUL]]
160 // CHECK: [[MUL:%.+]] = mul nsw i64 [[SUB:%.+]], 1
161 // CHECK: [[ADD:%.+]] = add nsw i64 [[CONV]], [[MUL]]
162 // CHECK: [[CAST:%.+]] = trunc i64 [[ADD]] to i32
163 // CHECK: store i32 [[CAST]], i32* [[J_PRIV:%.+]],
164
165 // Check that the loop variable is not out of its boundaries.
166 // CHECK: [[J_VAL:%.+]] = load i32, i32* [[J_PRIV]],
167 // CHECK: [[I_VAL:%.+]] = load i32, i32* [[I_PRIV]],
168 // CHECK: [[J_COND:%.+]] = add nsw i32 4, [[I_VAL]]
169 // CHECK: [[CMP:%.+]] = icmp slt i32 [[J_VAL]], [[J_COND]]
170 // CHECK: br i1 [[CMP]], label %[[NEXT:[^,]+]], label %[[BODY_CONT:[^,]+]]
171 // CHECK: [[NEXT]]:
172
173 // Main body is empty.
174 // CHECK: br label %[[BODY_CONT]]
175 // CHECK: [[BODY_CONT]]:
176 // CHECK: br label %[[INC:[^,]+]]
177 // CHECK: [[INC]]:
178 // CHECK: [[IV_VAL:%.+]] = load i64, i64* [[IV]],
179 // CHECK: [[ADD:%.+]] = add nsw i64 [[IV_VAL]], 1
180 // CHECK: store i64 [[ADD]], i64* [[IV]],
181 // CHECK: br label %[[COND]]
182 // CHECK: [[CLEANUP]]:
183 // CHECK: br label %[[EXIT:[^,]+]]
184 // CHECK: [[EXIT]]:
185 // CHECK: call void @__kmpc_for_static_fini(%struct.ident_t* @{{.+}}, i32 %{{.+}})
186 // LIFETIME: call void @llvm.lifetime.end
187 // LIFETIME: call void @llvm.lifetime.end
188 // LIFETIME: call void @llvm.lifetime.end
189 // LIFETIME: call void @llvm.lifetime.end
190 // LIFETIME: call void @llvm.lifetime.end
191 // LIFETIME: call void @llvm.lifetime.end
192 // LIFETIME: call void @llvm.lifetime.end
193 // LIFETIME: call void @llvm.lifetime.end
194 // LIFETIME: call void @llvm.lifetime.end
195 #pragma omp for collapse(2)
196 for (int i = 0; i < 4; i++) {
197 for (int j = i; j < 4 + i; j++) {
198 }
199 }
200 }
201 // CHECK-LABEL: define {{.*void}} @{{.*}}without_schedule_clause{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
without_schedule_clause(float * a,float * b,float * c,float * d)202 void without_schedule_clause(float *a, float *b, float *c, float *d) {
203 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
204 #pragma omp for nowait
205 // CHECK: call void @__kmpc_for_static_init_4([[IDENT_T_TY]]* [[LOOP_LOC]], i32 [[GTID]], i32 34, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 1)
206 // UB = min(UB, GlobalUB)
207 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
208 // CHECK-NEXT: [[UBCMP:%.+]] = icmp sgt i32 [[UB]], 4571423
209 // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]]
210 // CHECK: [[UBRESULT:%.+]] = phi i32 [ 4571423, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ]
211 // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]]
212 // CHECK-NEXT: [[LB:%.+]] = load i32, i32* [[OMP_LB]]
213 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]]
214 // Loop header
215 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]
216 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
217 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
218 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
219 for (int i = 33; i < 32000000; i += 7) {
220 // CHECK: [[LOOP1_BODY]]
221 // Start of body: calculate i from IV:
222 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]
223 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 7
224 // CHECK-NEXT: [[CALC_I_2:%.+]] = add nsw i32 33, [[CALC_I_1]]
225 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
226 // ... loop body ...
227 // End of body: store into a[i]:
228 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}
229 // CHECK-NOT: !llvm.access.group
230 a[i] = b[i] * c[i] * d[i];
231 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}
232 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
233 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
234 // CHECK-NEXT: br label %{{.+}}
235 }
236 // CHECK: [[LOOP1_END]]
237 // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[LOOP_LOC]], i32 [[GTID]])
238 // CHECK-NOT: __kmpc_barrier
239 // CHECK: ret void
240 }
241
242 // CHECK-LABEL: define {{.*void}} @{{.*}}static_not_chunked{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
static_not_chunked(float * a,float * b,float * c,float * d)243 void static_not_chunked(float *a, float *b, float *c, float *d) {
244 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
245 #pragma omp for schedule(static)
246 // CHECK: call void @__kmpc_for_static_init_4([[IDENT_T_TY]]* [[LOOP_LOC]], i32 [[GTID]], i32 34, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 1)
247 // UB = min(UB, GlobalUB)
248 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
249 // CHECK-NEXT: [[UBCMP:%.+]] = icmp sgt i32 [[UB]], 4571423
250 // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]]
251 // CHECK: [[UBRESULT:%.+]] = phi i32 [ 4571423, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ]
252 // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]]
253 // CHECK-NEXT: [[LB:%.+]] = load i32, i32* [[OMP_LB]]
254 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]]
255 // Loop header
256 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]
257 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
258 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
259 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
260 for (int i = 32000000; i > 33; i += -7) {
261 // CHECK: [[LOOP1_BODY]]
262 // Start of body: calculate i from IV:
263 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]
264 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 7
265 // CHECK-NEXT: [[CALC_I_2:%.+]] = sub nsw i32 32000000, [[CALC_I_1]]
266 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
267 // ... loop body ...
268 // End of body: store into a[i]:
269 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}
270 // CHECK-NOT: !llvm.access.group
271 a[i] = b[i] * c[i] * d[i];
272 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}
273 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
274 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
275 // CHECK-NEXT: br label %{{.+}}
276 }
277 // CHECK: [[LOOP1_END]]
278 // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[LOOP_LOC]], i32 [[GTID]])
279 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
280 // CHECK: ret void
281 }
282
283 // CHECK-LABEL: define {{.*void}} @{{.*}}static_chunked{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
static_chunked(float * a,float * b,float * c,float * d)284 void static_chunked(float *a, float *b, float *c, float *d) {
285 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
286 #pragma omp for schedule(monotonic: static, 5)
287 // CHECK: call void @__kmpc_for_static_init_4u([[IDENT_T_TY]]* [[LOOP_LOC]], i32 [[GTID]], i32 536870945, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 5)
288 // UB = min(UB, GlobalUB)
289 // CHECK: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
290 // CHECK-NEXT: [[UBCMP:%.+]] = icmp ugt i32 [[UB]], 16908288
291 // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]]
292 // CHECK: [[UBRESULT:%.+]] = phi i32 [ 16908288, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ]
293 // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]]
294 // CHECK-NEXT: [[LB:%.+]] = load i32, i32* [[OMP_LB]]
295 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]]
296
297 // Outer loop header
298 // CHECK: [[O_IV:%.+]] = load i32, i32* [[OMP_IV]]
299 // CHECK-NEXT: [[O_UB:%.+]] = load i32, i32* [[OMP_UB]]
300 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ule i32 [[O_IV]], [[O_UB]]
301 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]]
302
303 // Loop header
304 // CHECK: [[O_LOOP1_BODY]]
305 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]
306 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
307 // CHECK-NEXT: [[CMP:%.+]] = icmp ule i32 [[IV]], [[UB]]
308 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
309 for (unsigned i = 131071; i <= 2147483647; i += 127) {
310 // CHECK: [[LOOP1_BODY]]
311 // Start of body: calculate i from IV:
312 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]
313 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul i32 [[IV1_1]], 127
314 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i32 131071, [[CALC_I_1]]
315 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
316 // ... loop body ...
317 // End of body: store into a[i]:
318 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}
319 // CHECK-NOT: !llvm.access.group
320 a[i] = b[i] * c[i] * d[i];
321 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}
322 // CHECK-NEXT: [[ADD1_2:%.+]] = add i32 [[IV1_2]], 1
323 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
324 // CHECK-NEXT: br label %{{.+}}
325 }
326 // CHECK: [[LOOP1_END]]
327 // Update the counters, adding stride
328 // CHECK: [[LB:%.+]] = load i32, i32* [[OMP_LB]]
329 // CHECK-NEXT: [[ST:%.+]] = load i32, i32* [[OMP_ST]]
330 // CHECK-NEXT: [[ADD_LB:%.+]] = add i32 [[LB]], [[ST]]
331 // CHECK-NEXT: store i32 [[ADD_LB]], i32* [[OMP_LB]]
332 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
333 // CHECK-NEXT: [[ST:%.+]] = load i32, i32* [[OMP_ST]]
334 // CHECK-NEXT: [[ADD_UB:%.+]] = add i32 [[UB]], [[ST]]
335 // CHECK-NEXT: store i32 [[ADD_UB]], i32* [[OMP_UB]]
336
337 // CHECK: [[O_LOOP1_END]]
338 // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[LOOP_LOC]], i32 [[GTID]])
339 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
340 // CHECK: ret void
341 }
342
343 // CHECK-LABEL: define {{.*void}} @{{.*}}dynamic1{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
dynamic1(float * a,float * b,float * c,float * d)344 void dynamic1(float *a, float *b, float *c, float *d) {
345 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
346 #pragma omp for schedule(nonmonotonic: dynamic)
347 // CHECK: call void @__kmpc_dispatch_init_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 1073741859, i64 0, i64 16908287, i64 1, i64 1)
348 //
349 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i64* [[OMP_LB:%[^,]+]], i64* [[OMP_UB:%[^,]+]], i64* [[OMP_ST:%[^,]+]])
350 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0
351 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]]
352
353 // Loop header
354 // CHECK: [[O_LOOP1_BODY]]
355 // CHECK: [[LB:%.+]] = load i64, i64* [[OMP_LB]]
356 // CHECK-NEXT: store i64 [[LB]], i64* [[OMP_IV:[^,]+]]
357 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]]
358
359 // CHECK-NEXT: [[UB:%.+]] = load i64, i64* [[OMP_UB]]
360 // CHECK-NEXT: [[BOUND:%.+]] = add i64 [[UB]], 1
361 // CHECK-NEXT: [[CMP:%.+]] = icmp ult i64 [[IV]], [[BOUND]]
362 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
363 for (unsigned long long i = 131071; i < 2147483647; i += 127) {
364 // CHECK: [[LOOP1_BODY]]
365 // Start of body: calculate i from IV:
366 // CHECK: [[IV1_1:%.+]] = load i64, i64* [[OMP_IV]]
367 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul i64 [[IV1_1]], 127
368 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i64 131071, [[CALC_I_1]]
369 // CHECK-NEXT: store i64 [[CALC_I_2]], i64* [[LC_I:.+]]
370 // ... loop body ...
371 // End of body: store into a[i]:
372 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}!llvm.access.group
373 a[i] = b[i] * c[i] * d[i];
374 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}}
375 // CHECK-NEXT: [[ADD1_2:%.+]] = add i64 [[IV1_2]], 1
376 // CHECK-NEXT: store i64 [[ADD1_2]], i64* [[OMP_IV]]
377 // CHECK-NEXT: br label %{{.+}}
378 }
379 // CHECK: [[LOOP1_END]]
380 // CHECK: [[O_LOOP1_END]]
381 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
382 // CHECK: ret void
383 }
384
385 // CHECK-LABEL: define {{.*void}} @{{.*}}guided7{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
guided7(float * a,float * b,float * c,float * d)386 void guided7(float *a, float *b, float *c, float *d) {
387 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
388 #pragma omp for schedule(guided, 7)
389 // OMP45: call void @__kmpc_dispatch_init_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 36, i64 0, i64 16908287, i64 1, i64 7)
390 // OMP5: call void @__kmpc_dispatch_init_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 1073741860, i64 0, i64 16908287, i64 1, i64 7)
391 //
392 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i64* [[OMP_LB:%[^,]+]], i64* [[OMP_UB:%[^,]+]], i64* [[OMP_ST:%[^,]+]])
393 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0
394 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]]
395
396 // Loop header
397 // CHECK: [[O_LOOP1_BODY]]
398 // CHECK: [[LB:%.+]] = load i64, i64* [[OMP_LB]]
399 // CHECK-NEXT: store i64 [[LB]], i64* [[OMP_IV:[^,]+]]
400 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]]
401
402 // CHECK-NEXT: [[UB:%.+]] = load i64, i64* [[OMP_UB]]
403 // CHECK-NEXT: [[BOUND:%.+]] = add i64 [[UB]], 1
404 // CHECK-NEXT: [[CMP:%.+]] = icmp ult i64 [[IV]], [[BOUND]]
405 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
406 for (unsigned long long i = 131071; i < 2147483647; i += 127) {
407 // CHECK: [[LOOP1_BODY]]
408 // Start of body: calculate i from IV:
409 // CHECK: [[IV1_1:%.+]] = load i64, i64* [[OMP_IV]]
410 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul i64 [[IV1_1]], 127
411 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i64 131071, [[CALC_I_1]]
412 // CHECK-NEXT: store i64 [[CALC_I_2]], i64* [[LC_I:.+]]
413 // ... loop body ...
414 // End of body: store into a[i]:
415 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}!llvm.access.group
416 a[i] = b[i] * c[i] * d[i];
417 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}}
418 // CHECK-NEXT: [[ADD1_2:%.+]] = add i64 [[IV1_2]], 1
419 // CHECK-NEXT: store i64 [[ADD1_2]], i64* [[OMP_IV]]
420 // CHECK-NEXT: br label %{{.+}}
421 }
422 // CHECK: [[LOOP1_END]]
423 // CHECK: [[O_LOOP1_END]]
424 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
425 // CHECK: ret void
426 }
427
428 // CHECK-LABEL: define {{.*void}} @{{.*}}test_auto{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
test_auto(float * a,float * b,float * c,float * d)429 void test_auto(float *a, float *b, float *c, float *d) {
430 unsigned int x = 0;
431 unsigned int y = 0;
432 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
433 #pragma omp for schedule(auto) collapse(2)
434 // OMP45: call void @__kmpc_dispatch_init_8([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 38, i64 0, i64 [[LAST_ITER:%[^,]+]], i64 1, i64 1)
435 // OMP5: call void @__kmpc_dispatch_init_8([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 1073741862, i64 0, i64 [[LAST_ITER:%[^,]+]], i64 1, i64 1)
436 //
437 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_8([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i64* [[OMP_LB:%[^,]+]], i64* [[OMP_UB:%[^,]+]], i64* [[OMP_ST:%[^,]+]])
438 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0
439 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]]
440
441 // Loop header
442 // CHECK: [[O_LOOP1_BODY]]
443 // CHECK: [[LB:%.+]] = load i64, i64* [[OMP_LB]]
444 // CHECK-NEXT: store i64 [[LB]], i64* [[OMP_IV:[^,]+]]
445 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]]
446
447 // CHECK-NEXT: [[UB:%.+]] = load i64, i64* [[OMP_UB]]
448 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i64 [[IV]], [[UB]]
449 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
450 // FIXME: When the iteration count of some nested loop is not a known constant,
451 // we should pre-calculate it, like we do for the total number of iterations!
452 for (char i = static_cast<char>(y); i <= '9'; ++i)
453 for (x = 11; x > 0; --x) {
454 // CHECK: [[LOOP1_BODY]]
455 // Start of body: indices are calculated from IV:
456 // CHECK: store i8 {{%[^,]+}}, i8* {{%[^,]+}}
457 // CHECK: store i32 {{%[^,]+}}, i32* {{%[^,]+}}
458 // ... loop body ...
459 // End of body: store into a[i]:
460 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}
461 // CHECK-NOT: !llvm.access.group
462 a[i] = b[i] * c[i] * d[i];
463 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}}
464 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i64 [[IV1_2]], 1
465 // CHECK-NEXT: store i64 [[ADD1_2]], i64* [[OMP_IV]]
466 // CHECK-NEXT: br label %{{.+}}
467 }
468 // CHECK: [[LOOP1_END]]
469 // CHECK: [[O_LOOP1_END]]
470 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
471 // CHECK: ret void
472 }
473
474 // CHECK-LABEL: define {{.*void}} @{{.*}}runtime{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
runtime(float * a,float * b,float * c,float * d)475 void runtime(float *a, float *b, float *c, float *d) {
476 int x = 0;
477 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
478 #pragma omp for collapse(2) schedule(runtime)
479 // OMP45: call void @__kmpc_dispatch_init_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 37, i32 0, i32 199, i32 1, i32 1)
480 // OMP5: call void @__kmpc_dispatch_init_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 1073741861, i32 0, i32 199, i32 1, i32 1)
481 //
482 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]])
483 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0
484 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]]
485
486 // Loop header
487 // CHECK: [[O_LOOP1_BODY]]
488 // CHECK: [[LB:%.+]] = load i32, i32* [[OMP_LB]]
489 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]]
490 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]
491
492 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]]
493 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
494 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
495 for (unsigned char i = '0' ; i <= '9'; ++i)
496 for (x = -10; x < 10; ++x) {
497 // CHECK: [[LOOP1_BODY]]
498 // Start of body: indices are calculated from IV:
499 // CHECK: store i8 {{%[^,]+}}, i8* {{%[^,]+}}
500 // CHECK: store i32 {{%[^,]+}}, i32* {{%[^,]+}}
501 // ... loop body ...
502 // End of body: store into a[i]:
503 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}
504 // CHECK-NOT: !llvm.access.group
505 a[i] = b[i] * c[i] * d[i];
506 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}
507 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
508 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
509 // CHECK-NEXT: br label %{{.+}}
510 }
511 // CHECK: [[LOOP1_END]]
512 // CHECK: [[O_LOOP1_END]]
513 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
514 // CHECK: ret void
515 }
516
517 // CHECK-LABEL: test_precond
test_precond()518 void test_precond() {
519 // CHECK: [[A_ADDR:%.+]] = alloca i8,
520 // CHECK: [[I_ADDR:%.+]] = alloca i8,
521 // CHECK: [[CAP:%.+]] = alloca i8,
522 char a = 0;
523 // CHECK: store i8 0,
524 // CHECK: store i32
525 // CHECK: store i8
526 // CHECK: [[A:%.+]] = load i8, i8* [[CAP]],
527 // CHECK: [[CONV:%.+]] = sext i8 [[A]] to i32
528 // CHECK: [[CMP:%.+]] = icmp slt i32 [[CONV]], 10
529 // CHECK: br i1 [[CMP]], label %[[PRECOND_THEN:[^,]+]], label %[[PRECOND_END:[^,]+]]
530 // CHECK: [[PRECOND_THEN]]
531 // CHECK: call void @__kmpc_for_static_init_4
532 #pragma omp for
533 for(char i = a; i < 10; ++i);
534 // CHECK: call void @__kmpc_for_static_fini
535 // CHECK: [[PRECOND_END]]
536 }
537
538 // TERM_DEBUG-LABEL: foo
foo()539 int foo() { extern void mayThrow(); mayThrow(); return 0;};
540
541 // TERM_DEBUG-LABEL: parallel_for
parallel_for(float * a)542 void parallel_for(float *a) {
543 #pragma omp parallel
544 #pragma omp for schedule(static, 5)
545 // TERM_DEBUG-NOT: __kmpc_global_thread_num
546 // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg [[DBG_LOC:![0-9]+]]
547 // TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}()
548 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
549 // TERM_DEBUG-NOT: __kmpc_global_thread_num
550 // TERM_DEBUG: call void @__kmpc_for_static_fini({{.+}}), !dbg [[DBG_LOC]]
551 // TERM_DEBUG: call {{.+}} @__kmpc_barrier({{.+}}), !dbg [[DBG_LOC]]
552 // TERM_DEBUG: [[TERM_LPAD]]
553 // TERM_DEBUG: call void @__clang_call_terminate
554 // TERM_DEBUG: unreachable
555 for (unsigned i = 131071; i <= 2147483647; i += 127)
556 a[i] += foo();
557 }
558 // Check source line corresponds to "#pragma omp for schedule(static, 5)" above:
559 // TERM_DEBUG: [[DBG_LOC]] = !DILocation(line: [[@LINE-15]],
560
561 char i = 1, j = 2, k = 3;
562 // CHECK-LABEL: for_with_global_lcv
for_with_global_lcv()563 void for_with_global_lcv() {
564 // CHECK: alloca i8,
565 // CHECK: [[I_ADDR:%.+]] = alloca i8,
566 // CHECK: alloca i8,
567 // CHECK: [[J_ADDR:%.+]] = alloca i8,
568
569 // CHECK: call void @__kmpc_for_static_init_4(
570 // CHECK-NOT: [[I]]
571 // CHECK: store i8 %{{.+}}, i8* [[I_ADDR]]
572 // CHECK-NOT: [[I]]
573 // CHECK: [[I_VAL:%.+]] = load i8, i8* [[I_ADDR]],
574 // CHECK-NOT: [[I]]
575 // CHECK: store i8 [[I_VAL]], i8* [[K]]
576 // CHECK-NOT: [[I]]
577 // CHECK: call void @__kmpc_for_static_fini(
578 // CHECK: call void @__kmpc_barrier(
579 #pragma omp for
580 for (i = 0; i < 2; ++i) {
581 k = i;
582 }
583 // CHECK: call void @__kmpc_for_static_init_4(
584 // CHECK-NOT: [[J]]
585 // CHECK: store i8 %{{.+}}, i8* [[J_ADDR]]
586 // CHECK-NOT: [[J]]
587 // CHECK: [[J_VAL:%.+]] = load i8, i8* [[J_ADDR]],
588 // CHECK-NOT: [[J]]
589 // CHECK: store i8 [[J_VAL]], i8* [[K]]
590 // CHECK-NOT: [[J]]
591 // CHECK: call void @__kmpc_for_static_fini(
592 #pragma omp for collapse(2)
593 for (int i = 0; i < 2; ++i)
594 for (j = 0; j < 2; ++j) {
595 k = i;
596 k = j;
597 }
598 char &cnt = i;
599 #pragma omp for
600 for (cnt = 0; cnt < 2; ++cnt)
601 k = cnt;
602 }
603
604 // CHECK-LABEL: for_with_references
for_with_references()605 void for_with_references() {
606 // CHECK: [[I:%.+]] = alloca i8,
607 // CHECK: [[CNT:%.+]] = alloca i8*,
608 // CHECK: [[CNT_PRIV:%.+]] = alloca i8,
609 // CHECK: call void @__kmpc_for_static_init_8(
610 // CHECK-NOT: load i8, i8* [[CNT]],
611 // CHECK: call void @__kmpc_for_static_fini(
612 char i = 0;
613 char &cnt = i;
614 #pragma omp for collapse(2)
615 for (cnt = 0; cnt < 2; ++cnt)
616 for (int j = cnt; j < 4 + cnt; j++)
617 k = cnt;
618 }
619
620 // CHECK-LABEL: for_with_references_dep_cond
for_with_references_dep_cond()621 void for_with_references_dep_cond() {
622 // CHECK: [[I:%.+]] = alloca i8,
623 // CHECK: [[CNT:%.+]] = alloca i8*,
624 // CHECK: [[CNT_PRIV:%.+]] = alloca i8,
625 // CHECK: call void @__kmpc_for_static_init_8(
626 // CHECK-NOT: load i8, i8* [[CNT]],
627 // CHECK: call void @__kmpc_for_static_fini(
628 char i = 0;
629 char &cnt = i;
630 #pragma omp for collapse(2)
631 for (cnt = 0; cnt < 2; ++cnt)
632 for (int j = 0; j < 4 + cnt; j++)
633 k = cnt;
634 }
635
636 struct Bool {
BoolBool637 Bool(bool b) : b(b) {}
operator boolBool638 operator bool() const { return b; }
639 const bool b;
640 };
641
642 template <typename T>
643 struct It {
ItIt644 It() : p(0) {}
645 It(const It &, int = 0) ;
646 template <typename U>
647 It(U &, int = 0) ;
648 It &operator=(const It &);
649 It &operator=(It &);
~ItIt650 ~It() {}
651
ItIt652 It(T *p) : p(p) {}
653
operator T*&It654 operator T *&() { return p; }
operator T*It655 operator T *() const { return p; }
operator ->It656 T *operator->() const { return p; }
657
operator ++It658 It &operator++() { ++p; return *this; }
operator --It659 It &operator--() { --p; return *this; }
operator +=It660 It &operator+=(unsigned n) { p += n; return *this; }
operator -=It661 It &operator-=(unsigned n) { p -= n; return *this; }
662
663 T *p;
664 };
665
666 template <typename T>
operator +(It<T> a,typename It<T>::difference_type n)667 It<T> operator+(It<T> a, typename It<T>::difference_type n) { return a.p + n; }
668
669 template <typename T>
operator +(typename It<T>::difference_type n,It<T> a)670 It<T> operator+(typename It<T>::difference_type n, It<T> a) { return a.p + n; }
671
672 template <typename T>
operator -(It<T> a,typename It<T>::difference_type n)673 It<T> operator-(It<T> a, typename It<T>::difference_type n) { return a.p - n; }
674
675 typedef Bool BoolType;
676
677 template <typename T>
operator <(It<T> a,It<T> b)678 BoolType operator<(It<T> a, It<T> b) { return a.p < b.p; }
679
loop_with_It(It<char> begin,It<char> end)680 void loop_with_It(It<char> begin, It<char> end) {
681 #pragma omp for
682 for (It<char> it = begin; it < end; ++it) {
683 *it = 0;
684 }
685 }
686
687 // CHECK-LABEL: loop_with_It
688 // CHECK: call i32 @__kmpc_global_thread_num(
689 // CHECK: call void @__kmpc_for_static_init_8(
690 // CHECK: call void @__kmpc_for_static_fini(
691
loop_with_It_plus(It<char> begin,It<char> end)692 void loop_with_It_plus(It<char> begin, It<char> end) {
693 #pragma omp for
694 for (It<char> it = begin; it < end; it+=1u) {
695 *it = 0;
696 }
697 }
698
699 // CHECK-LABEL: loop_with_It_plus
700 // CHECK: call i32 @__kmpc_global_thread_num(
701 // CHECK: call void @__kmpc_for_static_init_8(
702 // CHECK: call void @__kmpc_for_static_fini(
703
loop_with_stmt_expr()704 void loop_with_stmt_expr() {
705 #pragma omp for collapse(2)
706 for (int i = __extension__({float b = 0;b; }); i < __extension__({double c = 1;c; }); i += __extension__({char d = 1; d; }))
707 for (int j = i; j < 4 + i; j++)
708 ;
709 }
710 // CHECK-LABEL: loop_with_stmt_expr
711 // CHECK: call i32 @__kmpc_global_thread_num(
712 // CHECK: call void @__kmpc_for_static_init_8(
713 // CHECK: call void @__kmpc_for_static_fini(
714
715
716 // CHECK-LABEL: fint
717 // CHECK: call {{.*}}i32 {{.*}}ftemplate
718 // CHECK: ret i32
719
720 // CHECK: load i16, i16*
721 // CHECK: store i16 %
722 // CHECK: call void {{.+}}@__kmpc_fork_call(
723 // CHECK: call void @__kmpc_for_static_init_4(
724 template <typename T>
ftemplate()725 T ftemplate() {
726 short aa = 0;
727
728 #pragma omp parallel for schedule(static, aa)
729 for (int i = 0; i < 100; i++) {
730 }
731 return T();
732 }
733
fint(void)734 int fint(void) { return ftemplate<int>(); }
735
736 // Check for imperfectly loop nests codegen.
737 #if _OPENMP == 201811
738 void first();
739 void last();
740 void inner_f();
741 void inner_l();
742 void body_f();
743
744 // OMP5-LABEL: imperfectly_nested_loop
imperfectly_nested_loop()745 void imperfectly_nested_loop() {
746 // OMP5: call void @__kmpc_for_static_init_4(
747 #pragma omp for collapse(3) order(concurrent)
748 for (int i = 0; i < 10; ++i) {
749 {
750 int a, d;
751 // OMP5: invoke void @{{.+}}first{{.+}}()
752 first();
753 // OMP5: load i32{{.*}}!llvm.access.group ![[AG:[0-9]+]]
754 // OMP5: store i32{{.*}}!llvm.access.group ![[AG]]
755 a = d;
756 for (int j = 0; j < 10; ++j) {
757 int a, d;
758 // OMP5: invoke void @{{.+}}inner_f{{.+}}()
759 inner_f();
760 // OMP5: load i32{{.*}}!llvm.access.group ![[AG]]
761 // OMP5: store i32{{.*}}!llvm.access.group ![[AG]]
762 a = d;
763 for (int k = 0; k < 10; ++k) {
764 int a, d;
765 // OMP5: invoke void @{{.+}}body_f{{.+}}()
766 body_f();
767 // OMP5: load i32{{.*}}!llvm.access.group ![[AG]]
768 // OMP5: store i32{{.*}}!llvm.access.group ![[AG]]
769 a = d;
770 }
771 // OMP5: invoke void @{{.+}}inner_l{{.+}}()
772 inner_l();
773 }
774 // OMP5: invoke void @{{.+}}last{{.+}}()
775 last();
776 }
777 }
778 // OMP5: call void @__kmpc_for_static_fini(
779 }
780
781 // OMP5: ![[AG]] = distinct !{}
782 // OMP5: !{!"llvm.loop.parallel_accesses", ![[AG]]}
783
784 #endif
785
786 #endif // HEADER
787