Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_depend_codegen.cpp
blob22bf654691de616eddb14e9bdc155a8ecf391a26
1 // Test host codegen.
2 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
4 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
5 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
9 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
11 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
12 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
13 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
14 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
15 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
17 // Test target codegen - host bc file has to be created first.
18 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc
19 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-64
20 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o %t %s
21 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-64
22 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm-bc %s -o %t-x86-host.bc
23 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-32
24 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o %t %s
25 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix TCHECK --check-prefix TCHECK-32
27 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc
28 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck --check-prefix SIMD-ONLY1 %s
29 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o %t %s
30 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
31 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm-bc %s -o %t-x86-host.bc
32 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck --check-prefix SIMD-ONLY1 %s
33 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -o %t %s
34 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
35 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
37 // expected-no-diagnostics
38 #ifndef HEADER
39 #define HEADER
41 // CHECK-DAG: [[TT:%.+]] = type { i64, i8 }
42 // CHECK-DAG: [[ENTTY:%.+]] = type { ptr, ptr, i[[SZ:32|64]], i32, i32 }
44 // TCHECK: [[ENTTY:%.+]] = type { ptr, ptr, i{{32|64}}, i32, i32 }
46 // CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [2 x i64] [i64 0, i64 4]
47 // CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 544, i64 800]
48 // CHECK-DAG: @{{.*}} = weak constant i8 0
50 // TCHECK: @{{.+}} = weak constant [[ENTTY]]
51 // TCHECK: @{{.+}} = {{.*}}constant [[ENTTY]]
52 // TCHECK-NOT: @{{.+}} = weak constant [[ENTTY]]
54 // Check target registration is registered as a Ctor.
55 // CHECK: appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @.omp_offloading.requires_reg, ptr null }]
58 template<typename tx, typename ty>
59 struct TT{
60 tx X;
61 ty Y;
64 int global;
65 extern int global;
67 // CHECK: define {{.*}}[[FOO:@.+]](
68 int foo(int n) {
69 int a = 0;
70 short aa = 0;
71 float b[10];
72 float bn[n];
73 double c[5][10];
74 double cn[5][n];
75 TT<long long, char> d;
76 static long *plocal;
78 // CHECK: [[ADD:%.+]] = add nsw i32
79 // CHECK: store i32 [[ADD]], ptr [[DEVICE_CAP:%.+]],
80 // CHECK: [[GEP:%.+]] = getelementptr inbounds %{{.+}}, ptr %{{.+}}, i32 0, i32 0
81 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],
82 // CHECK: store i32 [[DEV]], ptr [[GEP]],
83 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 [[GTID:%.+]], i32 1, i[[SZ]] {{20|40}}, i[[SZ]] 4, ptr [[TASK_ENTRY0:@.+]])
84 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 0
85 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 1
86 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 2
87 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 3
88 // CHECK: call void @__kmpc_omp_taskwait_deps_51(ptr @1, i32 [[GTID]], i32 4, ptr %{{.+}}, i32 0, ptr null, i32 0)
89 // CHECK: call void @__kmpc_omp_task_begin_if0(ptr @1, i32 [[GTID]], ptr [[TASK]])
90 // CHECK: call i32 [[TASK_ENTRY0]](i32 [[GTID]], ptr [[TASK]])
91 // CHECK: call void @__kmpc_omp_task_complete_if0(ptr @1, i32 [[GTID]], ptr [[TASK]])
92 #pragma omp target parallel device(global + a) depend(in \
93 : global) depend(out \
94 : a, b, cn[4])
98 // CHECK: [[ADD:%.+]] = add nsw i32
99 // CHECK: store i32 [[ADD]], ptr [[DEVICE_CAP:%.+]],
101 // CHECK: [[BOOL:%.+]] = icmp ne i32 %{{.+}}, 0
102 // CHECK: br i1 [[BOOL]], label %[[THEN:.+]], label %[[ELSE:.+]]
103 // CHECK: [[THEN]]:
104 // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [2 x ptr], ptr [[BP:%.+]], i32 0, i32 0
105 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [2 x ptr], ptr [[P:%.+]], i32 0, i32 0
106 // CHECK-DAG: store ptr [[BP0:%[^,]+]], ptr [[BPADDR0]]
107 // CHECK-DAG: store ptr [[BP0]], ptr [[PADDR0]]
109 // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [2 x ptr], ptr [[BP]], i32 0, i32 1
110 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [2 x ptr], ptr [[P]], i32 0, i32 1
111 // CHECK-DAG: store i[[SZ]] [[BP1:%[^,]+]], ptr [[BPADDR1]]
112 // CHECK-DAG: store i[[SZ]] [[BP1]], ptr [[PADDR1]]
113 // CHECK-DAG: getelementptr inbounds [2 x ptr], ptr [[BP]], i32 0, i32 0
114 // CHECK-DAG: getelementptr inbounds [2 x ptr], ptr [[P]], i32 0, i32 0
115 // CHECK: [[GEP:%.+]] = getelementptr inbounds %{{.+}}, ptr %{{.+}}, i32 0, i32 2
116 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],
117 // CHECK: store i32 [[DEV]], ptr [[GEP]],
118 // CHECK: [[DEV1:%.+]] = load i32, ptr [[DEVICE_CAP]],
119 // CHECK: [[DEV2:%.+]] = sext i32 [[DEV1]] to i64
121 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_target_task_alloc(ptr @{{.*}}, i32 [[GTID]], i32 1, i[[SZ]] {{104|60}}, i[[SZ]] {{16|12}}, ptr [[TASK_ENTRY1_:@.+]], i64 [[DEV2]])
122 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 0
123 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 1
124 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 2
125 // CHECK: call i32 @__kmpc_omp_task_with_deps(ptr @1, i32 [[GTID]], ptr [[TASK]], i32 3, ptr %{{.+}}, i32 0, ptr null)
126 // CHECK: br label %[[EXIT:.+]]
128 // CHECK: [[ELSE]]:
129 // CHECK-NOT: getelementptr inbounds [2 x ptr], ptr
130 // CHECK: [[GEP:%.+]] = getelementptr inbounds %{{.+}}, ptr %{{.+}}, i32 0, i32 2
131 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],
132 // CHECK: store i32 [[DEV]], ptr [[GEP]],
133 // CHECK: [[DEV1:%.+]] = load i32, ptr [[DEVICE_CAP]],
134 // CHECK: [[DEV2:%.+]] = sext i32 [[DEV1]] to i64
136 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_target_task_alloc(ptr @1, i32 [[GTID]], i32 1, i[[SZ]] {{56|28}}, i[[SZ]] {{16|12}}, ptr [[TASK_ENTRY1__:@.+]], i64 [[DEV2]])
137 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 0
138 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 1
139 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 2
140 // CHECK: call i32 @__kmpc_omp_task_with_deps(ptr @1, i32 [[GTID]], ptr [[TASK]], i32 3, ptr %{{.+}}, i32 0, ptr null)
141 // CHECK: br label %[[EXIT:.+]]
142 // CHECK: [[EXIT]]:
144 #pragma omp target parallel device(global + a) nowait depend(inout \
145 : global, a, bn) if (target \
146 : a)
148 static int local1;
149 *plocal = global;
150 local1 = global;
153 // CHECK: [[TASK:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 [[GTID]], i32 1, i[[SZ]] {{48|24}}, i[[SZ]] 4, ptr [[TASK_ENTRY2:@.+]])
154 // CHECK: getelementptr %struct.kmp_depend_info, ptr %{{.+}}, i[[SZ]] 0
155 // CHECK: call void @__kmpc_omp_taskwait_deps_51(ptr @1, i32 [[GTID]], i32 1, ptr %{{.+}}, i32 0, ptr null, i32 0)
156 // CHECK: call void @__kmpc_omp_task_begin_if0(ptr @1, i32 [[GTID]], ptr [[TASK]])
157 // CHECK: call i32 [[TASK_ENTRY2]](i32 [[GTID]], ptr [[TASK]])
158 // CHECK: call void @__kmpc_omp_task_complete_if0(ptr @1, i32 [[GTID]], ptr [[TASK]])
159 #pragma omp target parallel if (0) firstprivate(global) depend(out \
160 : global)
162 global += 1;
165 return a;
168 // Check that the offloading functions are emitted and that the arguments are
169 // correct and loaded correctly for the target regions in foo().
171 // CHECK: define internal void [[HVT0:@.+]]()
173 // CHECK: define internal{{.*}} i32 [[TASK_ENTRY0]](i32{{.*}}, ptr noalias noundef %1)
174 // CHECK: store ptr null, ptr %
175 // CHECK: [[DEVICE_CAP:%.+]] = load ptr,
176 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],
177 // CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64
178 // CHECK: [[RET:%.+]] = call i32 @__tgt_target_kernel(ptr @{{.+}}, i64 [[DEVICE]], i32 1, i32 0, ptr @.{{.+}}.region_id, ptr %{{.+}})
179 // CHECK-NEXT: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
180 // CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
181 // CHECK: [[FAIL]]
182 // CHECK: call void [[HVT0]]()
183 // CHECK-NEXT: br label %[[END]]
184 // CHECK: [[END]]
185 // CHECK: ret i32 0
187 // CHECK: define internal void [[HVT1:@.+]](ptr noundef %{{.+}}, i[[SZ]] noundef %{{.+}})
189 // CHECK: define internal{{.*}} i32 [[TASK_ENTRY1_]](i32{{.*}}, ptr noalias noundef %1)
190 // CHECK: call void {{%.*}}(
191 // CHECK: [[DEVICE_CAP:%.+]] = getelementptr inbounds %{{.+}}, ptr %{{.+}}, i32 0, i32 2
192 // CHECK: [[DEV:%.+]] = load i32, ptr [[DEVICE_CAP]],
193 // CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64
194 // CHECK: [[RET:%.+]] = call i32 @__tgt_target_kernel(ptr @{{.+}}, i64 [[DEVICE]], i32 1, i32 0, ptr @.{{.+}}.region_id, ptr %{{.+}})
196 // CHECK: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
197 // CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
198 // CHECK: [[FAIL]]
199 // CHECK: [[BP0:%.+]] = load ptr, ptr %
200 // CHECK: [[BP1_I32:%.+]] = load i32, ptr @
201 // CHECK-64: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],
202 // CHECK-32: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],
203 // CHECK: [[BP1:%.+]] = load i[[SZ]], ptr [[BP1_PTR]],
204 // CHECK: call void [[HVT1]](ptr [[BP0]], i[[SZ]] [[BP1]])
205 // CHECK-NEXT: br label %[[END]]
206 // CHECK: [[END]]
207 // CHECK: ret i32 0
209 // CHECK: define internal{{.*}} i32 [[TASK_ENTRY1__]](i32{{.*}}, ptr noalias noundef %1)
210 // CHECK: call void {{%.*}}(
211 // CHECK: [[DEVICE_CAP:%.+]] = getelementptr inbounds %{{.+}}, ptr %{{.+}}, i32 0, i32 2
212 // CHECK: [[BP0:%.+]] = load ptr, ptr %
213 // CHECK: [[BP1_I32:%.+]] = load i32, ptr @
214 // CHECK-64: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],
215 // CHECK-32: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],
216 // CHECK: [[BP1:%.+]] = load i[[SZ]], ptr [[BP1_PTR]],
217 // CHECK: call void [[HVT1]](ptr [[BP0]], i[[SZ]] [[BP1]])
218 // CHECK: ret i32 0
220 // CHECK: define internal void [[HVT2:@.+]](i[[SZ]] noundef %{{.+}})
221 // Create stack storage and store argument in there.
222 // CHECK: [[AA_ADDR:%.+]] = alloca i[[SZ]], align
223 // CHECK: store i[[SZ]] %{{.+}}, ptr [[AA_ADDR]], align
224 // CHECK-64: load i32, ptr [[AA_ADDR]], align
225 // CHECK-32: load i32, ptr [[AA_ADDR]], align
227 // CHECK: define internal{{.*}} i32 [[TASK_ENTRY2]](i32{{.*}}, ptr noalias noundef %1)
228 // CHECK: call void {{%.*}}(
229 // CHECK: [[BP1_I32:%.+]] = load i32, ptr %
230 // CHECK-64: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],
231 // CHECK-32: store i32 [[BP1_I32]], ptr [[BP1_PTR:%[^,]+]],
232 // CHECK: [[BP1:%.+]] = load i[[SZ]], ptr [[BP1_PTR]],
233 // CHECK: call void [[HVT2]](i[[SZ]] [[BP1]])
234 // CHECK: ret i32 0
236 // CHECK: define internal void @.omp_offloading.requires_reg()
237 // CHECK: call void @__tgt_register_requires(i64 1)
238 // CHECK: ret void
240 #endif