llvm.org GIT mirror llvm / 58c9643
[Tests] Autogen RLEV test and add tests for a future enhancement git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363193 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 3 months ago
1 changed file(s) with 194 addition(s) and 80 deletion(s). Raw diff Collapse all Expand all
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -indvars -loop-deletion -simplifycfg -S | FileCheck %s
2
3 ; Test that we can evaluate the exit values of various expression types. Since
14 ; these loops all have predictable exit values we can replace the use outside
2 ; of the loop with a closed-form computation, making the loop dead.
3 ;
4 ; RUN: opt < %s -indvars -loop-deletion -simplifycfg -S | FileCheck %s
5
6 ; CHECK-NOT: br
5 ; of the loop with a closed-form computation.
76
87 define i32 @polynomial_constant() {
98 ;
10 br label %Loop
11
12 Loop: ; preds = %Loop, %0
13 %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; [#uses=3]
14 %B1 = phi i32 [ 0, %0 ], [ %B2, %Loop ] ; [#uses=1]
15 %A2 = add i32 %A1, 1 ; [#uses=1]
16 %B2 = add i32 %B1, %A1 ; [#uses=2]
17 %C = icmp eq i32 %A1, 1000 ; [#uses=1]
18 br i1 %C, label %Out, label %Loop
19
20 Out: ; preds = %Loop
21 ret i32 %B2
9 ; CHECK-LABEL: @polynomial_constant(
10 ; CHECK-NEXT: Out:
11 ; CHECK-NEXT: ret i32 500500
12 ;
13 br label %Loop
14
15 Loop: ; preds = %Loop, %0
16 %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; [#uses=3]
17 %B1 = phi i32 [ 0, %0 ], [ %B2, %Loop ] ; [#uses=1]
18 %A2 = add i32 %A1, 1 ; [#uses=1]
19 %B2 = add i32 %B1, %A1 ; [#uses=2]
20 %C = icmp eq i32 %A1, 1000 ; [#uses=1]
21 br i1 %C, label %Out, label %Loop
22
23 Out: ; preds = %Loop
24 ret i32 %B2
2225 }
2326
2427 define i32 @NSquare(i32 %N) {
2528 ;
26 br label %Loop
27
28 Loop: ; preds = %Loop, %0
29 %X = phi i32 [ 0, %0 ], [ %X2, %Loop ] ; [#uses=4]
30 %X2 = add i32 %X, 1 ; [#uses=1]
31 %c = icmp eq i32 %X, %N ; [#uses=1]
32 br i1 %c, label %Out, label %Loop
33
34 Out: ; preds = %Loop
35 %Y = mul i32 %X, %X ; [#uses=1]
36 ret i32 %Y
29 ; CHECK-LABEL: @NSquare(
30 ; CHECK-NEXT: Out:
31 ; CHECK-NEXT: [[Y:%.*]] = mul i32 [[N:%.*]], [[N]]
32 ; CHECK-NEXT: ret i32 [[Y]]
33 ;
34 br label %Loop
35
36 Loop: ; preds = %Loop, %0
37 %X = phi i32 [ 0, %0 ], [ %X2, %Loop ] ; [#uses=4]
38 %X2 = add i32 %X, 1 ; [#uses=1]
39 %c = icmp eq i32 %X, %N ; [#uses=1]
40 br i1 %c, label %Out, label %Loop
41
42 Out: ; preds = %Loop
43 %Y = mul i32 %X, %X ; [#uses=1]
44 ret i32 %Y
3745 }
3846
3947 define i32 @NSquareOver2(i32 %N) {
4048 ;
41 br label %Loop
42
43 Loop: ; preds = %Loop, %0
44 %X = phi i32 [ 0, %0 ], [ %X2, %Loop ] ; [#uses=3]
45 %Y = phi i32 [ 15, %0 ], [ %Y2, %Loop ] ; [#uses=1]
46 %Y2 = add i32 %Y, %X ; [#uses=2]
47 %X2 = add i32 %X, 1 ; [#uses=1]
48 %c = icmp eq i32 %X, %N ; [#uses=1]
49 br i1 %c, label %Out, label %Loop
50
51 Out: ; preds = %Loop
52 ret i32 %Y2
49 ; CHECK-LABEL: @NSquareOver2(
50 ; CHECK-NEXT: Out:
51 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N:%.*]] to i33
52 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[N]], -1
53 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i33
54 ; CHECK-NEXT: [[TMP3:%.*]] = mul i33 [[TMP0]], [[TMP2]]
55 ; CHECK-NEXT: [[TMP4:%.*]] = lshr i33 [[TMP3]], 1
56 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i33 [[TMP4]] to i32
57 ; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[N]], [[TMP5]]
58 ; CHECK-NEXT: [[TMP7:%.*]] = add i32 [[TMP6]], 15
59 ; CHECK-NEXT: ret i32 [[TMP7]]
60 ;
61 br label %Loop
62
63 Loop: ; preds = %Loop, %0
64 %X = phi i32 [ 0, %0 ], [ %X2, %Loop ] ; [#uses=3]
65 %Y = phi i32 [ 15, %0 ], [ %Y2, %Loop ] ; [#uses=1]
66 %Y2 = add i32 %Y, %X ; [#uses=2]
67 %X2 = add i32 %X, 1 ; [#uses=1]
68 %c = icmp eq i32 %X, %N ; [#uses=1]
69 br i1 %c, label %Out, label %Loop
70
71 Out: ; preds = %Loop
72 ret i32 %Y2
5373 }
5474
5575 define i32 @strength_reduced() {
5676 ;
57 br label %Loop
58
59 Loop: ; preds = %Loop, %0
60 %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; [#uses=3]
61 %B1 = phi i32 [ 0, %0 ], [ %B2, %Loop ] ; [#uses=1]
62 %A2 = add i32 %A1, 1 ; [#uses=1]
63 %B2 = add i32 %B1, %A1 ; [#uses=2]
64 %C = icmp eq i32 %A1, 1000 ; [#uses=1]
65 br i1 %C, label %Out, label %Loop
66
67 Out: ; preds = %Loop
68 ret i32 %B2
77 ; CHECK-LABEL: @strength_reduced(
78 ; CHECK-NEXT: Out:
79 ; CHECK-NEXT: ret i32 500500
80 ;
81 br label %Loop
82
83 Loop: ; preds = %Loop, %0
84 %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; [#uses=3]
85 %B1 = phi i32 [ 0, %0 ], [ %B2, %Loop ] ; [#uses=1]
86 %A2 = add i32 %A1, 1 ; [#uses=1]
87 %B2 = add i32 %B1, %A1 ; [#uses=2]
88 %C = icmp eq i32 %A1, 1000 ; [#uses=1]
89 br i1 %C, label %Out, label %Loop
90
91 Out: ; preds = %Loop
92 ret i32 %B2
6993 }
7094
7195 define i32 @chrec_equals() {
72 entry:
73 br label %no_exit
96 ; CHECK-LABEL: @chrec_equals(
97 ; CHECK-NEXT: entry:
98 ; CHECK-NEXT: ret i32 101
99 ;
100 entry:
101 br label %no_exit
74102
75103 no_exit: ; preds = %no_exit, %entry
76 %i0 = phi i32 [ 0, %entry ], [ %i1, %no_exit ] ; [#uses=3]
77 %ISq = mul i32 %i0, %i0 ; [#uses=1]
78 %i1 = add i32 %i0, 1 ; [#uses=2]
79 %tmp.1 = icmp ne i32 %ISq, 10000 ; [#uses=1]
80 br i1 %tmp.1, label %no_exit, label %loopexit
104 %i0 = phi i32 [ 0, %entry ], [ %i1, %no_exit ] ; [#uses=3]
105 %ISq = mul i32 %i0, %i0 ; [#uses=1]
106 %i1 = add i32 %i0, 1 ; [#uses=2]
107 %tmp.1 = icmp ne i32 %ISq, 10000 ; [#uses=1]
108 br i1 %tmp.1, label %no_exit, label %loopexit
81109
82110 loopexit: ; preds = %no_exit
83 ret i32 %i1
111 ret i32 %i1
84112 }
85113
86114 define i16 @cast_chrec_test() {
87115 ;
88 br label %Loop
89
90 Loop: ; preds = %Loop, %0
91 %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; [#uses=2]
92 %B1 = trunc i32 %A1 to i16 ; [#uses=2]
93 %A2 = add i32 %A1, 1 ; [#uses=1]
94 %C = icmp eq i16 %B1, 1000 ; [#uses=1]
95 br i1 %C, label %Out, label %Loop
96
97 Out: ; preds = %Loop
98 ret i16 %B1
116 ; CHECK-LABEL: @cast_chrec_test(
117 ; CHECK-NEXT: Out:
118 ; CHECK-NEXT: ret i16 1000
119 ;
120 br label %Loop
121
122 Loop: ; preds = %Loop, %0
123 %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; [#uses=2]
124 %B1 = trunc i32 %A1 to i16 ; [#uses=2]
125 %A2 = add i32 %A1, 1 ; [#uses=1]
126 %C = icmp eq i16 %B1, 1000 ; [#uses=1]
127 br i1 %C, label %Out, label %Loop
128
129 Out: ; preds = %Loop
130 ret i16 %B1
99131 }
100132
101133 define i32 @linear_div_fold() {
102 entry:
103 br label %loop
134 ; CHECK-LABEL: @linear_div_fold(
135 ; CHECK-NEXT: entry:
136 ; CHECK-NEXT: ret i32 34
137 ;
138 entry:
139 br label %loop
104140
105141 loop: ; preds = %loop, %entry
106 %i = phi i32 [ 4, %entry ], [ %i.next, %loop ] ; [#uses=3]
107 %i.next = add i32 %i, 8 ; [#uses=1]
108 %RV = udiv i32 %i, 2 ; [#uses=1]
109 %c = icmp ne i32 %i, 68 ; [#uses=1]
110 br i1 %c, label %loop, label %loopexit
142 %i = phi i32 [ 4, %entry ], [ %i.next, %loop ] ; [#uses=3]
143 %i.next = add i32 %i, 8 ; [#uses=1]
144 %RV = udiv i32 %i, 2 ; [#uses=1]
145 %c = icmp ne i32 %i, 68 ; [#uses=1]
146 br i1 %c, label %loop, label %loopexit
111147
112148 loopexit: ; preds = %loop
113 ret i32 %RV
114 }
149 ret i32 %RV
150 }
151
152 define i32 @unroll_phi_select_constant_nonzero(i32 %arg1, i32 %arg2) {
153 ; CHECK-LABEL: @unroll_phi_select_constant_nonzero(
154 ; CHECK-NEXT: entry:
155 ; CHECK-NEXT: br label [[LOOP:%.*]]
156 ; CHECK: loop:
157 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
158 ; CHECK-NEXT: [[SELECTOR:%.*]] = phi i32 [ [[ARG1:%.*]], [[ENTRY]] ], [ [[ARG2:%.*]], [[LOOP]] ]
159 ; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
160 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[I]], 4
161 ; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[LOOPEXIT:%.*]]
162 ; CHECK: loopexit:
163 ; CHECK-NEXT: [[SELECTOR_LCSSA:%.*]] = phi i32 [ [[SELECTOR]], [[LOOP]] ]
164 ; CHECK-NEXT: ret i32 [[SELECTOR_LCSSA]]
165 ;
166 entry:
167 br label %loop
168
169 loop:
170 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
171 %selector = phi i32 [%arg1, %entry], [%arg2, %loop]
172 %i.next = add nsw nuw i32 %i, 1
173 %c = icmp ult i32 %i, 4
174 br i1 %c, label %loop, label %loopexit
175
176 loopexit:
177 ret i32 %selector
178 }
179
180 define i32 @unroll_phi_select_constant_zero(i32 %arg1, i32 %arg2) {
181 ; CHECK-LABEL: @unroll_phi_select_constant_zero(
182 ; CHECK-NEXT: entry:
183 ; CHECK-NEXT: ret i32 [[ARG1:%.*]]
184 ;
185 entry:
186 br label %loop
187
188 loop:
189 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
190 %selector = phi i32 [%arg1, %entry], [%arg2, %loop]
191 %i.next = add i32 %i, 1
192 %c = icmp ne i32 %i, 0
193 br i1 %c, label %loop, label %loopexit
194
195 loopexit:
196 ret i32 %selector
197 }
198
199 define i32 @unroll_phi_select(i32 %arg1, i32 %arg2, i16 %len) {
200 ; CHECK-LABEL: @unroll_phi_select(
201 ; CHECK-NEXT: entry:
202 ; CHECK-NEXT: [[LENGTH:%.*]] = zext i16 [[LEN:%.*]] to i32
203 ; CHECK-NEXT: br label [[LOOP:%.*]]
204 ; CHECK: loop:
205 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
206 ; CHECK-NEXT: [[SELECTOR:%.*]] = phi i32 [ [[ARG1:%.*]], [[ENTRY]] ], [ [[ARG2:%.*]], [[LOOP]] ]
207 ; CHECK-NEXT: [[I_NEXT]] = add nsw i32 [[I]], 1
208 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[I]], [[LENGTH]]
209 ; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[LOOPEXIT:%.*]]
210 ; CHECK: loopexit:
211 ; CHECK-NEXT: [[SELECTOR_LCSSA:%.*]] = phi i32 [ [[SELECTOR]], [[LOOP]] ]
212 ; CHECK-NEXT: ret i32 [[SELECTOR_LCSSA]]
213 ;
214 entry:
215 %length = zext i16 %len to i32
216 br label %loop
217
218 loop:
219 %i = phi i32 [ -1, %entry ], [ %i.next, %loop ]
220 %selector = phi i32 [%arg1, %entry], [%arg2, %loop]
221 %i.next = add nsw i32 %i, 1
222 %c = icmp slt i32 %i, %length
223 br i1 %c, label %loop, label %loopexit
224
225 loopexit:
226 ret i32 %selector
227 }
228