1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt -S -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
3; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
4
5!0 = !{i8 0, i8 127}
6
7define void @f0(i8* %len_addr) {
8; CHECK-LABEL: 'f0'
9; CHECK-NEXT:  Classifying expressions for: @f0
10; CHECK-NEXT:    %len = load i8, i8* %len_addr, align 1, !range !0
11; CHECK-NEXT:    --> %len U: [0,127) S: [0,127)
12; CHECK-NEXT:    %len_norange = load i8, i8* %len_addr, align 1
13; CHECK-NEXT:    --> %len_norange U: full-set S: full-set
14; CHECK-NEXT:    %t0 = add i8 %len, 1
15; CHECK-NEXT:    --> (1 + %len)<nuw><nsw> U: [1,-128) S: [1,-128)
16; CHECK-NEXT:    %t1 = add i8 %len, 2
17; CHECK-NEXT:    --> (2 + %len)<nuw> U: [2,-127) S: [2,-127)
18; CHECK-NEXT:    %t2 = sub i8 %len, 1
19; CHECK-NEXT:    --> (-1 + %len)<nsw> U: [-1,126) S: [-1,126)
20; CHECK-NEXT:    %t3 = sub i8 %len, 2
21; CHECK-NEXT:    --> (-2 + %len)<nsw> U: [-2,125) S: [-2,125)
22; CHECK-NEXT:    %q0 = add i8 %len_norange, 1
23; CHECK-NEXT:    --> (1 + %len_norange) U: full-set S: full-set
24; CHECK-NEXT:    %q1 = add i8 %len_norange, 2
25; CHECK-NEXT:    --> (2 + %len_norange) U: full-set S: full-set
26; CHECK-NEXT:    %q2 = sub i8 %len_norange, 1
27; CHECK-NEXT:    --> (-1 + %len_norange) U: full-set S: full-set
28; CHECK-NEXT:    %q3 = sub i8 %len_norange, 2
29; CHECK-NEXT:    --> (-2 + %len_norange) U: full-set S: full-set
30; CHECK-NEXT:  Determining loop execution counts for: @f0
31;
32  entry:
33  %len = load i8, i8* %len_addr, !range !0
34  %len_norange = load i8, i8* %len_addr
35
36  %t0 = add i8 %len, 1
37  %t1 = add i8 %len, 2
38
39  %t2 = sub i8 %len, 1
40  %t3 = sub i8 %len, 2
41
42  %q0 = add i8 %len_norange, 1
43  %q1 = add i8 %len_norange, 2
44
45  %q2 = sub i8 %len_norange, 1
46  %q3 = sub i8 %len_norange, 2
47
48  ret void
49}
50
51define void @f1(i8* %len_addr) {
52; CHECK-LABEL: 'f1'
53; CHECK-NEXT:  Classifying expressions for: @f1
54; CHECK-NEXT:    %len = load i8, i8* %len_addr, align 1, !range !0
55; CHECK-NEXT:    --> %len U: [0,127) S: [0,127)
56; CHECK-NEXT:    %len_norange = load i8, i8* %len_addr, align 1
57; CHECK-NEXT:    --> %len_norange U: full-set S: full-set
58; CHECK-NEXT:    %t0 = add i8 %len, -1
59; CHECK-NEXT:    --> (-1 + %len)<nsw> U: [-1,126) S: [-1,126)
60; CHECK-NEXT:    %t1 = add i8 %len, -2
61; CHECK-NEXT:    --> (-2 + %len)<nsw> U: [-2,125) S: [-2,125)
62; CHECK-NEXT:    %t0.sext = sext i8 %t0 to i16
63; CHECK-NEXT:    --> (-1 + (zext i8 %len to i16))<nsw> U: [-1,126) S: [-1,126)
64; CHECK-NEXT:    %t1.sext = sext i8 %t1 to i16
65; CHECK-NEXT:    --> (-2 + (zext i8 %len to i16))<nsw> U: [-2,125) S: [-2,125)
66; CHECK-NEXT:    %q0 = add i8 %len_norange, 1
67; CHECK-NEXT:    --> (1 + %len_norange) U: full-set S: full-set
68; CHECK-NEXT:    %q1 = add i8 %len_norange, 2
69; CHECK-NEXT:    --> (2 + %len_norange) U: full-set S: full-set
70; CHECK-NEXT:    %q0.sext = sext i8 %q0 to i16
71; CHECK-NEXT:    --> (sext i8 (1 + %len_norange) to i16) U: [-128,128) S: [-128,128)
72; CHECK-NEXT:    %q1.sext = sext i8 %q1 to i16
73; CHECK-NEXT:    --> (sext i8 (2 + %len_norange) to i16) U: [-128,128) S: [-128,128)
74; CHECK-NEXT:  Determining loop execution counts for: @f1
75;
76  entry:
77  %len = load i8, i8* %len_addr, !range !0
78  %len_norange = load i8, i8* %len_addr
79
80  %t0 = add i8 %len, -1
81  %t1 = add i8 %len, -2
82
83  %t0.sext = sext i8 %t0 to i16
84  %t1.sext = sext i8 %t1 to i16
85
86  %q0 = add i8 %len_norange, 1
87  %q1 = add i8 %len_norange, 2
88
89  %q0.sext = sext i8 %q0 to i16
90  %q1.sext = sext i8 %q1 to i16
91
92  ret void
93}
94
95define void @f2(i8* %len_addr) {
96; CHECK-LABEL: 'f2'
97; CHECK-NEXT:  Classifying expressions for: @f2
98; CHECK-NEXT:    %len = load i8, i8* %len_addr, align 1, !range !0
99; CHECK-NEXT:    --> %len U: [0,127) S: [0,127)
100; CHECK-NEXT:    %len_norange = load i8, i8* %len_addr, align 1
101; CHECK-NEXT:    --> %len_norange U: full-set S: full-set
102; CHECK-NEXT:    %t0 = add i8 %len, 1
103; CHECK-NEXT:    --> (1 + %len)<nuw><nsw> U: [1,-128) S: [1,-128)
104; CHECK-NEXT:    %t1 = add i8 %len, 2
105; CHECK-NEXT:    --> (2 + %len)<nuw> U: [2,-127) S: [2,-127)
106; CHECK-NEXT:    %t0.zext = zext i8 %t0 to i16
107; CHECK-NEXT:    --> (1 + (zext i8 %len to i16))<nuw><nsw> U: [1,128) S: [1,128)
108; CHECK-NEXT:    %t1.zext = zext i8 %t1 to i16
109; CHECK-NEXT:    --> (2 + (zext i8 %len to i16))<nuw><nsw> U: [2,129) S: [2,129)
110; CHECK-NEXT:    %q0 = add i8 %len_norange, 1
111; CHECK-NEXT:    --> (1 + %len_norange) U: full-set S: full-set
112; CHECK-NEXT:    %q1 = add i8 %len_norange, 2
113; CHECK-NEXT:    --> (2 + %len_norange) U: full-set S: full-set
114; CHECK-NEXT:    %q0.zext = zext i8 %q0 to i16
115; CHECK-NEXT:    --> (zext i8 (1 + %len_norange) to i16) U: [0,256) S: [0,256)
116; CHECK-NEXT:    %q1.zext = zext i8 %q1 to i16
117; CHECK-NEXT:    --> (zext i8 (2 + %len_norange) to i16) U: [0,256) S: [0,256)
118; CHECK-NEXT:  Determining loop execution counts for: @f2
119;
120  entry:
121  %len = load i8, i8* %len_addr, !range !0
122  %len_norange = load i8, i8* %len_addr
123
124  %t0 = add i8 %len, 1
125  %t1 = add i8 %len, 2
126
127  %t0.zext = zext i8 %t0 to i16
128  %t1.zext = zext i8 %t1 to i16
129
130  %q0 = add i8 %len_norange, 1
131  %q1 = add i8 %len_norange, 2
132  %q0.zext = zext i8 %q0 to i16
133  %q1.zext = zext i8 %q1 to i16
134
135
136  ret void
137}
138
139@z_addr = external global [16 x i8], align 4
140@z_addr_noalign = external global [16 x i8]
141
142%union = type { [10 x [4 x float]] }
143@tmp_addr = external unnamed_addr global { %union, [2000 x i8] }
144
145define void @f3(i8* %x_addr, i8* %y_addr, i32* %tmp_addr) {
146; CHECK-LABEL: 'f3'
147; CHECK-NEXT:  Classifying expressions for: @f3
148; CHECK-NEXT:    %x = load i8, i8* %x_addr, align 1
149; CHECK-NEXT:    --> %x U: full-set S: full-set
150; CHECK-NEXT:    %t0 = mul i8 %x, 4
151; CHECK-NEXT:    --> (4 * %x) U: [0,-3) S: [-128,125)
152; CHECK-NEXT:    %t1 = add i8 %t0, 5
153; CHECK-NEXT:    --> (5 + (4 * %x)) U: [5,2) S: [-123,-126)
154; CHECK-NEXT:    %t1.zext = zext i8 %t1 to i16
155; CHECK-NEXT:    --> (1 + (zext i8 (4 + (4 * %x)) to i16))<nuw><nsw> U: [1,254) S: [1,257)
156; CHECK-NEXT:    %q0 = mul i8 %x, 4
157; CHECK-NEXT:    --> (4 * %x) U: [0,-3) S: [-128,125)
158; CHECK-NEXT:    %q1 = add i8 %q0, 7
159; CHECK-NEXT:    --> (7 + (4 * %x)) U: [7,4) S: [-121,-124)
160; CHECK-NEXT:    %q1.zext = zext i8 %q1 to i16
161; CHECK-NEXT:    --> (3 + (zext i8 (4 + (4 * %x)) to i16))<nuw><nsw> U: [3,256) S: [3,259)
162; CHECK-NEXT:    %p0 = mul i8 %x, 4
163; CHECK-NEXT:    --> (4 * %x) U: [0,-3) S: [-128,125)
164; CHECK-NEXT:    %p1 = add i8 %p0, 8
165; CHECK-NEXT:    --> (8 + (4 * %x)) U: [0,-3) S: [-128,125)
166; CHECK-NEXT:    %p1.zext = zext i8 %p1 to i16
167; CHECK-NEXT:    --> (zext i8 (8 + (4 * %x)) to i16) U: [0,253) S: [0,256)
168; CHECK-NEXT:    %r0 = mul i8 %x, 4
169; CHECK-NEXT:    --> (4 * %x) U: [0,-3) S: [-128,125)
170; CHECK-NEXT:    %r1 = add i8 %r0, -2
171; CHECK-NEXT:    --> (-2 + (4 * %x)) U: [0,-1) S: [-128,127)
172; CHECK-NEXT:    %r1.zext = zext i8 %r1 to i16
173; CHECK-NEXT:    --> (2 + (zext i8 (-4 + (4 * %x)) to i16))<nuw><nsw> U: [2,255) S: [2,258)
174; CHECK-NEXT:    %y = load i8, i8* %y_addr, align 1
175; CHECK-NEXT:    --> %y U: full-set S: full-set
176; CHECK-NEXT:    %s0 = mul i8 %x, 32
177; CHECK-NEXT:    --> (32 * %x) U: [0,-31) S: [-128,97)
178; CHECK-NEXT:    %s1 = mul i8 %y, 36
179; CHECK-NEXT:    --> (36 * %y) U: [0,-3) S: [-128,125)
180; CHECK-NEXT:    %s2 = add i8 %s0, %s1
181; CHECK-NEXT:    --> ((32 * %x) + (36 * %y)) U: [0,-3) S: [-128,125)
182; CHECK-NEXT:    %s3 = add i8 %s2, 5
183; CHECK-NEXT:    --> (5 + (32 * %x) + (36 * %y)) U: full-set S: full-set
184; CHECK-NEXT:    %s3.zext = zext i8 %s3 to i16
185; CHECK-NEXT:    --> (1 + (zext i8 (4 + (32 * %x) + (36 * %y)) to i16))<nuw><nsw> U: [1,254) S: [1,257)
186; CHECK-NEXT:    %ptr = bitcast [16 x i8]* @z_addr to i8*
187; CHECK-NEXT:    --> @z_addr U: [0,-3) S: [-9223372036854775808,9223372036854775805)
188; CHECK-NEXT:    %int0 = ptrtoint i8* %ptr to i32
189; CHECK-NEXT:    --> (trunc i64 (ptrtoint [16 x i8]* @z_addr to i64) to i32) U: [0,-3) S: [-2147483648,2147483645)
190; CHECK-NEXT:    %int5 = add i32 %int0, 5
191; CHECK-NEXT:    --> (5 + (trunc i64 (ptrtoint [16 x i8]* @z_addr to i64) to i32)) U: [5,2) S: [-2147483643,-2147483646)
192; CHECK-NEXT:    %int.zext = zext i32 %int5 to i64
193; CHECK-NEXT:    --> (1 + (zext i32 (4 + (trunc i64 (ptrtoint [16 x i8]* @z_addr to i64) to i32)) to i64))<nuw><nsw> U: [1,4294967294) S: [1,4294967297)
194; CHECK-NEXT:    %ptr_noalign = bitcast [16 x i8]* @z_addr_noalign to i8*
195; CHECK-NEXT:    --> @z_addr_noalign U: full-set S: full-set
196; CHECK-NEXT:    %int0_na = ptrtoint i8* %ptr_noalign to i32
197; CHECK-NEXT:    --> (trunc i64 (ptrtoint [16 x i8]* @z_addr_noalign to i64) to i32) U: full-set S: full-set
198; CHECK-NEXT:    %int5_na = add i32 %int0_na, 5
199; CHECK-NEXT:    --> (5 + (trunc i64 (ptrtoint [16 x i8]* @z_addr_noalign to i64) to i32)) U: full-set S: full-set
200; CHECK-NEXT:    %int.zext_na = zext i32 %int5_na to i64
201; CHECK-NEXT:    --> (zext i32 (5 + (trunc i64 (ptrtoint [16 x i8]* @z_addr_noalign to i64) to i32)) to i64) U: [0,4294967296) S: [0,4294967296)
202; CHECK-NEXT:    %tmp = load i32, i32* %tmp_addr, align 4
203; CHECK-NEXT:    --> %tmp U: full-set S: full-set
204; CHECK-NEXT:    %mul = and i32 %tmp, -4
205; CHECK-NEXT:    --> (4 * (%tmp /u 4))<nuw> U: [0,-3) S: [-2147483648,2147483645)
206; CHECK-NEXT:    %add4 = add i32 %mul, 4
207; CHECK-NEXT:    --> (4 + (4 * (%tmp /u 4))<nuw>) U: [0,-3) S: [-2147483648,2147483645)
208; CHECK-NEXT:    %add4.zext = zext i32 %add4 to i64
209; CHECK-NEXT:    --> (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64) U: [0,4294967293) S: [0,4294967296)
210; CHECK-NEXT:    %sunkaddr3 = mul i64 %add4.zext, 4
211; CHECK-NEXT:    --> (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> U: [0,17179869169) S: [0,17179869181)
212; CHECK-NEXT:    %sunkaddr4 = getelementptr inbounds i8, i8* bitcast ({ %union, [2000 x i8] }* @tmp_addr to i8*), i64 %sunkaddr3
213; CHECK-NEXT:    --> ((4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr)<nuw> U: [0,-3) S: [-9223372036854775808,9223372036854775805)
214; CHECK-NEXT:    %sunkaddr5 = getelementptr inbounds i8, i8* %sunkaddr4, i64 4096
215; CHECK-NEXT:    --> (4096 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr)<nuw> U: [4096,-3) S: [-9223372036854775808,9223372036854775805)
216; CHECK-NEXT:    %addr4.cast = bitcast i8* %sunkaddr5 to i32*
217; CHECK-NEXT:    --> (4096 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr)<nuw> U: [4096,-3) S: [-9223372036854775808,9223372036854775805)
218; CHECK-NEXT:    %addr4.incr = getelementptr i32, i32* %addr4.cast, i64 1
219; CHECK-NEXT:    --> (4100 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr) U: [0,-3) S: [-9223372036854775808,9223372036854775805)
220; CHECK-NEXT:    %add5 = add i32 %mul, 5
221; CHECK-NEXT:    --> (5 + (4 * (%tmp /u 4))<nuw>) U: [5,2) S: [-2147483643,-2147483646)
222; CHECK-NEXT:    %add5.zext = zext i32 %add5 to i64
223; CHECK-NEXT:    --> (1 + (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> U: [1,4294967294) S: [1,4294967297)
224; CHECK-NEXT:    %sunkaddr0 = mul i64 %add5.zext, 4
225; CHECK-NEXT:    --> (4 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw>)<nuw><nsw> U: [4,17179869173) S: [4,17179869185)
226; CHECK-NEXT:    %sunkaddr1 = getelementptr inbounds i8, i8* bitcast ({ %union, [2000 x i8] }* @tmp_addr to i8*), i64 %sunkaddr0
227; CHECK-NEXT:    --> (4 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr)<nuw> U: [4,-3) S: [-9223372036854775808,9223372036854775805)
228; CHECK-NEXT:    %sunkaddr2 = getelementptr inbounds i8, i8* %sunkaddr1, i64 4096
229; CHECK-NEXT:    --> (4100 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr)<nuw> U: [0,-3) S: [-9223372036854775808,9223372036854775805)
230; CHECK-NEXT:    %addr5.cast = bitcast i8* %sunkaddr2 to i32*
231; CHECK-NEXT:    --> (4100 + (4 * (zext i32 (4 + (4 * (%tmp /u 4))<nuw>) to i64))<nuw><nsw> + @tmp_addr)<nuw> U: [0,-3) S: [-9223372036854775808,9223372036854775805)
232; CHECK-NEXT:  Determining loop execution counts for: @f3
233;
234  entry:
235  %x = load i8, i8* %x_addr
236  %t0 = mul i8 %x, 4
237  %t1 = add i8 %t0, 5
238  %t1.zext = zext i8 %t1 to i16
239
240  %q0 = mul i8 %x, 4
241  %q1 = add i8 %q0, 7
242  %q1.zext = zext i8 %q1 to i16
243
244  %p0 = mul i8 %x, 4
245  %p1 = add i8 %p0, 8
246  %p1.zext = zext i8 %p1 to i16
247
248  %r0 = mul i8 %x, 4
249  %r1 = add i8 %r0, 254
250  %r1.zext = zext i8 %r1 to i16
251
252  %y = load i8, i8* %y_addr
253  %s0 = mul i8 %x, 32
254  %s1 = mul i8 %y, 36
255  %s2 = add i8 %s0, %s1
256  %s3 = add i8 %s2, 5
257  %s3.zext = zext i8 %s3 to i16
258
259  %ptr = bitcast [16 x i8]* @z_addr to i8*
260  %int0 = ptrtoint i8* %ptr to i32
261  %int5 = add i32 %int0, 5
262  %int.zext = zext i32 %int5 to i64
263
264  %ptr_noalign = bitcast [16 x i8]* @z_addr_noalign to i8*
265  %int0_na = ptrtoint i8* %ptr_noalign to i32
266  %int5_na = add i32 %int0_na, 5
267  %int.zext_na = zext i32 %int5_na to i64
268
269  %tmp = load i32, i32* %tmp_addr
270  %mul = and i32 %tmp, -4
271  %add4 = add i32 %mul, 4
272  %add4.zext = zext i32 %add4 to i64
273  %sunkaddr3 = mul i64 %add4.zext, 4
274  %sunkaddr4 = getelementptr inbounds i8, i8* bitcast ({ %union, [2000 x i8] }* @tmp_addr to i8*), i64 %sunkaddr3
275  %sunkaddr5 = getelementptr inbounds i8, i8* %sunkaddr4, i64 4096
276  %addr4.cast = bitcast i8* %sunkaddr5 to i32*
277  %addr4.incr = getelementptr i32, i32* %addr4.cast, i64 1
278
279  %add5 = add i32 %mul, 5
280  %add5.zext = zext i32 %add5 to i64
281  %sunkaddr0 = mul i64 %add5.zext, 4
282  %sunkaddr1 = getelementptr inbounds i8, i8* bitcast ({ %union, [2000 x i8] }* @tmp_addr to i8*), i64 %sunkaddr0
283  %sunkaddr2 = getelementptr inbounds i8, i8* %sunkaddr1, i64 4096
284  %addr5.cast = bitcast i8* %sunkaddr2 to i32*
285
286  ret void
287}
288