[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / pragma-loop.cpp
blob127df41522a5743c117bfad08eb765887300885d
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
3 // Verify while loop is recognized after sequence of pragma clang loop directives.
4 void while_test(int *List, int Length) {
5 // CHECK: define {{.*}} @_Z10while_test
6 int i = 0;
8 #pragma clang loop vectorize(enable)
9 #pragma clang loop interleave_count(4)
10 #pragma clang loop vectorize_width(4)
11 #pragma clang loop unroll(full)
12 #pragma clang loop distribute(enable)
13 while (i < Length) {
14 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
15 List[i] = i * 2;
16 i++;
20 // Verify do loop is recognized after multi-option pragma clang loop directive.
21 void do_test(int *List, int Length) {
22 int i = 0;
24 #pragma clang loop vectorize_width(8) interleave_count(4) unroll(disable) distribute(disable)
25 do {
26 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
27 List[i] = i * 2;
28 i++;
29 } while (i < Length);
32 enum struct Tuner : short { Interleave = 4, Unroll = 8 };
34 // Verify for loop is recognized after sequence of pragma clang loop directives.
35 void for_test(int *List, int Length) {
36 #pragma clang loop interleave(enable)
37 #pragma clang loop interleave_count(static_cast<int>(Tuner::Interleave))
38 #pragma clang loop unroll_count(static_cast<int>(Tuner::Unroll))
39 for (int i = 0; i < Length; i++) {
40 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
41 List[i] = i * 2;
45 // Verify c++11 for range loop is recognized after
46 // sequence of pragma clang loop directives.
47 void for_range_test() {
48 double List[100];
50 #pragma clang loop vectorize_width(2) interleave_count(2)
51 for (int i : List) {
52 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
53 List[i] = i;
57 // Verify disable pragma clang loop directive generates correct metadata
58 void disable_test(int *List, int Length) {
59 #pragma clang loop vectorize(disable) unroll(disable) distribute(disable)
60 for (int i = 0; i < Length; i++) {
61 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_5:.*]]
62 List[i] = i * 2;
66 #define VECWIDTH 2
67 #define INTCOUNT 2
68 #define UNROLLCOUNT 8
70 // Verify defines are correctly resolved in pragma clang loop directive
71 void for_define_test(int *List, int Length, int Value) {
72 #pragma clang loop vectorize_width(VECWIDTH) interleave_count(INTCOUNT)
73 #pragma clang loop unroll_count(UNROLLCOUNT)
74 for (int i = 0; i < Length; i++) {
75 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_6:.*]]
76 List[i] = i * Value;
80 // Verify constant expressions are handled correctly.
81 void for_contant_expression_test(int *List, int Length) {
82 #pragma clang loop vectorize_width(1 + 4)
83 for (int i = 0; i < Length; i++) {
84 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_7:.*]]
85 List[i] = i;
88 #pragma clang loop vectorize_width(3 + VECWIDTH)
89 for (int i = 0; i < Length; i++) {
90 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_8:.*]]
91 List[i] += i;
95 // Verify metadata is generated when template is used.
96 template <typename A>
97 void for_template_test(A *List, int Length, A Value) {
98 #pragma clang loop vectorize_width(8) interleave_count(8) unroll_count(8)
99 for (int i = 0; i < Length; i++) {
100 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_9:.*]]
101 List[i] = i * Value;
105 // Verify define is resolved correctly when template is used.
106 template <typename A, typename T>
107 void for_template_define_test(A *List, int Length, A Value) {
108 const T VWidth = VECWIDTH;
109 const T ICount = INTCOUNT;
110 const T UCount = UNROLLCOUNT;
111 #pragma clang loop vectorize_width(VWidth) interleave_count(ICount)
112 #pragma clang loop unroll_count(UCount)
113 for (int i = 0; i < Length; i++) {
114 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_10:.*]]
115 List[i] = i * Value;
119 // Verify templates and constant expressions are handled correctly.
120 template <typename A, int V, int I, int U>
121 void for_template_constant_expression_test(A *List, int Length) {
122 #pragma clang loop vectorize_width(V) interleave_count(I) unroll_count(U)
123 for (int i = 0; i < Length; i++) {
124 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_11:.*]]
125 List[i] = i;
128 #pragma clang loop vectorize_width(V * 2 + VECWIDTH) interleave_count(I * 2 + INTCOUNT) unroll_count(U * 2 + UNROLLCOUNT)
129 for (int i = 0; i < Length; i++) {
130 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_12:.*]]
131 List[i] += i;
134 const int Scale = 4;
135 #pragma clang loop vectorize_width(Scale * V) interleave_count(Scale * I) unroll_count(Scale * U)
136 for (int i = 0; i < Length; i++) {
137 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_13:.*]]
138 List[i] += i;
141 #pragma clang loop vectorize_width((Scale * V) + 2)
142 for (int i = 0; i < Length; i++) {
143 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_14:.*]]
144 List[i] += i;
148 #undef VECWIDTH
149 #undef INTCOUNT
150 #undef UNROLLCOUNT
152 // Use templates defined above. Test verifies metadata is generated correctly.
153 void template_test(double *List, int Length) {
154 double Value = 10;
156 for_template_test<double>(List, Length, Value);
157 for_template_define_test<double, int>(List, Length, Value);
158 for_template_constant_expression_test<double, 2, 4, 8>(List, Length);
161 // Verify for loop is performing fixed width vectorization
162 void for_test_fixed_16(int *List, int Length) {
163 #pragma clang loop vectorize_width(16, fixed) interleave_count(4) unroll(disable) distribute(disable)
164 for (int i = 0; i < Length; i++) {
165 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_15:.*]]
166 List[i] = i * 2;
170 // Verify for loop is performing scalable vectorization
171 void for_test_scalable_16(int *List, int Length) {
172 #pragma clang loop vectorize_width(16, scalable) interleave_count(4) unroll(disable) distribute(disable)
173 for (int i = 0; i < Length; i++) {
174 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_16:.*]]
175 List[i] = i * 2;
179 // Verify for loop is performing fixed width vectorization
180 void for_test_fixed(int *List, int Length) {
181 #pragma clang loop vectorize_width(fixed) interleave_count(4) unroll(disable) distribute(disable)
182 for (int i = 0; i < Length; i++) {
183 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_17:.*]]
184 List[i] = i * 2;
188 // Verify for loop is performing scalable vectorization
189 void for_test_scalable(int *List, int Length) {
190 #pragma clang loop vectorize_width(scalable) interleave_count(4) unroll(disable) distribute(disable)
191 for (int i = 0; i < Length; i++) {
192 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_18:.*]]
193 List[i] = i * 2;
197 // Verify for loop is performing scalable vectorization
198 void for_test_scalable_1(int *List, int Length) {
199 #pragma clang loop vectorize_width(1, scalable) interleave_count(4) unroll(disable) distribute(disable)
200 for (int i = 0; i < Length; i++) {
201 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_19:.*]]
202 List[i] = i * 2;
206 // CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], [[MP:![0-9]+]], ![[UNROLL_FULL:.*]]}
207 // CHECK: ![[UNROLL_FULL]] = !{!"llvm.loop.unroll.full"}
209 // CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2]], [[MP]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[WIDTH_8:.*]], ![[FIXED_VEC:.*]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE:.*]]}
210 // CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
211 // CHECK: ![[DISTRIBUTE_DISABLE]] = !{!"llvm.loop.distribute.enable", i1 false}
212 // CHECK: ![[WIDTH_8]] = !{!"llvm.loop.vectorize.width", i32 8}
213 // CHECK: ![[FIXED_VEC]] = !{!"llvm.loop.vectorize.scalable.enable", i1 false}
214 // CHECK: ![[INTERLEAVE_4]] = !{!"llvm.loop.interleave.count", i32 4}
215 // CHECK: ![[VECTORIZE_ENABLE]] = !{!"llvm.loop.vectorize.enable", i1 true}
217 // CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], [[MP]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_3:.*]]}
218 // CHECK: ![[FOLLOWUP_VECTOR_3]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_3:.*]]}
219 // CHECK: ![[AFTER_VECTOR_3]] = distinct !{![[AFTER_VECTOR_3]], [[MP]], ![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
220 // CHECK: ![[ISVECTORIZED]] = !{!"llvm.loop.isvectorized"}
221 // CHECK: ![[UNROLL_8]] = !{!"llvm.loop.unroll.count", i32 8}
223 // CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[WIDTH_2:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_2:.*]], ![[VECTORIZE_ENABLE]]}
224 // CHECK: ![[WIDTH_2]] = !{!"llvm.loop.vectorize.width", i32 2}
225 // CHECK: ![[INTERLEAVE_2]] = !{!"llvm.loop.interleave.count", i32 2}
227 // CHECK: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[WIDTH_1:.*]]}
228 // CHECK: ![[WIDTH_1]] = !{!"llvm.loop.vectorize.width", i32 1}
230 // CHECK: ![[LOOP_6]] = distinct !{![[LOOP_6]], [[MP]], ![[WIDTH_2:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_2:.*]], ![[FOLLOWUP_VECTOR_6:.*]]}
231 // CHECK: ![[FOLLOWUP_VECTOR_6]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_6:.*]]}
232 // CHECK: ![[AFTER_VECTOR_6]] = distinct !{![[AFTER_VECTOR_6]], ![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
234 // CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], [[MP]], ![[WIDTH_5:.*]], ![[FIXED_VEC]], ![[VECTORIZE_ENABLE]]}
235 // CHECK: ![[WIDTH_5]] = !{!"llvm.loop.vectorize.width", i32 5}
237 // CHECK: ![[LOOP_8]] = distinct !{![[LOOP_8]], [[MP]], ![[WIDTH_5:.*]], ![[FIXED_VEC]], ![[VECTORIZE_ENABLE]]}
239 // CHECK: ![[LOOP_9]] = distinct !{![[LOOP_9]], ![[WIDTH_8:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_8:.*]], ![[FOLLOWUP_VECTOR_9:.*]]}
240 // CHECK: ![[FOLLOWUP_VECTOR_9]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_9:.*]]}
241 // CHECK: ![[AFTER_VECTOR_9]] = distinct !{![[AFTER_VECTOR_9]], ![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
243 // CHECK: ![[LOOP_10]] = distinct !{![[LOOP_10]], ![[WIDTH_2:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_2:.*]], ![[FOLLOWUP_VECTOR_10:.*]]}
244 // CHECK: ![[FOLLOWUP_VECTOR_10]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_10:.*]]}
245 // CHECK: ![[AFTER_VECTOR_10]] = distinct !{![[AFTER_VECTOR_10]], ![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
247 // CHECK: ![[LOOP_11]] = distinct !{![[LOOP_11]], ![[WIDTH_2:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_4:.*]], ![[FOLLOWUP_VECTOR_11:.*]]}
248 // CHECK: ![[FOLLOWUP_VECTOR_11]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_11:.*]]}
249 // CHECK: ![[AFTER_VECTOR_11]] = distinct !{![[AFTER_VECTOR_11]], ![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
251 // CHECK: ![[LOOP_12]] = distinct !{![[LOOP_12]], ![[WIDTH_6:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_10:.*]], ![[FOLLOWUP_VECTOR_12:.*]]}
252 // CHECK: ![[FOLLOWUP_VECTOR_12]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_12:.*]]}
253 // CHECK: ![[AFTER_VECTOR_12]] = distinct !{![[AFTER_VECTOR_12]], ![[ISVECTORIZED:.*]], ![[UNROLL_24:.*]]}
254 // CHECK: ![[UNROLL_24]] = !{!"llvm.loop.unroll.count", i32 24}
256 // CHECK: ![[LOOP_13]] = distinct !{![[LOOP_13]], ![[WIDTH_8:.*]], ![[INTERLEAVE_16:.*]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_13:.*]]}
257 // CHECK: ![[INTERLEAVE_16]] = !{!"llvm.loop.interleave.count", i32 16}
258 // CHECK: ![[FOLLOWUP_VECTOR_13]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_13:.*]]}
259 // CHECK: ![[AFTER_VECTOR_13]] = distinct !{![[AFTER_VECTOR_13]], ![[ISVECTORIZED:.*]], ![[UNROLL_32:.*]]}
260 // CHECK: ![[UNROLL_32]] = !{!"llvm.loop.unroll.count", i32 32}
262 // CHECK: ![[LOOP_14]] = distinct !{![[LOOP_14]], [[MP]], ![[WIDTH_10:.*]], ![[FIXED_VEC]], ![[VECTORIZE_ENABLE]]}
263 // CHECK: ![[WIDTH_10]] = !{!"llvm.loop.vectorize.width", i32 10}
265 // CHECK: ![[LOOP_15]] = distinct !{![[LOOP_15]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[WIDTH_16:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE:.*]]}
266 // CHECK: ![[WIDTH_16]] = !{!"llvm.loop.vectorize.width", i32 16}
268 // CHECK: ![[LOOP_16]] = distinct !{![[LOOP_16]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[WIDTH_16]], ![[SCALABLE_VEC:.*]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE:.*]]}
269 // CHECK: ![[SCALABLE_VEC]] = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
271 // CHECK: ![[LOOP_17]] = distinct !{![[LOOP_17]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[FIXED_VEC]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE:.*]]}
272 // CHECK: ![[LOOP_18]] = distinct !{![[LOOP_18]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[SCALABLE_VEC]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE:.*]]}
273 // CHECK: ![[LOOP_19]] = distinct !{![[LOOP_19]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[WIDTH_1]], ![[SCALABLE_VEC]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE:.*]]}