blob: dd40c1d72600eaf2a1aad6b0fef4fa40bdcefd8e [file] [log] [blame]
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
2
3// Verify while loop is recognized after sequence of pragma clang loop directives.
4void while_test(int *List, int Length) {
5 // CHECK: define {{.*}} @_Z10while_test
6 int i = 0;
7
8#pragma clang loop vectorize(enable)
9#pragma clang loop interleave_count(4)
10#pragma clang loop vectorize_width(4)
Stephen Hines176edba2014-12-01 14:53:08 -080011#pragma clang loop unroll(full)
Stephen Hinesc568f1e2014-07-21 00:47:37 -070012 while (i < Length) {
13 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
14 List[i] = i * 2;
15 i++;
16 }
17}
18
19// Verify do loop is recognized after multi-option pragma clang loop directive.
20void do_test(int *List, int Length) {
21 int i = 0;
22
23#pragma clang loop vectorize_width(8) interleave_count(4) unroll(disable)
24 do {
25 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
26 List[i] = i * 2;
27 i++;
28 } while (i < Length);
29}
30
Stephen Hines176edba2014-12-01 14:53:08 -080031enum struct Tuner : short { Interleave = 4, Unroll = 8 };
32
Stephen Hinesc568f1e2014-07-21 00:47:37 -070033// Verify for loop is recognized after sequence of pragma clang loop directives.
34void for_test(int *List, int Length) {
35#pragma clang loop interleave(enable)
Stephen Hines176edba2014-12-01 14:53:08 -080036#pragma clang loop interleave_count(static_cast<int>(Tuner::Interleave))
37#pragma clang loop unroll_count(static_cast<int>(Tuner::Unroll))
Stephen Hinesc568f1e2014-07-21 00:47:37 -070038 for (int i = 0; i < Length; i++) {
39 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
40 List[i] = i * 2;
41 }
42}
43
44// Verify c++11 for range loop is recognized after
45// sequence of pragma clang loop directives.
46void for_range_test() {
47 double List[100];
48
49#pragma clang loop vectorize_width(2) interleave_count(2)
50 for (int i : List) {
51 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
52 List[i] = i;
53 }
54}
55
56// Verify disable pragma clang loop directive generates correct metadata
57void disable_test(int *List, int Length) {
58#pragma clang loop vectorize(disable) unroll(disable)
59 for (int i = 0; i < Length; i++) {
60 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_5:.*]]
61 List[i] = i * 2;
62 }
63}
64
65#define VECWIDTH 2
66#define INTCOUNT 2
67#define UNROLLCOUNT 8
68
69// Verify defines are correctly resolved in pragma clang loop directive
70void for_define_test(int *List, int Length, int Value) {
71#pragma clang loop vectorize_width(VECWIDTH) interleave_count(INTCOUNT)
72#pragma clang loop unroll_count(UNROLLCOUNT)
73 for (int i = 0; i < Length; i++) {
74 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_6:.*]]
75 List[i] = i * Value;
76 }
77}
78
Stephen Hines176edba2014-12-01 14:53:08 -080079// Verify constant expressions are handled correctly.
80void for_contant_expression_test(int *List, int Length) {
81#pragma clang loop vectorize_width(1 + 4)
82 for (int i = 0; i < Length; i++) {
83 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_7:.*]]
84 List[i] = i;
85 }
86
87#pragma clang loop vectorize_width(3 + VECWIDTH)
88 for (int i = 0; i < Length; i++) {
89 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_8:.*]]
90 List[i] += i;
91 }
92}
93
Stephen Hinesc568f1e2014-07-21 00:47:37 -070094// Verify metadata is generated when template is used.
95template <typename A>
96void for_template_test(A *List, int Length, A Value) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -070097#pragma clang loop vectorize_width(8) interleave_count(8) unroll_count(8)
98 for (int i = 0; i < Length; i++) {
Stephen Hines176edba2014-12-01 14:53:08 -080099 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_9:.*]]
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700100 List[i] = i * Value;
101 }
102}
103
104// Verify define is resolved correctly when template is used.
Stephen Hines176edba2014-12-01 14:53:08 -0800105template <typename A, typename T>
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700106void for_template_define_test(A *List, int Length, A Value) {
Stephen Hines176edba2014-12-01 14:53:08 -0800107 const T VWidth = VECWIDTH;
108 const T ICount = INTCOUNT;
109 const T UCount = UNROLLCOUNT;
110#pragma clang loop vectorize_width(VWidth) interleave_count(ICount)
111#pragma clang loop unroll_count(UCount)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700112 for (int i = 0; i < Length; i++) {
Stephen Hines176edba2014-12-01 14:53:08 -0800113 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_10:.*]]
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700114 List[i] = i * Value;
115 }
116}
117
Stephen Hines176edba2014-12-01 14:53:08 -0800118// Verify templates and constant expressions are handled correctly.
119template <typename A, int V, int I, int U>
120void for_template_constant_expression_test(A *List, int Length) {
121#pragma clang loop vectorize_width(V) interleave_count(I) unroll_count(U)
122 for (int i = 0; i < Length; i++) {
123 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_11:.*]]
124 List[i] = i;
125 }
126
127#pragma clang loop vectorize_width(V * 2 + VECWIDTH) interleave_count(I * 2 + INTCOUNT) unroll_count(U * 2 + UNROLLCOUNT)
128 for (int i = 0; i < Length; i++) {
129 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_12:.*]]
130 List[i] += i;
131 }
132
133 const int Scale = 4;
134#pragma clang loop vectorize_width(Scale * V) interleave_count(Scale * I) unroll_count(Scale * U)
135 for (int i = 0; i < Length; i++) {
136 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_13:.*]]
137 List[i] += i;
138 }
139
140#pragma clang loop vectorize_width((Scale * V) + 2)
141 for (int i = 0; i < Length; i++) {
142 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_14:.*]]
143 List[i] += i;
144 }
145}
146
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700147#undef VECWIDTH
148#undef INTCOUNT
149#undef UNROLLCOUNT
150
151// Use templates defined above. Test verifies metadata is generated correctly.
152void template_test(double *List, int Length) {
153 double Value = 10;
154
155 for_template_test<double>(List, Length, Value);
Stephen Hines176edba2014-12-01 14:53:08 -0800156 for_template_define_test<double, int>(List, Length, Value);
157 for_template_constant_expression_test<double, 2, 4, 8>(List, Length);
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700158}
159
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700160// CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[UNROLL_FULL:.*]], ![[WIDTH_4:.*]], ![[INTERLEAVE_4:.*]], ![[INTENABLE_1:.*]]}
161// CHECK: ![[UNROLL_FULL]] = !{!"llvm.loop.unroll.full"}
162// CHECK: ![[WIDTH_4]] = !{!"llvm.loop.vectorize.width", i32 4}
163// CHECK: ![[INTERLEAVE_4]] = !{!"llvm.loop.interleave.count", i32 4}
164// CHECK: ![[INTENABLE_1]] = !{!"llvm.loop.vectorize.enable", i1 true}
165// CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2:.*]], ![[UNROLL_DISABLE:.*]], ![[INTERLEAVE_4:.*]], ![[WIDTH_8:.*]]}
166// CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
167// CHECK: ![[WIDTH_8]] = !{!"llvm.loop.vectorize.width", i32 8}
168// CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[UNROLL_8:.*]], ![[INTERLEAVE_4:.*]], ![[ENABLE_1:.*]]}
169// CHECK: ![[UNROLL_8]] = !{!"llvm.loop.unroll.count", i32 8}
170// CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[INTERLEAVE_2:.*]], ![[WIDTH_2:.*]]}
171// CHECK: ![[INTERLEAVE_2]] = !{!"llvm.loop.interleave.count", i32 2}
172// CHECK: ![[WIDTH_2]] = !{!"llvm.loop.vectorize.width", i32 2}
173// CHECK: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[UNROLL_DISABLE:.*]], ![[WIDTH_1:.*]]}
174// CHECK: ![[WIDTH_1]] = !{!"llvm.loop.vectorize.width", i32 1}
175// CHECK: ![[LOOP_6]] = distinct !{![[LOOP_6]], ![[UNROLL_8:.*]], ![[INTERLEAVE_2:.*]], ![[WIDTH_2:.*]]}
176// CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[WIDTH_5:.*]]}
177// CHECK: ![[WIDTH_5]] = !{!"llvm.loop.vectorize.width", i32 5}
178// CHECK: ![[LOOP_8]] = distinct !{![[LOOP_8]], ![[WIDTH_5:.*]]}
179// CHECK: ![[LOOP_9]] = distinct !{![[LOOP_9]], ![[UNROLL_8:.*]], ![[INTERLEAVE_8:.*]], ![[WIDTH_8:.*]]}
180// CHECK: ![[INTERLEAVE_8]] = !{!"llvm.loop.interleave.count", i32 8}
181// CHECK: ![[LOOP_10]] = distinct !{![[LOOP_10]], ![[UNROLL_8:.*]], ![[INTERLEAVE_2:.*]], ![[WIDTH_2:.*]]}
182// CHECK: ![[LOOP_11]] = distinct !{![[LOOP_11]], ![[UNROLL_8:.*]], ![[INTERLEAVE_4:.*]], ![[WIDTH_2:.*]]}
183// CHECK: ![[LOOP_12]] = distinct !{![[LOOP_12]], ![[UNROLL_24:.*]], ![[INTERLEAVE_10:.*]], ![[WIDTH_6:.*]]}
184// CHECK: ![[UNROLL_24]] = !{!"llvm.loop.unroll.count", i32 24}
185// CHECK: ![[INTERLEAVE_10]] = !{!"llvm.loop.interleave.count", i32 10}
186// CHECK: ![[WIDTH_6]] = !{!"llvm.loop.vectorize.width", i32 6}
187// CHECK: ![[LOOP_13]] = distinct !{![[LOOP_13]], ![[UNROLL_32:.*]], ![[INTERLEAVE_16:.*]], ![[WIDTH_8:.*]]}
188// CHECK: ![[UNROLL_32]] = !{!"llvm.loop.unroll.count", i32 32}
189// CHECK: ![[INTERLEAVE_16]] = !{!"llvm.loop.interleave.count", i32 16}
190// CHECK: ![[LOOP_14]] = distinct !{![[LOOP_14]], ![[WIDTH_10:.*]]}
191// CHECK: ![[WIDTH_10]] = !{!"llvm.loop.vectorize.width", i32 10}