1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
6 define void @f0(ptr %len_addr) {
8 ; CHECK-NEXT: Classifying expressions for: @f0
9 ; CHECK-NEXT: %len = load i8, ptr %len_addr, align 1, !range !0
10 ; CHECK-NEXT: --> %len U: [0,127) S: [0,127)
11 ; CHECK-NEXT: %len_norange = load i8, ptr %len_addr, align 1
12 ; CHECK-NEXT: --> %len_norange U: full-set S: full-set
13 ; CHECK-NEXT: %t0 = add i8 %len, 1
14 ; CHECK-NEXT: --> (1 + %len)<nuw><nsw> U: [1,-128) S: [1,-128)
15 ; CHECK-NEXT: %t1 = add i8 %len, 2
16 ; CHECK-NEXT: --> (2 + %len)<nuw> U: [2,-127) S: [2,-127)
17 ; CHECK-NEXT: %t2 = sub i8 %len, 1
18 ; CHECK-NEXT: --> (-1 + %len)<nsw> U: [-1,126) S: [-1,126)
19 ; CHECK-NEXT: %t3 = sub i8 %len, 2
20 ; CHECK-NEXT: --> (-2 + %len)<nsw> U: [-2,125) S: [-2,125)
21 ; CHECK-NEXT: %q0 = add i8 %len_norange, 1
22 ; CHECK-NEXT: --> (1 + %len_norange) U: full-set S: full-set
23 ; CHECK-NEXT: %q1 = add i8 %len_norange, 2
24 ; CHECK-NEXT: --> (2 + %len_norange) U: full-set S: full-set
25 ; CHECK-NEXT: %q2 = sub i8 %len_norange, 1
26 ; CHECK-NEXT: --> (-1 + %len_norange) U: full-set S: full-set
27 ; CHECK-NEXT: %q3 = sub i8 %len_norange, 2
28 ; CHECK-NEXT: --> (-2 + %len_norange) U: full-set S: full-set
29 ; CHECK-NEXT: Determining loop execution counts for: @f0
32 %len = load i8, ptr %len_addr, !range !0
33 %len_norange = load i8, ptr %len_addr
41 %q0 = add i8 %len_norange, 1
42 %q1 = add i8 %len_norange, 2
44 %q2 = sub i8 %len_norange, 1
45 %q3 = sub i8 %len_norange, 2
50 define void @f1(ptr %len_addr) {
52 ; CHECK-NEXT: Classifying expressions for: @f1
53 ; CHECK-NEXT: %len = load i8, ptr %len_addr, align 1, !range !0
54 ; CHECK-NEXT: --> %len U: [0,127) S: [0,127)
55 ; CHECK-NEXT: %len_norange = load i8, ptr %len_addr, align 1
56 ; CHECK-NEXT: --> %len_norange U: full-set S: full-set
57 ; CHECK-NEXT: %t0 = add i8 %len, -1
58 ; CHECK-NEXT: --> (-1 + %len)<nsw> U: [-1,126) S: [-1,126)
59 ; CHECK-NEXT: %t1 = add i8 %len, -2
60 ; CHECK-NEXT: --> (-2 + %len)<nsw> U: [-2,125) S: [-2,125)
61 ; CHECK-NEXT: %t0.sext = sext i8 %t0 to i16
62 ; CHECK-NEXT: --> (-1 + (zext i8 %len to i16))<nsw> U: [-1,126) S: [-1,126)
63 ; CHECK-NEXT: %t1.sext = sext i8 %t1 to i16
64 ; CHECK-NEXT: --> (-2 + (zext i8 %len to i16))<nsw> U: [-2,125) S: [-2,125)
65 ; CHECK-NEXT: %q0 = add i8 %len_norange, 1
66 ; CHECK-NEXT: --> (1 + %len_norange) U: full-set S: full-set
67 ; CHECK-NEXT: %q1 = add i8 %len_norange, 2
68 ; CHECK-NEXT: --> (2 + %len_norange) U: full-set S: full-set
69 ; CHECK-NEXT: %q0.sext = sext i8 %q0 to i16
70 ; CHECK-NEXT: --> (sext i8 (1 + %len_norange) to i16) U: [-128,128) S: [-128,128)
71 ; CHECK-NEXT: %q1.sext = sext i8 %q1 to i16
72 ; CHECK-NEXT: --> (sext i8 (2 + %len_norange) to i16) U: [-128,128) S: [-128,128)
73 ; CHECK-NEXT: Determining loop execution counts for: @f1
76 %len = load i8, ptr %len_addr, !range !0
77 %len_norange = load i8, ptr %len_addr
82 %t0.sext = sext i8 %t0 to i16
83 %t1.sext = sext i8 %t1 to i16
85 %q0 = add i8 %len_norange, 1
86 %q1 = add i8 %len_norange, 2
88 %q0.sext = sext i8 %q0 to i16
89 %q1.sext = sext i8 %q1 to i16
94 define void @f2(ptr %len_addr) {
96 ; CHECK-NEXT: Classifying expressions for: @f2
97 ; CHECK-NEXT: %len = load i8, ptr %len_addr, align 1, !range !0
98 ; CHECK-NEXT: --> %len U: [0,127) S: [0,127)
99 ; CHECK-NEXT: %len_norange = load i8, ptr %len_addr, align 1
100 ; CHECK-NEXT: --> %len_norange U: full-set S: full-set
101 ; CHECK-NEXT: %t0 = add i8 %len, 1
102 ; CHECK-NEXT: --> (1 + %len)<nuw><nsw> U: [1,-128) S: [1,-128)
103 ; CHECK-NEXT: %t1 = add i8 %len, 2
104 ; CHECK-NEXT: --> (2 + %len)<nuw> U: [2,-127) S: [2,-127)
105 ; CHECK-NEXT: %t0.zext = zext i8 %t0 to i16
106 ; CHECK-NEXT: --> (1 + (zext i8 %len to i16))<nuw><nsw> U: [1,128) S: [1,128)
107 ; CHECK-NEXT: %t1.zext = zext i8 %t1 to i16
108 ; CHECK-NEXT: --> (2 + (zext i8 %len to i16))<nuw><nsw> U: [2,129) S: [2,129)
109 ; CHECK-NEXT: %q0 = add i8 %len_norange, 1
110 ; CHECK-NEXT: --> (1 + %len_norange) U: full-set S: full-set
111 ; CHECK-NEXT: %q1 = add i8 %len_norange, 2
112 ; CHECK-NEXT: --> (2 + %len_norange) U: full-set S: full-set
113 ; CHECK-NEXT: %q0.zext = zext i8 %q0 to i16
114 ; CHECK-NEXT: --> (zext i8 (1 + %len_norange) to i16) U: [0,256) S: [0,256)
115 ; CHECK-NEXT: %q1.zext = zext i8 %q1 to i16
116 ; CHECK-NEXT: --> (zext i8 (2 + %len_norange) to i16) U: [0,256) S: [0,256)
117 ; CHECK-NEXT: Determining loop execution counts for: @f2
120 %len = load i8, ptr %len_addr, !range !0
121 %len_norange = load i8, ptr %len_addr
126 %t0.zext = zext i8 %t0 to i16
127 %t1.zext = zext i8 %t1 to i16
129 %q0 = add i8 %len_norange, 1
130 %q1 = add i8 %len_norange, 2
131 %q0.zext = zext i8 %q0 to i16
132 %q1.zext = zext i8 %q1 to i16
138 @z_addr = external global [16 x i8], align 4
139 @z_addr_noalign = external global [16 x i8]
141 %union = type { [10 x [4 x float]] }
142 @tmp_addr = external unnamed_addr global { %union, [2000 x i8] }
144 define void @f3(ptr %x_addr, ptr %y_addr, ptr %tmp_addr) {
146 ; CHECK-NEXT: Classifying expressions for: @f3
147 ; CHECK-NEXT: %x = load i8, ptr %x_addr, align 1
148 ; CHECK-NEXT: --> %x U: full-set S: full-set
149 ; CHECK-NEXT: %t0 = mul i8 %x, 4
150 ; CHECK-NEXT: --> (4 * %x) U: [0,-3) S: [-128,125)
151 ; CHECK-NEXT: %t1 = add i8 %t0, 5
152 ; CHECK-NEXT: --> (5 + (4 * %x)) U: [5,2) S: [-123,-126)
153 ; CHECK-NEXT: %t1.zext = zext i8 %t1 to i16
154 ; CHECK-NEXT: --> (1 + (zext i8 (4 + (4 * %x)) to i16))<nuw><nsw> U: [1,254) S: [1,257)
155 ; CHECK-NEXT: %q0 = mul i8 %x, 4
156 ; CHECK-NEXT: --> (4 * %x) U: [0,-3) S: [-128,125)
157 ; CHECK-NEXT: %q1 = add i8 %q0, 7
158 ; CHECK-NEXT: --> (7 + (4 * %x)) U: [7,4) S: [-121,-124)
159 ; CHECK-NEXT: %q1.zext = zext i8 %q1 to i16
160 ; CHECK-NEXT: --> (3 + (zext i8 (4 + (4 * %x)) to i16))<nuw><nsw> U: [3,256) S: [3,259)
161 ; CHECK-NEXT: %p0 = mul i8 %x, 4
162 ; CHECK-NEXT: --> (4 * %x) U: [0,-3) S: [-128,125)
163 ; CHECK-NEXT: %p1 = add i8 %p0, 8
164 ; CHECK-NEXT: --> (8 + (4 * %x)) U: [0,-3) S: [-128,125)
165 ; CHECK-NEXT: %p1.zext = zext i8 %p1 to i16
166 ; CHECK-NEXT: --> (zext i8 (8 + (4 * %x)) to i16) U: [0,253) S: [0,256)
167 ; CHECK-NEXT: %r0 = mul i8 %x, 4
168 ; CHECK-NEXT: --> (4 * %x) U: [0,-3) S: [-128,125)
169 ; CHECK-NEXT: %r1 = add i8 %r0, -2
170 ; CHECK-NEXT: --> (-2 + (4 * %x)) U: [0,-1) S: [-128,127)
171 ; CHECK-NEXT: %r1.zext = zext i8 %r1 to i16
172 ; CHECK-NEXT: --> (2 + (zext i8 (-4 + (4 * %x)) to i16))<nuw><nsw> U: [2,255) S: [2,258)
173 ; CHECK-NEXT: %y = load i8, ptr %y_addr, align 1
174 ; CHECK-NEXT: --> %y U: full-set S: full-set
175 ; CHECK-NEXT: %s0 = mul i8 %x, 32
176 ; CHECK-NEXT: --> (32 * %x) U: [0,-31) S: [-128,97)
177 ; CHECK-NEXT: %s1 = mul i8 %y, 36
178 ; CHECK-NEXT: --> (36 * %y) U: [0,-3) S: [-128,125)
179 ; CHECK-NEXT: %s2 = add i8 %s0, %s1
180 ; CHECK-NEXT: --> ((32 * %x) + (36 * %y)) U: [0,-3) S: [-128,125)
181 ; CHECK-NEXT: %s3 = add i8 %s2, 5
182 ; CHECK-NEXT: --> (5 + (32 * %x) + (36 * %y)) U: full-set S: full-set
183 ; CHECK-NEXT: %s3.zext = zext i8 %s3 to i16
184 ; CHECK-NEXT: --> (1 + (zext i8 (4 + (32 * %x) + (36 * %y)) to i16))<nuw><nsw> U: [1,254) S: [1,257)
185 ; CHECK-NEXT: %ptr = bitcast ptr @z_addr to ptr
186 ; CHECK-NEXT: --> @z_addr U: [0,-3) S: [-9223372036854775808,9223372036854775805)
187 ; CHECK-NEXT: %int0 = ptrtoint ptr %ptr to i32
188 ; CHECK-NEXT: --> (trunc i64 (ptrtoint ptr @z_addr to i64) to i32) U: [0,-3) S: [-2147483648,2147483645)
189 ; CHECK-NEXT: %int5 = add i32 %int0, 5
190 ; CHECK-NEXT: --> (5 + (trunc i64 (ptrtoint ptr @z_addr to i64) to i32)) U: [5,2) S: [-2147483643,-2147483646)
191 ; CHECK-NEXT: %int.zext = zext i32 %int5 to i64
192 ; CHECK-NEXT: --> (1 + (zext i32 (4 + (trunc i64 (ptrtoint ptr @z_addr to i64) to i32)) to i64))<nuw><nsw> U: [1,4294967294) S: [1,4294967297)
193 ; CHECK-NEXT: %ptr_noalign = bitcast ptr @z_addr_noalign to ptr
194 ; CHECK-NEXT: --> @z_addr_noalign U: full-set S: full-set
195 ; CHECK-NEXT: %int0_na = ptrtoint ptr %ptr_noalign to i32
196 ; CHECK-NEXT: --> (trunc i64 (ptrtoint ptr @z_addr_noalign to i64) to i32) U: full-set S: full-set
197 ; CHECK-NEXT: %int5_na = add i32 %int0_na, 5
198 ; CHECK-NEXT: --> (5 + (trunc i64 (ptrtoint ptr @z_addr_noalign to i64) to i32)) U: full-set S: full-set
199 ; CHECK-NEXT: %int.zext_na = zext i32 %int5_na to i64
200 ; CHECK-NEXT: --> (zext i32 (5 + (trunc i64 (ptrtoint ptr @z_addr_noalign to i64) to i32)) to i64) U: [0,4294967296) S: [0,4294967296)
201 ; CHECK-NEXT: %tmp = load i32, ptr %tmp_addr, align 4
202 ; CHECK-NEXT: --> %tmp U: full-set S: full-set
203 ; CHECK-NEXT: %mul = and i32 %tmp, -4
204 ; CHECK-NEXT: --> (4 * (%tmp /u 4))<nuw> U: [0,-3) S: [-2147483648,2147483645)
205 ; CHECK-NEXT: %add4 = add i32 %mul, 4
206 ; CHECK-NEXT: --> (4 + (4 * (%tmp /u 4))<nuw>) U: [0,-3) S: [-2147483648,2147483645)
207 ; CHECK-NEXT: %add4.zext = zext i32 %add4 to i64
208 ; CHECK-NEXT: --> (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64) U: [0,4294967293) S: [0,4294967296)
209 ; CHECK-NEXT: %sunkaddr3 = mul i64 %add4.zext, 4
210 ; CHECK-NEXT: --> (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> U: [0,17179869169) S: [0,17179869181)
211 ; CHECK-NEXT: %sunkaddr4 = getelementptr inbounds i8, ptr @tmp_addr, i64 %sunkaddr3
212 ; CHECK-NEXT: --> ((4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
213 ; CHECK-NEXT: %sunkaddr5 = getelementptr inbounds i8, ptr %sunkaddr4, i64 4096
214 ; CHECK-NEXT: --> (4096 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
215 ; CHECK-NEXT: %addr4.cast = bitcast ptr %sunkaddr5 to ptr
216 ; CHECK-NEXT: --> (4096 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
217 ; CHECK-NEXT: %addr4.incr = getelementptr i32, ptr %addr4.cast, i64 1
218 ; CHECK-NEXT: --> (4100 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
219 ; CHECK-NEXT: %add5 = add i32 %mul, 5
220 ; CHECK-NEXT: --> (5 + (4 * (%tmp /u 4))<nuw>) U: [5,2) S: [-2147483643,-2147483646)
221 ; CHECK-NEXT: %add5.zext = zext i32 %add5 to i64
222 ; CHECK-NEXT: --> (1 + (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> U: [1,4294967294) S: [1,4294967297)
223 ; CHECK-NEXT: %sunkaddr0 = mul i64 %add5.zext, 4
224 ; CHECK-NEXT: --> (4 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw>)<nuw><nsw> U: [4,17179869173) S: [4,17179869185)
225 ; CHECK-NEXT: %sunkaddr1 = getelementptr inbounds i8, ptr @tmp_addr, i64 %sunkaddr0
226 ; CHECK-NEXT: --> (4 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
227 ; CHECK-NEXT: %sunkaddr2 = getelementptr inbounds i8, ptr %sunkaddr1, i64 4096
228 ; CHECK-NEXT: --> (4100 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
229 ; CHECK-NEXT: %addr5.cast = bitcast ptr %sunkaddr2 to ptr
230 ; CHECK-NEXT: --> (4100 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
231 ; CHECK-NEXT: Determining loop execution counts for: @f3
234 %x = load i8, ptr %x_addr
237 %t1.zext = zext i8 %t1 to i16
241 %q1.zext = zext i8 %q1 to i16
245 %p1.zext = zext i8 %p1 to i16
248 %r1 = add i8 %r0, 254
249 %r1.zext = zext i8 %r1 to i16
251 %y = load i8, ptr %y_addr
254 %s2 = add i8 %s0, %s1
256 %s3.zext = zext i8 %s3 to i16
258 %ptr = bitcast ptr @z_addr to ptr
259 %int0 = ptrtoint ptr %ptr to i32
260 %int5 = add i32 %int0, 5
261 %int.zext = zext i32 %int5 to i64
263 %ptr_noalign = bitcast ptr @z_addr_noalign to ptr
264 %int0_na = ptrtoint ptr %ptr_noalign to i32
265 %int5_na = add i32 %int0_na, 5
266 %int.zext_na = zext i32 %int5_na to i64
268 %tmp = load i32, ptr %tmp_addr
269 %mul = and i32 %tmp, -4
270 %add4 = add i32 %mul, 4
271 %add4.zext = zext i32 %add4 to i64
272 %sunkaddr3 = mul i64 %add4.zext, 4
273 %sunkaddr4 = getelementptr inbounds i8, ptr @tmp_addr, i64 %sunkaddr3
274 %sunkaddr5 = getelementptr inbounds i8, ptr %sunkaddr4, i64 4096
275 %addr4.cast = bitcast ptr %sunkaddr5 to ptr
276 %addr4.incr = getelementptr i32, ptr %addr4.cast, i64 1
278 %add5 = add i32 %mul, 5
279 %add5.zext = zext i32 %add5 to i64
280 %sunkaddr0 = mul i64 %add5.zext, 4
281 %sunkaddr1 = getelementptr inbounds i8, ptr @tmp_addr, i64 %sunkaddr0
282 %sunkaddr2 = getelementptr inbounds i8, ptr %sunkaddr1, i64 4096
283 %addr5.cast = bitcast ptr %sunkaddr2 to ptr
289 ; The next two tests demonstrate that (at the time of being written), SCEV
290 ; will incorrectly propagate flags from an add in one scope to an add in
291 ; another scope. Note as well that the results are visit order dependent
292 ; and (as shown in the _b variant) the printer frequently makes the actual
293 ; bug very hard to see.
294 define i1 @test2_a(i32 %a, i32 %b, i1 %will_overflow) {
295 ; CHECK-LABEL: 'test2_a'
296 ; CHECK-NEXT: Classifying expressions for: @test2_a
297 ; CHECK-NEXT: %iv = phi i32 [ %a, %entry ], [ %iv.next, %loop ]
298 ; CHECK-NEXT: --> {%a,+,%b}<nuw><nsw><%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
299 ; CHECK-NEXT: %iv.next = add nuw nsw i32 %iv, %b
300 ; CHECK-NEXT: --> {(%a + %b),+,%b}<nuw><nsw><%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
301 ; CHECK-NEXT: %trap = udiv i32 %a, %iv.next
302 ; CHECK-NEXT: --> (%a /u {(%a + %b),+,%b}<nuw><nsw><%loop>) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
303 ; CHECK-NEXT: %c = add i32 %a, %b
304 ; CHECK-NEXT: --> (%a + %b) U: full-set S: full-set
305 ; CHECK-NEXT: Determining loop execution counts for: @test2_a
306 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
307 ; CHECK-NEXT: Loop %loop: Unpredictable constant max backedge-taken count.
308 ; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count.
309 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
312 br i1 %will_overflow, label %exit1, label %loop
315 %iv = phi i32 [%a, %entry], [%iv.next, %loop]
316 %iv.next = add nuw nsw i32 %iv, %b
317 %trap = udiv i32 %a, %iv.next ;; Use to force poison -> UB
318 %ret2 = icmp ult i32 %iv.next, %a
319 ; Note: backedge is unreachable here
320 br i1 %ret2, label %loop, label %exit2
327 %ret1 = icmp ult i32 %c, %a
331 define i1 @test2_b(i32 %a, i32 %b, i1 %will_overflow) {
332 ; CHECK-LABEL: 'test2_b'
333 ; CHECK-NEXT: Classifying expressions for: @test2_b
334 ; CHECK-NEXT: %c = add i32 %a, %b
335 ; CHECK-NEXT: --> (%a + %b) U: full-set S: full-set
336 ; CHECK-NEXT: %iv = phi i32 [ %a, %entry ], [ %iv.next, %loop ]
337 ; CHECK-NEXT: --> {%a,+,%b}<nuw><nsw><%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
338 ; CHECK-NEXT: %iv.next = add nuw nsw i32 %iv, %b
339 ; CHECK-NEXT: --> {(%a + %b),+,%b}<nuw><nsw><%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
340 ; CHECK-NEXT: %trap = udiv i32 %a, %iv.next
341 ; CHECK-NEXT: --> (%a /u {(%a + %b),+,%b}<nuw><nsw><%loop>) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
342 ; CHECK-NEXT: Determining loop execution counts for: @test2_b
343 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
344 ; CHECK-NEXT: Loop %loop: Unpredictable constant max backedge-taken count.
345 ; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count.
346 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
349 br i1 %will_overflow, label %exit1, label %loop
353 %ret1 = icmp ult i32 %c, %a
357 %iv = phi i32 [%a, %entry], [%iv.next, %loop]
358 %iv.next = add nuw nsw i32 %iv, %b
359 %trap = udiv i32 %a, %iv.next
360 %ret2 = icmp ult i32 %iv.next, %a
361 ; Note: backedge is unreachable here
362 br i1 %ret2, label %loop, label %exit2