2014-06-11 05:35:24 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
|
|
|
|
|
|
|
|
// Verify while loop is recognized after sequence of pragma clang loop directives.
|
|
|
|
void while_test(int *List, int Length) {
|
|
|
|
// CHECK: define {{.*}} @_Z10while_test
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
#pragma clang loop vectorize(enable)
|
|
|
|
#pragma clang loop interleave_count(4)
|
|
|
|
#pragma clang loop vectorize_width(4)
|
2014-07-24 01:31:31 +08:00
|
|
|
#pragma clang loop unroll(full)
|
2016-06-14 20:04:26 +08:00
|
|
|
#pragma clang loop distribute(enable)
|
2014-06-11 05:35:24 +08:00
|
|
|
while (i < Length) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
|
2014-06-11 05:35:24 +08:00
|
|
|
List[i] = i * 2;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify do loop is recognized after multi-option pragma clang loop directive.
|
|
|
|
void do_test(int *List, int Length) {
|
|
|
|
int i = 0;
|
|
|
|
|
2016-06-14 20:04:26 +08:00
|
|
|
#pragma clang loop vectorize_width(8) interleave_count(4) unroll(disable) distribute(disable)
|
2014-06-11 05:35:24 +08:00
|
|
|
do {
|
|
|
|
// CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
|
|
|
|
List[i] = i * 2;
|
|
|
|
i++;
|
|
|
|
} while (i < Length);
|
|
|
|
}
|
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
enum struct Tuner : short { Interleave = 4, Unroll = 8 };
|
|
|
|
|
2014-06-11 05:35:24 +08:00
|
|
|
// Verify for loop is recognized after sequence of pragma clang loop directives.
|
|
|
|
void for_test(int *List, int Length) {
|
|
|
|
#pragma clang loop interleave(enable)
|
2014-10-13 04:46:07 +08:00
|
|
|
#pragma clang loop interleave_count(static_cast<int>(Tuner::Interleave))
|
|
|
|
#pragma clang loop unroll_count(static_cast<int>(Tuner::Unroll))
|
2014-06-11 05:35:24 +08:00
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
|
2014-06-11 05:35:24 +08:00
|
|
|
List[i] = i * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify c++11 for range loop is recognized after
|
|
|
|
// sequence of pragma clang loop directives.
|
|
|
|
void for_range_test() {
|
|
|
|
double List[100];
|
|
|
|
|
|
|
|
#pragma clang loop vectorize_width(2) interleave_count(2)
|
|
|
|
for (int i : List) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
|
2014-06-11 05:35:24 +08:00
|
|
|
List[i] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify disable pragma clang loop directive generates correct metadata
|
|
|
|
void disable_test(int *List, int Length) {
|
2016-06-14 20:04:26 +08:00
|
|
|
#pragma clang loop vectorize(disable) unroll(disable) distribute(disable)
|
2014-06-11 05:35:24 +08:00
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_5:.*]]
|
2014-06-11 05:35:24 +08:00
|
|
|
List[i] = i * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VECWIDTH 2
|
|
|
|
#define INTCOUNT 2
|
2014-06-12 01:56:26 +08:00
|
|
|
#define UNROLLCOUNT 8
|
2014-06-11 05:35:24 +08:00
|
|
|
|
|
|
|
// Verify defines are correctly resolved in pragma clang loop directive
|
|
|
|
void for_define_test(int *List, int Length, int Value) {
|
|
|
|
#pragma clang loop vectorize_width(VECWIDTH) interleave_count(INTCOUNT)
|
2014-06-12 01:56:26 +08:00
|
|
|
#pragma clang loop unroll_count(UNROLLCOUNT)
|
2014-06-11 05:35:24 +08:00
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_6:.*]]
|
2014-06-11 05:35:24 +08:00
|
|
|
List[i] = i * Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
// Verify constant expressions are handled correctly.
|
|
|
|
void for_contant_expression_test(int *List, int Length) {
|
|
|
|
#pragma clang loop vectorize_width(1 + 4)
|
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_7:.*]]
|
2014-10-13 04:46:07 +08:00
|
|
|
List[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma clang loop vectorize_width(3 + VECWIDTH)
|
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_8:.*]]
|
2014-10-13 04:46:07 +08:00
|
|
|
List[i] += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-11 05:35:24 +08:00
|
|
|
// Verify metadata is generated when template is used.
|
|
|
|
template <typename A>
|
|
|
|
void for_template_test(A *List, int Length, A Value) {
|
2014-06-12 01:56:26 +08:00
|
|
|
#pragma clang loop vectorize_width(8) interleave_count(8) unroll_count(8)
|
2014-06-11 05:35:24 +08:00
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_9:.*]]
|
2014-06-11 05:35:24 +08:00
|
|
|
List[i] = i * Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify define is resolved correctly when template is used.
|
2014-10-13 04:46:07 +08:00
|
|
|
template <typename A, typename T>
|
2014-06-11 05:35:24 +08:00
|
|
|
void for_template_define_test(A *List, int Length, A Value) {
|
2014-10-13 04:46:07 +08:00
|
|
|
const T VWidth = VECWIDTH;
|
|
|
|
const T ICount = INTCOUNT;
|
|
|
|
const T UCount = UNROLLCOUNT;
|
|
|
|
#pragma clang loop vectorize_width(VWidth) interleave_count(ICount)
|
|
|
|
#pragma clang loop unroll_count(UCount)
|
2014-06-11 05:35:24 +08:00
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_10:.*]]
|
2014-06-11 05:35:24 +08:00
|
|
|
List[i] = i * Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
// Verify templates and constant expressions are handled correctly.
|
|
|
|
template <typename A, int V, int I, int U>
|
|
|
|
void for_template_constant_expression_test(A *List, int Length) {
|
|
|
|
#pragma clang loop vectorize_width(V) interleave_count(I) unroll_count(U)
|
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_11:.*]]
|
2014-10-13 04:46:07 +08:00
|
|
|
List[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma clang loop vectorize_width(V * 2 + VECWIDTH) interleave_count(I * 2 + INTCOUNT) unroll_count(U * 2 + UNROLLCOUNT)
|
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_12:.*]]
|
2014-10-13 04:46:07 +08:00
|
|
|
List[i] += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int Scale = 4;
|
|
|
|
#pragma clang loop vectorize_width(Scale * V) interleave_count(Scale * I) unroll_count(Scale * U)
|
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_13:.*]]
|
2014-10-13 04:46:07 +08:00
|
|
|
List[i] += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma clang loop vectorize_width((Scale * V) + 2)
|
|
|
|
for (int i = 0; i < Length; i++) {
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_14:.*]]
|
2014-10-13 04:46:07 +08:00
|
|
|
List[i] += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-11 05:35:24 +08:00
|
|
|
#undef VECWIDTH
|
|
|
|
#undef INTCOUNT
|
2014-06-12 01:56:26 +08:00
|
|
|
#undef UNROLLCOUNT
|
2014-06-11 05:35:24 +08:00
|
|
|
|
|
|
|
// Use templates defined above. Test verifies metadata is generated correctly.
|
|
|
|
void template_test(double *List, int Length) {
|
|
|
|
double Value = 10;
|
|
|
|
|
|
|
|
for_template_test<double>(List, Length, Value);
|
2014-10-13 04:46:07 +08:00
|
|
|
for_template_define_test<double, int>(List, Length, Value);
|
|
|
|
for_template_constant_expression_test<double, 2, 4, 8>(List, Length);
|
2014-06-11 05:35:24 +08:00
|
|
|
}
|
|
|
|
|
2016-06-14 20:04:26 +08:00
|
|
|
// CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[WIDTH_4:.*]], ![[INTERLEAVE_4:.*]], ![[INTENABLE_1:.*]], ![[UNROLL_FULL:.*]], ![[DISTRIBUTE_ENABLE:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[WIDTH_4]] = !{!"llvm.loop.vectorize.width", i32 4}
|
|
|
|
// CHECK: ![[INTERLEAVE_4]] = !{!"llvm.loop.interleave.count", i32 4}
|
|
|
|
// CHECK: ![[INTENABLE_1]] = !{!"llvm.loop.vectorize.enable", i1 true}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[UNROLL_FULL]] = !{!"llvm.loop.unroll.full"}
|
2016-06-14 20:04:26 +08:00
|
|
|
// CHECK: ![[DISTRIBUTE_ENABLE]] = !{!"llvm.loop.distribute.enable", i1 true}
|
|
|
|
// CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2:.*]], ![[WIDTH_8:.*]], ![[INTERLEAVE_4:.*]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[WIDTH_8]] = !{!"llvm.loop.vectorize.width", i32 8}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
|
2016-06-14 20:04:26 +08:00
|
|
|
// CHECK: ![[DISTRIBUTE_DISABLE]] = !{!"llvm.loop.distribute.enable", i1 false}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[INTERLEAVE_4:.*]], ![[UNROLL_8:.*]], ![[INTENABLE_1:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[UNROLL_8]] = !{!"llvm.loop.unroll.count", i32 8}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[WIDTH_2:.*]], ![[INTERLEAVE_2:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[WIDTH_2]] = !{!"llvm.loop.vectorize.width", i32 2}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[INTERLEAVE_2]] = !{!"llvm.loop.interleave.count", i32 2}
|
2016-06-14 20:04:26 +08:00
|
|
|
// CHECK: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[WIDTH_1:.*]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[WIDTH_1]] = !{!"llvm.loop.vectorize.width", i32 1}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[LOOP_6]] = distinct !{![[LOOP_6]], ![[WIDTH_2:.*]], ![[INTERLEAVE_2:.*]], ![[UNROLL_8:.*]]}
|
2015-01-09 06:39:28 +08:00
|
|
|
// CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[WIDTH_5:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[WIDTH_5]] = !{!"llvm.loop.vectorize.width", i32 5}
|
2015-01-09 06:39:28 +08:00
|
|
|
// CHECK: ![[LOOP_8]] = distinct !{![[LOOP_8]], ![[WIDTH_5:.*]]}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[LOOP_9]] = distinct !{![[LOOP_9]], ![[WIDTH_8:.*]], ![[INTERLEAVE_8:.*]], ![[UNROLL_8:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[INTERLEAVE_8]] = !{!"llvm.loop.interleave.count", i32 8}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[LOOP_10]] = distinct !{![[LOOP_10]], ![[WIDTH_2:.*]], ![[INTERLEAVE_2:.*]], ![[UNROLL_8:.*]]}
|
|
|
|
// CHECK: ![[LOOP_11]] = distinct !{![[LOOP_11]], ![[WIDTH_2:.*]], ![[INTERLEAVE_4:.*]], ![[UNROLL_8:.*]]}
|
|
|
|
// CHECK: ![[LOOP_12]] = distinct !{![[LOOP_12]], ![[WIDTH_6:.*]], ![[INTERLEAVE_10:.*]], ![[UNROLL_24:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[WIDTH_6]] = !{!"llvm.loop.vectorize.width", i32 6}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[INTERLEAVE_10]] = !{!"llvm.loop.interleave.count", i32 10}
|
|
|
|
// CHECK: ![[UNROLL_24]] = !{!"llvm.loop.unroll.count", i32 24}
|
|
|
|
// CHECK: ![[LOOP_13]] = distinct !{![[LOOP_13]], ![[WIDTH_8:.*]], ![[INTERLEAVE_16:.*]], ![[UNROLL_32:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[INTERLEAVE_16]] = !{!"llvm.loop.interleave.count", i32 16}
|
2015-07-28 04:10:20 +08:00
|
|
|
// CHECK: ![[UNROLL_32]] = !{!"llvm.loop.unroll.count", i32 32}
|
2015-01-09 06:39:28 +08:00
|
|
|
// CHECK: ![[LOOP_14]] = distinct !{![[LOOP_14]], ![[WIDTH_10:.*]]}
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: ![[WIDTH_10]] = !{!"llvm.loop.vectorize.width", i32 10}
|