summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGenCXX/pragma-unroll.cpp
diff options
context:
space:
mode:
authorTyler Nowicki <tyler.nowicki@gmail.com>2015-06-08 22:53:36 +0000
committerTyler Nowicki <tyler.nowicki@gmail.com>2015-06-08 22:53:36 +0000
commit90203dc85535e95da5ab367448cdbce55c15bc5a (patch)
tree2873fd5661748efea6907a8bcd46dd92d673e91b /clang/test/CodeGenCXX/pragma-unroll.cpp
parentb7403336ce356951c1655e82d10c3710671d30f2 (diff)
downloadbcm5719-llvm-90203dc85535e95da5ab367448cdbce55c15bc5a.tar.gz
bcm5719-llvm-90203dc85535e95da5ab367448cdbce55c15bc5a.zip
Moved CPP CodeGen tests into CodeGenCXX.
llvm-svn: 239362
Diffstat (limited to 'clang/test/CodeGenCXX/pragma-unroll.cpp')
-rw-r--r--clang/test/CodeGenCXX/pragma-unroll.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/pragma-unroll.cpp b/clang/test/CodeGenCXX/pragma-unroll.cpp
new file mode 100644
index 00000000000..8b73fa6c8aa
--- /dev/null
+++ b/clang/test/CodeGenCXX/pragma-unroll.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+// Verify while loop is recognized after unroll pragma.
+void while_test(int *List, int Length) {
+ // CHECK: define {{.*}} @_Z10while_test
+ int i = 0;
+
+#pragma unroll
+ while (i < Length) {
+ // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
+ 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;
+
+#pragma nounroll
+ do {
+ // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
+ List[i] = i * 2;
+ i++;
+ } while (i < Length);
+}
+
+// Verify for loop is recognized after unroll pragma.
+void for_test(int *List, int Length) {
+#pragma unroll 8
+ for (int i = 0; i < Length; i++) {
+ // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
+ List[i] = i * 2;
+ }
+}
+
+// Verify c++11 for range loop is recognized after unroll pragma.
+void for_range_test() {
+ double List[100];
+
+#pragma unroll(4)
+ for (int i : List) {
+ // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
+ List[i] = i;
+ }
+}
+
+#define UNROLLCOUNT 8
+
+// Verify defines are correctly resolved in unroll pragmas.
+void for_define_test(int *List, int Length, int Value) {
+#pragma unroll(UNROLLCOUNT)
+ for (int i = 0; i < Length; i++) {
+ // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_5:.*]]
+ List[i] = i * Value;
+ }
+}
+
+// Verify metadata is generated when template is used.
+template <typename A>
+void for_template_test(A *List, int Length, A Value) {
+#pragma unroll 8
+ for (int i = 0; i < Length; i++) {
+ // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_6:.*]]
+ List[i] = i * Value;
+ }
+}
+
+// Verify define is resolved correctly when template is used.
+template <typename A>
+void for_template_define_test(A *List, int Length, A Value) {
+#pragma unroll(UNROLLCOUNT)
+ for (int i = 0; i < Length; i++) {
+ // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_7:.*]]
+ List[i] = i * Value;
+ }
+}
+
+#undef UNROLLCOUNT
+
+// 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);
+ for_template_define_test<double>(List, Length, Value);
+}
+
+// CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[UNROLL_FULL:.*]]}
+// CHECK: ![[UNROLL_FULL]] = !{!"llvm.loop.unroll.full"}
+// CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2:.*]], ![[UNROLL_DISABLE:.*]]}
+// CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
+// CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[UNROLL_8:.*]]}
+// CHECK: ![[UNROLL_8]] = !{!"llvm.loop.unroll.count", i32 8}
+// CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[UNROLL_4:.*]]}
+// CHECK: ![[UNROLL_4]] = !{!"llvm.loop.unroll.count", i32 4}
+// CHECK: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[UNROLL_8:.*]]}
+// CHECK: ![[LOOP_6]] = distinct !{![[LOOP_6]], ![[UNROLL_8:.*]]}
+// CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[UNROLL_8:.*]]}
OpenPOWER on IntegriCloud