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
13 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
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
26 // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
32 // Verify for loop is recognized after unroll pragma.
33 void for_test(int *List
, int Length
) {
34 // CHECK: define {{.*}} @_Z8for_test
36 for (int i
= 0; i
< Length
; i
++) {
37 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
42 // Verify c++11 for range loop is recognized after unroll pragma.
43 void for_range_test() {
44 // CHECK: define {{.*}} @_Z14for_range_test
49 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
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:.*]]
66 // Verify metadata is generated when template is used.
68 void for_template_test(A
*List
, int Length
, A Value
) {
69 // CHECK: define {{.*}} @_Z13template_test
71 for (int i
= 0; i
< Length
; i
++) {
72 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_6:.*]]
77 // Verify define is resolved correctly when template is used.
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:.*]]
91 // Use templates defined above. Test verifies metadata is generated correctly.
92 void template_test(double *List
, int Length
) {
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:.*]]}