Debian Codegraph @

clang/test/CodeGenHLSL/loops/unroll.hlsl

raw
1 // RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple \
2 // RUN: dxil-pc-shadermodel6.3-library -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
3
4 /*** for ***/
5 void for_count()
6 {
7 // CHECK-LABEL: for_count
8 [unroll(8)]
9 for( int i = 0; i < 1000; ++i);
10 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_DISTINCT:.*]]
11 }
12
13 void for_disable()
14 {
15 // CHECK-LABEL: for_disable
16 [loop]
17 for( int i = 0; i < 1000; ++i);
18 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_DISABLE:.*]]
19 }
20
21 void for_enable()
22 {
23 // CHECK-LABEL: for_enable
24 [unroll]
25 for( int i = 0; i < 1000; ++i);
26 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_ENABLE:.*]]
27 }
28
29 void for_nested_one_unroll_enable()
30 {
31 // CHECK-LABEL: for_nested_one_unroll_enable
32 int s = 0;
33 [unroll]
34 for( int i = 0; i < 1000; ++i) {
35 for( int j = 0; j < 10; ++j)
36 s += i + j;
37 }
38 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_NESTED_ENABLE_INNER:.*]]
39 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_NESTED_ENABLE_OUTER:.*]]
40 }
41
42 void for_nested_two_unroll_enable()
43 {
44 // CHECK-LABEL: for_nested_two_unroll_enable
45 int s = 0;
46 [unroll]
47 for( int i = 0; i < 1000; ++i) {
48 [unroll]
49 for( int j = 0; j < 10; ++j)
50 s += i + j;
51 }
52 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_NESTED2_ENABLE:.*]]
53 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_NESTED2_1_ENABLE:.*]]
54 }
55
56
57 /*** while ***/
58 void while_count()
59 {
60 // CHECK-LABEL: while_count
61 int i = 1000;
62 [unroll(4)]
63 while(i-->0);
64 // CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_DISTINCT:.*]]
65 }
66
67 void while_disable()
68 {
69 // CHECK-LABEL: while_disable
70 int i = 1000;
71 [loop]
72 while(i-->0);
73 // CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_DISABLE:.*]]
74 }
75
76 void while_enable()
77 {
78 // CHECK-LABEL: while_enable
79 int i = 1000;
80 [unroll]
81 while(i-->0);
82 // CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_ENABLE:.*]]
83 }
84
85 /*** do ***/
86 void do_count()
87 {
88 // CHECK-LABEL: do_count
89 int i = 1000;
90 [unroll(16)]
91 do {} while(i--> 0);
92 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop ![[DO_DISTINCT:.*]]
93 }
94
95 void do_disable()
96 {
97 // CHECK-LABEL: do_disable
98 int i = 1000;
99 [loop]
100 do {} while(i--> 0);
101 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop ![[DO_DISABLE:.*]]
102 }
103
104 void do_enable()
105 {
106 // CHECK-LABEL: do_enable
107 int i = 1000;
108 [unroll]
109 do {} while(i--> 0);
110 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop ![[DO_ENABLE:.*]]
111 }
112
113
114 // CHECK-DAG: [[MUST_PROGRESS:.*]] = !{!"llvm.loop.mustprogress"}
115 // CHECK-DAG: [[DISABLE:.*]] = !{!"llvm.loop.unroll.disable"}
116 // CHECK-DAG: [[FOR_COUNT:.*]] = !{!"llvm.loop.unroll.count", i32 8}
117 // CHECK-DAG: [[ENABLE:.*]] = !{!"llvm.loop.unroll.enable"}
118 // CHECK-DAG: [[WHILE_COUNT:.*]] = !{!"llvm.loop.unroll.count", i32 4}
119 // CHECK-DAG: [[DO_COUNT:.*]] = !{!"llvm.loop.unroll.count", i32 16}
120
121 // CHECK-DAG: ![[FOR_DISTINCT]] = distinct !{![[FOR_DISTINCT]], [[MUST_PROGRESS]], [[FOR_COUNT]]}
122 // CHECK-DAG: ![[FOR_DISABLE]] = distinct !{![[FOR_DISABLE]], [[MUST_PROGRESS]], [[DISABLE]]}
123 // CHECK-DAG: ![[FOR_ENABLE]] = distinct !{![[FOR_ENABLE]], [[MUST_PROGRESS]], [[ENABLE]]}
124
125 // CHECK-DAG: ![[FOR_NESTED_ENABLE_INNER]] = distinct !{![[FOR_NESTED_ENABLE_INNER]], [[MUST_PROGRESS]]}
126 // CHECK-DAG: ![[FOR_NESTED_ENABLE_OUTER]] = distinct !{![[FOR_NESTED_ENABLE_OUTER]], [[MUST_PROGRESS]], [[ENABLE]]}
127 // CHECK-DAG: ![[FOR_NESTED2_ENABLE]] = distinct !{![[FOR_NESTED2_ENABLE]], [[MUST_PROGRESS]], [[ENABLE]]}
128 // CHECK-DAG: ![[FOR_NESTED2_1_ENABLE]] = distinct !{![[FOR_NESTED2_1_ENABLE]], [[MUST_PROGRESS]], [[ENABLE]]}
129 // CHECK-DAG: ![[WHILE_DISTINCT]] = distinct !{![[WHILE_DISTINCT]], [[MUST_PROGRESS]], [[WHILE_COUNT]]}
130
131 // CHECK-DAG: ![[WHILE_DISABLE]] = distinct !{![[WHILE_DISABLE]], [[MUST_PROGRESS]], [[DISABLE]]}
132 // CHECK-DAG: ![[WHILE_ENABLE]] = distinct !{![[WHILE_ENABLE]], [[MUST_PROGRESS]], [[ENABLE]]}
133 // CHECK-DAG: ![[DO_DISTINCT]] = distinct !{![[DO_DISTINCT]], [[MUST_PROGRESS]], [[DO_COUNT]]}
134
135 // CHECK-DAG: ![[DO_DISABLE]] = distinct !{![[DO_DISABLE]], [[MUST_PROGRESS]], [[DISABLE]]}
136 // CHECK-DAG: ![[DO_ENABLE]] = distinct !{![[DO_ENABLE]], [[MUST_PROGRESS]], [[ENABLE]]}