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