Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / loops_explicit_clauses_codegen.cpp
blobc23fcd66eb224e3ec34735950336c68b402578d1
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++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -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++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
12 #ifndef HEADER
13 #define HEADER
15 #define N 10
16 int foo();
17 int bar();
18 int k;
19 // CHECK-LABEL: @main
20 int main(int argc, char **argv) {
21 foo();
22 // CHECK: @{{.+}}foo
23 // CHECK: call void @__kmpc_for_static_init_4(
24 // CHECK-NOT: @k
25 // CHECK: call void @__kmpc_for_static_fini(
26 // CHECK-NOT: @k
27 #pragma omp for private(k)
28 for (k = 0; k < argc; k++)
30 foo();
31 // CHECK: @{{.+}}foo
32 // CHECK: call void @__kmpc_for_static_init_8(
33 // CHECK-NOT: @k
34 // CHECK: call void @__kmpc_for_static_fini(
35 // CHECK: store i32 %{{.+}}, ptr @k
36 #pragma omp for lastprivate(k) collapse(2)
37 for (int i = 0; i < 2; ++i)
38 for (k = 0; k < argc; k++)
40 foo();
41 // CHECK: @{{.+}}foo
42 // CHECK-NOT: @k{{.+}}!llvm.access.group
43 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
44 // CHECK-NOT: @k{{.+}}!llvm.access.group
45 // CHECK: sdiv i32
46 // CHECK: store i32 %{{.+}}, ptr @k,
47 #pragma omp simd linear(k : 2)
48 for (k = 0; k < argc; k++)
49 bar();
50 // CHECK: @{{.+}}foo
51 // CHECK-NOT: @k{{.+}}!llvm.access.group
52 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
53 // CHECK-NOT: @k{{.+}}!llvm.access.group
54 // CHECK: sdiv i32
55 // CHECK: store i32 %{{.+}}, ptr @k,
56 foo();
57 #pragma omp simd lastprivate(k) collapse(2)
58 for (int i = 0; i < 2; ++i)
59 for (k = 0; k < argc; k++)
60 bar() ;
61 foo();
62 // CHECK: @{{.+}}foo
63 // CHECK-NOT: @k{{.+}}!llvm.access.group
64 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
65 // CHECK-NOT: @k{{.+}}!llvm.access.group
66 // CHECK: sdiv i32
67 // CHECK: store i32 %{{.+}}, ptr @k,
68 #pragma omp simd
69 for (k = 0; k < argc; k++)
70 bar();
71 foo();
72 // CHECK: @{{.+}}foo
73 // CHECK-NOT: @k{{.+}}!llvm.access.group
74 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
75 // CHECK-NOT: @k{{.+}}!llvm.access.group
76 // CHECK: sdiv i32
77 // CHECK: store i32 %{{.+}}, ptr @k,
78 #pragma omp simd collapse(2)
79 for (int i = 0; i < 2; ++i)
80 for (k = 0; k < argc; k++)
81 bar();
82 // CHECK: @{{.+}}foo
83 foo();
84 return 0;
87 struct S {
88 int k;
89 S(int argc) {
90 foo();
91 // CHECK: @{{.+}}foo
92 // CHECK: call void @__kmpc_for_static_init_4(
93 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
94 // CHECK: call void @__kmpc_for_static_fini(
95 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
96 #pragma omp for private(k)
97 for (k = 0; k < argc; k++)
99 foo();
100 // CHECK: @{{.+}}foo
101 // CHECK: call void @__kmpc_for_static_init_8(
102 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
103 // CHECK: call void @__kmpc_for_static_fini(
104 #pragma omp for lastprivate(k) collapse(2)
105 for (int i = 0; i < 2; ++i)
106 for (k = 0; k < argc; k++)
108 foo();
109 // CHECK: @{{.+}}foo
110 // CHECK: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
111 // CHECK: br i1
112 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
113 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
114 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
115 // CHECK: add nsw i32 %{{.+}}, 1
116 // CHECK: br label {{.+}}, !llvm.loop
117 // CHECK: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
118 #pragma omp simd linear(k : 2)
119 for (k = 0; k < argc; k++)
120 bar();
121 foo();
122 // CHECK: @{{.+}}foo
123 // CHECK: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
124 // CHECK: br i1
125 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
126 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
127 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
128 // CHECK: add nsw i64 %{{.+}}, 1
129 // CHECK: br label {{.+}}, !llvm.loop
130 // CHECK: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
131 #pragma omp simd lastprivate(k) collapse(2)
132 for (int i = 0; i < 2; ++i)
133 for (k = 0; k < argc; k++)
134 bar();
135 foo();
136 // CHECK: @{{.+}}foo
137 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
138 // CHECK: br i1
139 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
140 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
141 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
142 // CHECK: add nsw i32 %{{.+}}, 1
143 // CHECK: br label {{.+}}, !llvm.loop
144 // CHECK: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
145 #pragma omp simd
146 for (k = 0; k < argc; k++)
147 bar();
148 foo();
149 // CHECK: @{{.+}}foo
150 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
151 // CHECK: br i1
152 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
153 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.access.group
154 // CHECK-NOT: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
155 // CHECK: add nsw i64 %{{.+}}, 1
156 // CHECK: br label {{.+}}, !llvm.loop
157 // CHECK: getelementptr inbounds %struct.S, ptr %{{.+}}, i32 0, i32 0
158 #pragma omp simd collapse(2)
159 for (int i = 0; i < 2; ++i)
160 for (k = 0; k < argc; k++)
161 bar();
162 // CHECK: @{{.+}}foo
163 foo();
165 } s(N);
167 #endif // HEADER