[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / CodeGenCXX / pragma-unroll.cpp
blob02d9bad7148d363f46c0694b6df1903d2f61978c
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
3 // Check that passing -fno-unroll-loops does not impact the decision made using pragmas.
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - -O1 -disable-llvm-optzns -fno-unroll-loops %s | FileCheck %s
6 // Verify while loop is recognized after unroll pragma.
7 void while_test(int *List, int Length) {
8 // CHECK: define {{.*}} @_Z10while_test
9 int i = 0;
11 #pragma unroll
12 while (i < Length) {
13 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
14 List[i] = i * 2;
15 i++;
19 // Verify do loop is recognized after multi-option pragma clang loop directive.
20 void do_test(int *List, int Length) {
21 // CHECK: define {{.*}} @_Z7do_test
22 int i = 0;
24 #pragma nounroll
25 do {
26 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
27 List[i] = i * 2;
28 i++;
29 } while (i < Length);
32 // Verify for loop is recognized after unroll pragma.
33 void for_test(int *List, int Length) {
34 // CHECK: define {{.*}} @_Z8for_test
35 #pragma unroll 8
36 for (int i = 0; i < Length; i++) {
37 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
38 List[i] = i * 2;
42 // Verify c++11 for range loop is recognized after unroll pragma.
43 void for_range_test() {
44 // CHECK: define {{.*}} @_Z14for_range_test
45 double List[100];
47 #pragma unroll(4)
48 for (int i : List) {
49 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
50 List[i] = i;
54 #define UNROLLCOUNT 8
56 // Verify defines are correctly resolved in unroll pragmas.
57 void for_define_test(int *List, int Length, int Value) {
58 // CHECK: define {{.*}} @_Z15for_define_test
59 #pragma unroll(UNROLLCOUNT)
60 for (int i = 0; i < Length; i++) {
61 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_5:.*]]
62 List[i] = i * Value;
66 // Verify metadata is generated when template is used.
67 template <typename A>
68 void for_template_test(A *List, int Length, A Value) {
69 // CHECK: define {{.*}} @_Z13template_test
70 #pragma unroll 8
71 for (int i = 0; i < Length; i++) {
72 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_6:.*]]
73 List[i] = i * Value;
77 // Verify define is resolved correctly when template is used.
78 template <typename A>
79 void for_template_define_test(A *List, int Length, A Value) {
80 // CHECK: define {{.*}} @_Z24for_template_define_test
82 #pragma unroll(UNROLLCOUNT)
83 for (int i = 0; i < Length; i++) {
84 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_7:.*]]
85 List[i] = i * Value;
89 #undef UNROLLCOUNT
91 // Use templates defined above. Test verifies metadata is generated correctly.
92 void template_test(double *List, int Length) {
93 double Value = 10;
95 for_template_test<double>(List, Length, Value);
96 for_template_define_test<double>(List, Length, Value);
99 // CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], [[MP:![0-9]+]], ![[UNROLL_ENABLE:.*]]}
100 // CHECK: ![[UNROLL_ENABLE]] = !{!"llvm.loop.unroll.enable"}
101 // CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2:.*]], ![[UNROLL_DISABLE:.*]]}
102 // CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
103 // CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], [[MP]], ![[UNROLL_8:.*]]}
104 // CHECK: ![[UNROLL_8]] = !{!"llvm.loop.unroll.count", i32 8}
105 // CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[UNROLL_4:.*]]}
106 // CHECK: ![[UNROLL_4]] = !{!"llvm.loop.unroll.count", i32 4}
107 // CHECK: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[UNROLL_8:.*]]}
108 // CHECK: ![[LOOP_6]] = distinct !{![[LOOP_6]], ![[UNROLL_8:.*]]}
109 // CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[UNROLL_8:.*]]}