1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
5 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
10 // expected-no-diagnostics
20 // CHECK: store i32 0, ptr [[A_ADDR:%.+]],
21 // CHECK: store i32 0, ptr [[OMP_CNT:%.+]],
22 // CHECK: br label %[[OMP_HEADER:.+]]
24 // CHECK: [[OMP_HEADER]]:
25 // CHECK: [[CNT_VAL:%.+]] = load i32, ptr [[OMP_CNT]],
26 // CHECK: [[CMP:%.+]] = icmp slt i32 [[CNT_VAL]], 10
27 // CHECK: br i1 [[CMP]], label %[[OMP_BODY:.+]], label %[[OMP_END:.+]]
28 #pragma omp simd reduction(inscan, + : a)
29 for (int i
= 0; i
< 10; ++i
) {
30 // CHECK: [[OMP_BODY]]:
33 // CHECK: [[CNT_VAL:%.+]] = load i32, ptr [[OMP_CNT]],
34 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT_VAL]], 1
35 // CHECK: [[ADD:%.+]] = add nsw i32 0, [[MUL]]
36 // CHECK: store i32 [[ADD]], ptr [[I_ADDR:%.+]],
39 // CHECK: store i32 0, ptr [[A_PRIV_ADDR:%.+]],
42 // CHECK: br label %[[DISPATCH:[^,]+]]
47 // CHECK: [[INPUT_PHASE:.+]]:
48 // CHECK: call void @{{.*}}foo{{.*}}()
49 // CHECK: br label %[[REDUCE:[^,]+]]
54 // CHECK: [[DISPATCH]]:
55 // CHECK: br label %[[INPUT_PHASE]]
62 // CHECK: [[A:%.+]] = load i32, ptr [[A_ADDR]],
63 // CHECK: [[A_PRIV:%.+]] = load i32, ptr [[A_PRIV_ADDR]],
64 // CHECK: [[SUM:%.+]] = add nsw i32 [[A]], [[A_PRIV]]
65 // CHECK: store i32 [[SUM]], ptr [[A_ADDR]],
66 // CHECK: [[A:%.+]] = load i32, ptr [[A_ADDR]],
67 // CHECK: store i32 [[A]], ptr [[A_PRIV_ADDR]],
68 // CHECK: br label %[[SCAN_PHASE:[^,]+]]
69 #pragma omp scan inclusive(a)
74 // CHECK: [[SCAN_PHASE]]:
75 // CHECK: call void @{{.*}}bar{{.*}}()
76 // CHECK: br label %[[CONTINUE:[^,]+]]
79 // CHECK: [[CONTINUE]]:
80 // CHECK: br label %[[INC_BLOCK:[^,]+]]
83 // CHECK: [[INC_BLOCK]]:
84 // CHECK: [[CNT:%.+]] = load i32, ptr [[OMP_CNT]],
85 // CHECK: [[INC:%.+]] = add nsw i32 [[CNT]], 1
86 // CHECK: store i32 [[INC]], ptr [[OMP_CNT]],
87 // CHECK: br label %[[OMP_HEADER]]
89 // CHECK: [[OMP_END]]:
96 S
& operator+(const S
&);
97 S
& operator=(const S
&);
104 // CHECK: [[S_BEGIN:%.+]] = getelementptr inbounds [2 x %struct.S], ptr [[S_ADDR:%.+]], i{{.+}} 0, i{{.+}} 0
105 // CHECK: [[S_END:%.+]] = getelementptr {{.*}}%struct.S, ptr [[S_BEGIN]], i{{.+}} 2
106 // CHECK: br label %[[ARRAY_INIT:.+]]
107 // CHECK: [[ARRAY_INIT]]:
108 // CHECK: [[S_CUR:%.+]] = phi ptr [ [[S_BEGIN]], %{{.+}} ], [ [[S_NEXT:%.+]], %[[ARRAY_INIT]] ]
109 // CHECK: call void [[CONSTR:@.+]](ptr {{[^,]*}} [[S_CUR]])
110 // CHECK: [[S_NEXT]] = getelementptr inbounds %struct.S, ptr [[S_CUR]], i{{.+}} 1
111 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[S_NEXT]], [[S_END]]
112 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[ARRAY_INIT]]
114 // CHECK: store i32 0, ptr [[OMP_CNT:%.+]],
115 // CHECK: br label %[[OMP_HEADER:.+]]
117 // CHECK: [[OMP_HEADER]]:
118 // CHECK: [[CNT_VAL:%.+]] = load i32, ptr [[OMP_CNT]],
119 // CHECK: [[CMP:%.+]] = icmp slt i32 [[CNT_VAL]], 10
120 // CHECK: br i1 [[CMP]], label %[[OMP_BODY:.+]], label %[[OMP_END:.+]]
121 #pragma omp simd reduction(inscan, + : s)
122 for (int i
= 0; i
< 10; ++i
) {
123 // CHECK: [[OMP_BODY]]:
125 // i = OMP_CNT*1 + 0;
126 // CHECK: [[CNT_VAL:%.+]] = load i32, ptr [[OMP_CNT]],
127 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT_VAL]], 1
128 // CHECK: [[ADD:%.+]] = add nsw i32 0, [[MUL]]
129 // CHECK: store i32 [[ADD]], ptr [[I_ADDR:%.+]],
132 // CHECK: [[S_BEGIN:%.+]] = getelementptr inbounds [2 x %struct.S], ptr [[S_PRIV_ADDR:%.+]], i{{.+}} 0, i{{.+}} 0
133 // CHECK: [[S_END:%.+]] = getelementptr {{.*}}%struct.S, ptr [[S_BEGIN]], i{{.+}} 2
134 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[S_BEGIN]], [[S_END]]
135 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[ARRAY_INIT:[^,]+]]
136 // CHECK: [[ARRAY_INIT]]:
137 // CHECK: [[S_CUR:%.+]] = phi ptr [ [[S_BEGIN]], %[[OMP_BODY]] ], [ [[S_NEXT:%.+]], %[[ARRAY_INIT]] ]
138 // CHECK: call void [[CONSTR]](ptr {{[^,]*}} [[S_CUR]])
139 // CHECK: [[S_NEXT]] = getelementptr {{.*}}%struct.S, ptr [[S_CUR]], i{{.+}} 1
140 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[S_NEXT]], [[S_END]]
141 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[ARRAY_INIT]]
145 // CHECK: br label %[[DISPATCH:[^,]+]]
150 // CHECK: [[SCAN_PHASE:.+]]:
151 // CHECK: call void @{{.*}}foo{{.*}}()
152 // CHECK: br label %[[CONTINUE:[^,]+]]
157 // CHECK: [[DISPATCH]]:
158 // CHECK: br label %[[INPUT_PHASE:[^,]+]]
165 // CHECK: [[REDUCE:.+]]:
168 // CHECK: [[TEMP_ARR_BEG:%.+]] = getelementptr inbounds [2 x %struct.S], ptr [[TEMP_ARR:%.+]], i32 0, i32 0
169 // CHECK: [[TEMP_ARR_END:%.+]] = getelementptr inbounds %struct.S, ptr [[TEMP_ARR_BEG]], i64 2
170 // CHECK: br label %[[BODY:[^,]+]]
172 // CHECK: [[CUR:%.+]] = phi ptr [ [[TEMP_ARR_BEG]], %[[REDUCE]] ], [ [[NEXT:%.+]], %[[BODY]] ]
173 // CHECK: call void [[CONSTR]](ptr {{[^,]*}} [[CUR]])
174 // CHECK: [[NEXT]] = getelementptr inbounds %struct.S, ptr [[CUR]], i64 1
175 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[NEXT]], [[TEMP_ARR_END]]
176 // CHECK: br i1 [[IS_DONE]], label %[[EXIT:[^,]+]], label %[[BODY]]
180 // CHECK: [[TEMP_ARR_BEG:%.+]] = getelementptr inbounds [2 x %struct.S], ptr [[TEMP_ARR]], i32 0, i32 0
181 // CHECK: [[TEMP_ARR_END:%.+]] = getelementptr inbounds %struct.S, ptr [[TEMP_ARR_BEG]], i64 2
182 // CHECK: [[IS_EMPTY:%.+]] = icmp eq ptr [[TEMP_ARR_BEG]], [[TEMP_ARR_END]]
183 // CHECK: br i1 [[IS_EMPTY]], label %[[EXIT:[^,]+]], label %[[BODY:[^,]+]]
185 // CHECK: [[CUR_SRC:%.+]] = phi ptr [ [[S_ADDR]], %{{.+}} ], [ [[SRC_NEXT:%.+]], %[[BODY]] ]
186 // CHECK: [[CUR_DEST:%.+]] = phi ptr [ [[TEMP_ARR_BEG]], %{{.+}} ], [ [[DEST_NEXT:%.+]], %[[BODY]] ]
187 // CHECK: call {{.*}}ptr [[S_COPY:@.+]](ptr {{[^,]*}} [[CUR_DEST]], ptr {{.*}}[[CUR_SRC]])
188 // CHECK: [[DEST_NEXT:%.+]] = getelementptr %struct.S, ptr [[CUR_DEST]], i32 1
189 // CHECK: [[SRC_NEXT:%.+]] = getelementptr %struct.S, ptr [[CUR_SRC]], i32 1
190 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[DEST_NEXT]], [[TEMP_ARR_END]]
191 // CHECK: br i1 [[IS_DONE]], label %[[EXIT]], label %[[BODY]]
195 // CHECK: [[LHS_END:%.+]] = getelementptr {{.*}}%struct.S, ptr [[S_ADDR]], i{{.+}} 2
196 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[S_ADDR]], [[LHS_END]]
197 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[ARRAY_REDUCE_COPY:[^,]+]]
198 // CHECK: [[ARRAY_REDUCE_COPY]]:
199 // CHECK: [[SRC_CUR:%.+]] = phi ptr [ [[S_PRIV_ADDR]], %[[EXIT]] ], [ [[SRC_NEXT:%.+]], %[[ARRAY_REDUCE_COPY]] ]
200 // CHECK: [[DEST_CUR:%.+]] = phi ptr [ [[S_ADDR]], %[[EXIT]] ], [ [[DEST_NEXT:%.+]], %[[ARRAY_REDUCE_COPY]] ]
201 // CHECK: [[SUM:%.+]] = call {{.*}}ptr @{{.+}}(ptr {{[^,]*}} [[DEST_CUR]], ptr {{.*}}[[SRC_CUR]])
202 // CHECK: call {{.*}}ptr [[S_COPY]](ptr {{[^,]*}} [[DEST_CUR]], ptr {{.*}}[[SUM]])
203 // CHECK: [[DEST_NEXT]] = getelementptr {{.*}}%struct.S, ptr [[DEST_CUR]], i{{.+}} 1
204 // CHECK: [[SRC_NEXT]] = getelementptr {{.*}}%struct.S, ptr [[SRC_CUR]], i{{.+}} 1
205 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[DEST_NEXT]], [[LHS_END]]
206 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[ARRAY_REDUCE_COPY]]
210 // CHECK: [[RHS_END:%.+]] = getelementptr inbounds %struct.S, ptr [[S_PRIV_ADDR]], i64 2
211 // CHECK: [[IS_EMPTY:%.+]] = icmp eq ptr [[S_PRIV_ADDR]], [[RHS_END]]
212 // CHECK: br i1 [[IS_EMPTY]], label %[[EXIT:[^,]+]], label %[[BODY:[^,]+]]
214 // CHECK: [[CUR_SRC:%.+]] = phi ptr [ [[TEMP_ARR]], %[[DONE]] ], [ [[SRC_NEXT:%.+]], %[[BODY]] ]
215 // CHECK: [[CUR_DEST:%.+]] = phi ptr [ [[S_PRIV_ADDR]], %[[DONE]] ], [ [[DEST_NEXT:%.+]], %[[BODY]] ]
216 // CHECK: call {{.*}}ptr [[S_COPY]](ptr {{[^,]*}} [[CUR_DEST]], ptr {{.*}}[[CUR_SRC]])
217 // CHECK: [[DEST_NEXT]] = getelementptr %struct.S, ptr [[CUR_DEST]], i32 1
218 // CHECK: [[SRC_NEXT]] = getelementptr %struct.S, ptr [[CUR_SRC]], i32 1
219 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[DEST_NEXT]], [[RHS_END]]
220 // CHECK: br i1 [[IS_DONE]], label %[[DONE:[^,]+]], label %[[BODY]]
224 // CHECK: [[TEMP_ARR_BEG:%.+]] = getelementptr inbounds [2 x %struct.S], ptr [[TEMP_ARR]], i32 0, i32 0
225 // CHECK: [[TEMP_ARR_END:%.+]] = getelementptr inbounds %struct.S, ptr [[TEMP_ARR_BEG]], i64 2
226 // CHECK: br label %[[BODY:[^,]+]]
228 // CHECK: [[CUR:%.+]] = phi ptr [ [[TEMP_ARR_END]], %[[DONE]] ], [ [[PREV:%.+]], %[[BODY]] ]
229 // CHECK: [[PREV]] = getelementptr inbounds %struct.S, ptr [[CUR]], i64 -1
230 // CHECK: call void [[DESTR:@.+]](ptr {{[^,]*}} [[PREV]])
231 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[PREV]], [[TEMP_ARR_BEG]]
232 // CHECK: br i1 [[IS_DONE]], label %[[EXIT:[^,]+]], label %[[BODY]]
236 // CHECK: br label %[[SCAN_PHASE]]
237 #pragma omp scan exclusive(s)
242 // CHECK: [[INPUT_PHASE]]:
243 // CHECK: call void @{{.*}}bar{{.*}}()
244 // CHECK: br label %[[REDUCE]]
247 // CHECK: [[CONTINUE]]:
250 // CHECK: [[S_BEGIN:%.+]] = getelementptr inbounds [2 x %struct.S], ptr [[S_PRIV_ADDR]], i{{.+}} 0, i{{.+}} 0
251 // CHECK: [[S_END:%.+]] = getelementptr {{.*}}%struct.S, ptr [[S_BEGIN]], i{{.+}} 2
252 // CHECK: br label %[[ARRAY_DESTR:[^,]+]]
253 // CHECK: [[ARRAY_DESTR]]:
254 // CHECK: [[S_CUR:%.+]] = phi ptr [ [[S_END]], %[[CONTINUE]] ], [ [[S_PREV:%.+]], %[[ARRAY_DESTR]] ]
255 // CHECK: [[S_PREV]] = getelementptr {{.*}}%struct.S, ptr [[S_CUR]], i{{.+}} -1
256 // CHECK: call void [[DESTR]](ptr {{[^,]*}} [[S_PREV]])
257 // CHECK: [[IS_DONE:%.+]] = icmp eq ptr [[S_PREV]], [[S_BEGIN]]
258 // CHECK: br i1 [[IS_DONE]], label %[[DONE:.+]], label %[[ARRAY_DESTR]]
260 // CHECK: br label %[[INC_BLOCK:[^,]+]]
263 // CHECK: [[INC_BLOCK]]:
264 // CHECK: [[CNT:%.+]] = load i32, ptr [[OMP_CNT]],
265 // CHECK: [[INC:%.+]] = add nsw i32 [[CNT]], 1
266 // CHECK: store i32 [[INC]], ptr [[OMP_CNT]],
267 // CHECK: br label %[[OMP_HEADER]]
269 // CHECK: [[OMP_END]]:
272 // CHECK-NOT: !{!"llvm.loop.parallel_accesses"