1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -indvars -S "-data-layout=e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" | FileCheck -check-prefix=PTR64 %s
3 ; RUN: opt < %s -indvars -S "-data-layout=e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32" | FileCheck -check-prefix=PTR32 %s
5 ; PR11279: Assertion !IVLimit->getType()->isPointerTy()
7 ; Test LinearFunctionTestReplace of a pointer-type loop counter. Note
8 ; that BECount may or may not be a pointer type. A pointer type
9 ; BECount doesn't really make sense, but that's what falls out of
10 ; SCEV. Since it's an i8*, it has unit stride so we never adjust the
11 ; SCEV expression in a way that would convert it to an integer type.
13 define i8 @testnullptrptr(i8* %buf, i8* %end) nounwind {
14 ; PTR64-LABEL: @testnullptrptr(
15 ; PTR64-NEXT: br label [[LOOPGUARD:%.*]]
17 ; PTR64-NEXT: [[GUARD:%.*]] = icmp ult i8* null, [[END:%.*]]
18 ; PTR64-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
20 ; PTR64-NEXT: br label [[LOOP:%.*]]
22 ; PTR64-NEXT: [[P_01_US_US:%.*]] = phi i8* [ null, [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
23 ; PTR64-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
24 ; PTR64-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
25 ; PTR64-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[END]]
26 ; PTR64-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
27 ; PTR64: exit.loopexit:
28 ; PTR64-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
29 ; PTR64-NEXT: br label [[EXIT]]
31 ; PTR64-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
32 ; PTR64-NEXT: ret i8 [[RET]]
34 ; PTR32-LABEL: @testnullptrptr(
35 ; PTR32-NEXT: br label [[LOOPGUARD:%.*]]
37 ; PTR32-NEXT: [[GUARD:%.*]] = icmp ult i8* null, [[END:%.*]]
38 ; PTR32-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
40 ; PTR32-NEXT: br label [[LOOP:%.*]]
42 ; PTR32-NEXT: [[P_01_US_US:%.*]] = phi i8* [ null, [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
43 ; PTR32-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
44 ; PTR32-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
45 ; PTR32-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[END]]
46 ; PTR32-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
47 ; PTR32: exit.loopexit:
48 ; PTR32-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
49 ; PTR32-NEXT: br label [[EXIT]]
51 ; PTR32-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
52 ; PTR32-NEXT: ret i8 [[RET]]
57 %guard = icmp ult i8* null, %end
58 br i1 %guard, label %preheader, label %exit
64 %p.01.us.us = phi i8* [ null, %preheader ], [ %gep, %loop ]
65 %s = phi i8 [0, %preheader], [%snext, %loop]
66 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1
67 %snext = load i8, i8* %gep
68 %cmp = icmp ult i8* %gep, %end
69 br i1 %cmp, label %loop, label %exit
72 %ret = phi i8 [0, %loopguard], [%snext, %loop]
76 define i8 @testptrptr(i8* %buf, i8* %end) nounwind {
77 ; PTR64-LABEL: @testptrptr(
78 ; PTR64-NEXT: br label [[LOOPGUARD:%.*]]
80 ; PTR64-NEXT: [[GUARD:%.*]] = icmp ult i8* [[BUF:%.*]], [[END:%.*]]
81 ; PTR64-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
83 ; PTR64-NEXT: br label [[LOOP:%.*]]
85 ; PTR64-NEXT: [[P_01_US_US:%.*]] = phi i8* [ [[BUF]], [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
86 ; PTR64-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
87 ; PTR64-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
88 ; PTR64-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[END]]
89 ; PTR64-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
90 ; PTR64: exit.loopexit:
91 ; PTR64-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
92 ; PTR64-NEXT: br label [[EXIT]]
94 ; PTR64-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
95 ; PTR64-NEXT: ret i8 [[RET]]
97 ; PTR32-LABEL: @testptrptr(
98 ; PTR32-NEXT: br label [[LOOPGUARD:%.*]]
100 ; PTR32-NEXT: [[GUARD:%.*]] = icmp ult i8* [[BUF:%.*]], [[END:%.*]]
101 ; PTR32-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
103 ; PTR32-NEXT: br label [[LOOP:%.*]]
105 ; PTR32-NEXT: [[P_01_US_US:%.*]] = phi i8* [ [[BUF]], [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
106 ; PTR32-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
107 ; PTR32-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
108 ; PTR32-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[END]]
109 ; PTR32-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
110 ; PTR32: exit.loopexit:
111 ; PTR32-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
112 ; PTR32-NEXT: br label [[EXIT]]
114 ; PTR32-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
115 ; PTR32-NEXT: ret i8 [[RET]]
120 %guard = icmp ult i8* %buf, %end
121 br i1 %guard, label %preheader, label %exit
127 %p.01.us.us = phi i8* [ %buf, %preheader ], [ %gep, %loop ]
128 %s = phi i8 [0, %preheader], [%snext, %loop]
129 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1
130 %snext = load i8, i8* %gep
131 %cmp = icmp ult i8* %gep, %end
132 br i1 %cmp, label %loop, label %exit
135 %ret = phi i8 [0, %loopguard], [%snext, %loop]
139 define i8 @testnullptrint(i8* %buf, i8* %end) nounwind {
140 ; PTR64-LABEL: @testnullptrint(
141 ; PTR64-NEXT: br label [[LOOPGUARD:%.*]]
143 ; PTR64-NEXT: [[BI:%.*]] = ptrtoint i8* [[BUF:%.*]] to i32
144 ; PTR64-NEXT: [[EI:%.*]] = ptrtoint i8* [[END:%.*]] to i32
145 ; PTR64-NEXT: [[CNT:%.*]] = sub i32 [[EI]], [[BI]]
146 ; PTR64-NEXT: [[GUARD:%.*]] = icmp ult i32 0, [[CNT]]
147 ; PTR64-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
149 ; PTR64-NEXT: [[TMP1:%.*]] = add i32 [[EI]], -1
150 ; PTR64-NEXT: [[TMP2:%.*]] = sub i32 [[TMP1]], [[BI]]
151 ; PTR64-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
152 ; PTR64-NEXT: [[TMP4:%.*]] = add nuw nsw i64 [[TMP3]], 1
153 ; PTR64-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to i8*
154 ; PTR64-NEXT: br label [[LOOP:%.*]]
156 ; PTR64-NEXT: [[P_01_US_US:%.*]] = phi i8* [ null, [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
157 ; PTR64-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
158 ; PTR64-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
159 ; PTR64-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[TMP5]]
160 ; PTR64-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
161 ; PTR64: exit.loopexit:
162 ; PTR64-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
163 ; PTR64-NEXT: br label [[EXIT]]
165 ; PTR64-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
166 ; PTR64-NEXT: ret i8 [[RET]]
168 ; PTR32-LABEL: @testnullptrint(
169 ; PTR32-NEXT: br label [[LOOPGUARD:%.*]]
171 ; PTR32-NEXT: [[BI:%.*]] = ptrtoint i8* [[BUF:%.*]] to i32
172 ; PTR32-NEXT: [[EI:%.*]] = ptrtoint i8* [[END:%.*]] to i32
173 ; PTR32-NEXT: [[CNT:%.*]] = sub i32 [[EI]], [[BI]]
174 ; PTR32-NEXT: [[CNT1:%.*]] = inttoptr i32 [[CNT]] to i8*
175 ; PTR32-NEXT: [[GUARD:%.*]] = icmp ult i32 0, [[CNT]]
176 ; PTR32-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
178 ; PTR32-NEXT: br label [[LOOP:%.*]]
180 ; PTR32-NEXT: [[P_01_US_US:%.*]] = phi i8* [ null, [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
181 ; PTR32-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
182 ; PTR32-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
183 ; PTR32-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[GEP]], [[CNT1]]
184 ; PTR32-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
185 ; PTR32: exit.loopexit:
186 ; PTR32-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
187 ; PTR32-NEXT: br label [[EXIT]]
189 ; PTR32-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
190 ; PTR32-NEXT: ret i8 [[RET]]
195 %bi = ptrtoint i8* %buf to i32
196 %ei = ptrtoint i8* %end to i32
197 %cnt = sub i32 %ei, %bi
198 %guard = icmp ult i32 0, %cnt
199 br i1 %guard, label %preheader, label %exit
205 %p.01.us.us = phi i8* [ null, %preheader ], [ %gep, %loop ]
206 %iv = phi i32 [ 0, %preheader ], [ %ivnext, %loop ]
207 %s = phi i8 [0, %preheader], [%snext, %loop]
208 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1
209 %snext = load i8, i8* %gep
210 %ivnext = add i32 %iv, 1
211 %cmp = icmp ult i32 %ivnext, %cnt
212 br i1 %cmp, label %loop, label %exit
215 %ret = phi i8 [0, %loopguard], [%snext, %loop]
219 define i8 @testptrint(i8* %buf, i8* %end) nounwind {
220 ; PTR64-LABEL: @testptrint(
221 ; PTR64-NEXT: br label [[LOOPGUARD:%.*]]
223 ; PTR64-NEXT: [[BI:%.*]] = ptrtoint i8* [[BUF:%.*]] to i32
224 ; PTR64-NEXT: [[EI:%.*]] = ptrtoint i8* [[END:%.*]] to i32
225 ; PTR64-NEXT: [[CNT:%.*]] = sub i32 [[EI]], [[BI]]
226 ; PTR64-NEXT: [[GUARD:%.*]] = icmp ult i32 [[BI]], [[CNT]]
227 ; PTR64-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
229 ; PTR64-NEXT: br label [[LOOP:%.*]]
231 ; PTR64-NEXT: [[P_01_US_US:%.*]] = phi i8* [ [[BUF]], [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
232 ; PTR64-NEXT: [[IV:%.*]] = phi i32 [ [[BI]], [[PREHEADER]] ], [ [[IVNEXT:%.*]], [[LOOP]] ]
233 ; PTR64-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
234 ; PTR64-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
235 ; PTR64-NEXT: [[IVNEXT]] = add nuw i32 [[IV]], 1
236 ; PTR64-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[IVNEXT]], [[CNT]]
237 ; PTR64-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
238 ; PTR64: exit.loopexit:
239 ; PTR64-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
240 ; PTR64-NEXT: br label [[EXIT]]
242 ; PTR64-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
243 ; PTR64-NEXT: ret i8 [[RET]]
245 ; PTR32-LABEL: @testptrint(
246 ; PTR32-NEXT: br label [[LOOPGUARD:%.*]]
248 ; PTR32-NEXT: [[BI:%.*]] = ptrtoint i8* [[BUF:%.*]] to i32
249 ; PTR32-NEXT: [[EI:%.*]] = ptrtoint i8* [[END:%.*]] to i32
250 ; PTR32-NEXT: [[CNT:%.*]] = sub i32 [[EI]], [[BI]]
251 ; PTR32-NEXT: [[GUARD:%.*]] = icmp ult i32 [[BI]], [[CNT]]
252 ; PTR32-NEXT: br i1 [[GUARD]], label [[PREHEADER:%.*]], label [[EXIT:%.*]]
254 ; PTR32-NEXT: br label [[LOOP:%.*]]
256 ; PTR32-NEXT: [[P_01_US_US:%.*]] = phi i8* [ [[BUF]], [[PREHEADER]] ], [ [[GEP:%.*]], [[LOOP]] ]
257 ; PTR32-NEXT: [[IV:%.*]] = phi i32 [ [[BI]], [[PREHEADER]] ], [ [[IVNEXT:%.*]], [[LOOP]] ]
258 ; PTR32-NEXT: [[GEP]] = getelementptr inbounds i8, i8* [[P_01_US_US]], i64 1
259 ; PTR32-NEXT: [[SNEXT:%.*]] = load i8, i8* [[GEP]]
260 ; PTR32-NEXT: [[IVNEXT]] = add nuw i32 [[IV]], 1
261 ; PTR32-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[IVNEXT]], [[CNT]]
262 ; PTR32-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
263 ; PTR32: exit.loopexit:
264 ; PTR32-NEXT: [[SNEXT_LCSSA:%.*]] = phi i8 [ [[SNEXT]], [[LOOP]] ]
265 ; PTR32-NEXT: br label [[EXIT]]
267 ; PTR32-NEXT: [[RET:%.*]] = phi i8 [ 0, [[LOOPGUARD]] ], [ [[SNEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
268 ; PTR32-NEXT: ret i8 [[RET]]
273 %bi = ptrtoint i8* %buf to i32
274 %ei = ptrtoint i8* %end to i32
275 %cnt = sub i32 %ei, %bi
276 %guard = icmp ult i32 %bi, %cnt
277 br i1 %guard, label %preheader, label %exit
283 %p.01.us.us = phi i8* [ %buf, %preheader ], [ %gep, %loop ]
284 %iv = phi i32 [ %bi, %preheader ], [ %ivnext, %loop ]
285 %s = phi i8 [0, %preheader], [%snext, %loop]
286 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1
287 %snext = load i8, i8* %gep
288 %ivnext = add i32 %iv, 1
289 %cmp = icmp ult i32 %ivnext, %cnt
290 br i1 %cmp, label %loop, label %exit
293 %ret = phi i8 [0, %loopguard], [%snext, %loop]
297 ; IV and BECount have two different pointer types here.
298 define void @testnullptr([512 x i8]* %base) nounwind {
299 ; PTR64-LABEL: @testnullptr(
301 ; PTR64-NEXT: [[ADD_PTR1603:%.*]] = getelementptr [512 x i8], [512 x i8]* [[BASE:%.*]], i64 0, i64 512
302 ; PTR64-NEXT: br label [[PREHEADER:%.*]]
304 ; PTR64-NEXT: [[CMP1604192:%.*]] = icmp ult i8* undef, [[ADD_PTR1603]]
305 ; PTR64-NEXT: br i1 [[CMP1604192]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END1609:%.*]]
306 ; PTR64: for.body.preheader:
307 ; PTR64-NEXT: br label [[FOR_BODY:%.*]]
309 ; PTR64-NEXT: [[R_17193:%.*]] = phi i8* [ [[INCDEC_PTR1608:%.*]], [[FOR_BODY]] ], [ null, [[FOR_BODY_PREHEADER]] ]
310 ; PTR64-NEXT: [[INCDEC_PTR1608]] = getelementptr i8, i8* [[R_17193]], i64 1
311 ; PTR64-NEXT: [[CMP1604:%.*]] = icmp ult i8* [[INCDEC_PTR1608]], [[ADD_PTR1603]]
312 ; PTR64-NEXT: br i1 [[CMP1604]], label [[FOR_BODY]], label [[FOR_END1609_LOOPEXIT:%.*]]
313 ; PTR64: for.end1609.loopexit:
314 ; PTR64-NEXT: br label [[FOR_END1609]]
315 ; PTR64: for.end1609:
316 ; PTR64-NEXT: unreachable
318 ; PTR32-LABEL: @testnullptr(
320 ; PTR32-NEXT: [[ADD_PTR1603:%.*]] = getelementptr [512 x i8], [512 x i8]* [[BASE:%.*]], i64 0, i64 512
321 ; PTR32-NEXT: br label [[PREHEADER:%.*]]
323 ; PTR32-NEXT: [[CMP1604192:%.*]] = icmp ult i8* undef, [[ADD_PTR1603]]
324 ; PTR32-NEXT: br i1 [[CMP1604192]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END1609:%.*]]
325 ; PTR32: for.body.preheader:
326 ; PTR32-NEXT: br label [[FOR_BODY:%.*]]
328 ; PTR32-NEXT: [[R_17193:%.*]] = phi i8* [ [[INCDEC_PTR1608:%.*]], [[FOR_BODY]] ], [ null, [[FOR_BODY_PREHEADER]] ]
329 ; PTR32-NEXT: [[INCDEC_PTR1608]] = getelementptr i8, i8* [[R_17193]], i64 1
330 ; PTR32-NEXT: [[CMP1604:%.*]] = icmp ult i8* [[INCDEC_PTR1608]], [[ADD_PTR1603]]
331 ; PTR32-NEXT: br i1 [[CMP1604]], label [[FOR_BODY]], label [[FOR_END1609_LOOPEXIT:%.*]]
332 ; PTR32: for.end1609.loopexit:
333 ; PTR32-NEXT: br label [[FOR_END1609]]
334 ; PTR32: for.end1609:
335 ; PTR32-NEXT: unreachable
338 %add.ptr1603 = getelementptr [512 x i8], [512 x i8]* %base, i64 0, i64 512
342 %cmp1604192 = icmp ult i8* undef, %add.ptr1603
343 br i1 %cmp1604192, label %for.body, label %for.end1609
346 %r.17193 = phi i8* [ %incdec.ptr1608, %for.body ], [ null, %preheader ]
347 %incdec.ptr1608 = getelementptr i8, i8* %r.17193, i64 1
348 %cmp1604 = icmp ult i8* %incdec.ptr1608, %add.ptr1603
349 br i1 %cmp1604, label %for.body, label %for.end1609