1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt -disable-output "-passes=print<scalar-evolution>" -S < %s 2>&1 | FileCheck %s
4 define i16 @test1(i8 %x) {
6 ; CHECK-NEXT: Classifying expressions for: @test1
7 ; CHECK-NEXT: %A = zext i8 %x to i12
8 ; CHECK-NEXT: --> (zext i8 %x to i12) U: [0,256) S: [0,256)
9 ; CHECK-NEXT: %B = sext i12 %A to i16
10 ; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256)
11 ; CHECK-NEXT: Determining loop execution counts for: @test1
13 %A = zext i8 %x to i12
14 %B = sext i12 %A to i16
18 define i8 @test2(i8 %x) {
19 ; CHECK-LABEL: 'test2'
20 ; CHECK-NEXT: Classifying expressions for: @test2
21 ; CHECK-NEXT: %A = zext i8 %x to i16
22 ; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256)
23 ; CHECK-NEXT: %B = add i16 %A, 1025
24 ; CHECK-NEXT: --> (1025 + (zext i8 %x to i16))<nuw><nsw> U: [1025,1281) S: [1025,1281)
25 ; CHECK-NEXT: %C = trunc i16 %B to i8
26 ; CHECK-NEXT: --> (1 + %x) U: full-set S: full-set
27 ; CHECK-NEXT: Determining loop execution counts for: @test2
29 %A = zext i8 %x to i16
31 %C = trunc i16 %B to i8
35 define i8 @test3(i8 %x) {
36 ; CHECK-LABEL: 'test3'
37 ; CHECK-NEXT: Classifying expressions for: @test3
38 ; CHECK-NEXT: %A = zext i8 %x to i16
39 ; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256)
40 ; CHECK-NEXT: %B = mul i16 %A, 1027
41 ; CHECK-NEXT: --> (1027 * (zext i8 %x to i16)) U: full-set S: full-set
42 ; CHECK-NEXT: %C = trunc i16 %B to i8
43 ; CHECK-NEXT: --> (3 * %x) U: full-set S: full-set
44 ; CHECK-NEXT: Determining loop execution counts for: @test3
46 %A = zext i8 %x to i16
48 %C = trunc i16 %B to i8
52 define void @test4(i32 %x, i32 %y) {
53 ; CHECK-LABEL: 'test4'
54 ; CHECK-NEXT: Classifying expressions for: @test4
55 ; CHECK-NEXT: %Y = and i32 %y, 3
56 ; CHECK-NEXT: --> (zext i2 (trunc i32 %y to i2) to i32) U: [0,4) S: [0,4)
57 ; CHECK-NEXT: %A = phi i32 [ 0, %entry ], [ %I, %loop ]
58 ; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
59 ; CHECK-NEXT: %Z1 = select i1 %rand1, i32 %A, i32 %Y
60 ; CHECK-NEXT: --> ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
61 ; CHECK-NEXT: %Z2 = select i1 %rand2, i32 %A, i32 %Z1
62 ; CHECK-NEXT: --> ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
63 ; CHECK-NEXT: %B = trunc i32 %Z2 to i16
64 ; CHECK-NEXT: --> (trunc i32 ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) to i16) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
65 ; CHECK-NEXT: %C = sext i16 %B to i30
66 ; CHECK-NEXT: --> (trunc i32 ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) to i30) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
67 ; CHECK-NEXT: %D = sext i16 %B to i32
68 ; CHECK-NEXT: --> ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
69 ; CHECK-NEXT: %E = sext i16 %B to i34
70 ; CHECK-NEXT: --> ((zext i32 ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>) to i34) umax {0,+,1}<nuw><nsw><%loop>) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
71 ; CHECK-NEXT: %F = zext i16 %B to i30
72 ; CHECK-NEXT: --> (trunc i32 ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) to i30) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
73 ; CHECK-NEXT: %G = zext i16 %B to i32
74 ; CHECK-NEXT: --> ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
75 ; CHECK-NEXT: %H = zext i16 %B to i34
76 ; CHECK-NEXT: --> ((zext i32 ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>) to i34) umax {0,+,1}<nuw><nsw><%loop>) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable }
77 ; CHECK-NEXT: %I = add i32 %A, 1
78 ; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,22) S: [1,22) Exits: 21 LoopDispositions: { %loop: Computable }
79 ; CHECK-NEXT: Determining loop execution counts for: @test4
80 ; CHECK-NEXT: Loop %loop: backedge-taken count is 20
81 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 20
82 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 20
83 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 20
84 ; CHECK-NEXT: Predicates:
85 ; CHECK-NEXT: Loop %loop: Trip multiple is 21
91 %A = phi i32 [0, %entry], [%I, %loop]
92 %rand1 = icmp sgt i32 %A, %Y
93 %Z1 = select i1 %rand1, i32 %A, i32 %Y
94 %rand2 = icmp ugt i32 %A, %Z1
95 %Z2 = select i1 %rand2, i32 %A, i32 %Z1
96 %B = trunc i32 %Z2 to i16
97 %C = sext i16 %B to i30
98 %D = sext i16 %B to i32
99 %E = sext i16 %B to i34
100 %F = zext i16 %B to i30
101 %G = zext i16 %B to i32
102 %H = zext i16 %B to i34
104 %0 = icmp ne i32 %A, 20
105 br i1 %0, label %loop, label %exit
110 define void @test5(i32 %i) {
111 ; CHECK-LABEL: 'test5'
112 ; CHECK-NEXT: Classifying expressions for: @test5
113 ; CHECK-NEXT: %A = and i32 %i, 1
114 ; CHECK-NEXT: --> (zext i1 (trunc i32 %i to i1) to i32) U: [0,2) S: [0,2)
115 ; CHECK-NEXT: %B = and i32 %i, 2
116 ; CHECK-NEXT: --> (2 * (zext i1 (trunc i32 (%i /u 2) to i1) to i32))<nuw><nsw> U: [0,3) S: [0,3)
117 ; CHECK-NEXT: %C = and i32 %i, 63
118 ; CHECK-NEXT: --> (zext i6 (trunc i32 %i to i6) to i32) U: [0,64) S: [0,64)
119 ; CHECK-NEXT: %D = and i32 %i, 126
120 ; CHECK-NEXT: --> (2 * (zext i6 (trunc i32 (%i /u 2) to i6) to i32))<nuw><nsw> U: [0,127) S: [0,127)
121 ; CHECK-NEXT: %E = and i32 %i, 64
122 ; CHECK-NEXT: --> (64 * (zext i1 (trunc i32 (%i /u 64) to i1) to i32))<nuw><nsw> U: [0,65) S: [0,65)
123 ; CHECK-NEXT: %F = and i32 %i, -2147483648
124 ; CHECK-NEXT: --> (-2147483648 * (%i /u -2147483648))<nuw><nsw> U: [0,-2147483647) S: [-2147483648,1)
125 ; CHECK-NEXT: Determining loop execution counts for: @test5
132 %F = and i32 %i, -2147483648
136 define void @test6(i8 %x) {
137 ; CHECK-LABEL: 'test6'
138 ; CHECK-NEXT: Classifying expressions for: @test6
139 ; CHECK-NEXT: %A = zext i8 %x to i16
140 ; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256)
141 ; CHECK-NEXT: %B = shl nuw i16 %A, 8
142 ; CHECK-NEXT: --> (256 * (zext i8 %x to i16))<nuw> U: [0,-255) S: [-32768,32513)
143 ; CHECK-NEXT: %C = and i16 %B, -2048
144 ; CHECK-NEXT: --> (2048 * ((zext i8 %x to i16) /u 8))<nuw> U: [0,-2047) S: [-32768,30721)
145 ; CHECK-NEXT: Determining loop execution counts for: @test6
147 %A = zext i8 %x to i16
148 %B = shl nuw i16 %A, 8
149 %C = and i16 %B, -2048
154 define void @test7(i32 %A) {
155 ; CHECK-LABEL: 'test7'
156 ; CHECK-NEXT: Classifying expressions for: @test7
157 ; CHECK-NEXT: %B = sext i32 %A to i64
158 ; CHECK-NEXT: --> (sext i32 %A to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
159 ; CHECK-NEXT: %C = zext i32 %A to i64
160 ; CHECK-NEXT: --> (zext i32 %A to i64) U: [0,4294967296) S: [0,4294967296)
161 ; CHECK-NEXT: %D = sub i64 %B, %C
162 ; CHECK-NEXT: --> ((sext i32 %A to i64) + (-1 * (zext i32 %A to i64))<nsw>) U: [-6442450943,2147483648) S: [-6442450943,2147483648)
163 ; CHECK-NEXT: %E = trunc i64 %D to i16
164 ; CHECK-NEXT: --> 0 U: [0,1) S: [0,1)
165 ; CHECK-NEXT: Determining loop execution counts for: @test7
167 %B = sext i32 %A to i64
168 %C = zext i32 %A to i64
170 %E = trunc i64 %D to i16
174 define i64 @test8(i64 %a) {
175 ; CHECK-LABEL: 'test8'
176 ; CHECK-NEXT: Classifying expressions for: @test8
177 ; CHECK-NEXT: %t0 = udiv i64 %a, 56
178 ; CHECK-NEXT: --> (%a /u 56) U: [0,329406144173384851) S: [0,329406144173384851)
179 ; CHECK-NEXT: %t1 = udiv i64 %t0, 56
180 ; CHECK-NEXT: --> (%a /u 3136) U: [0,5882252574524730) S: [0,5882252574524730)
181 ; CHECK-NEXT: Determining loop execution counts for: @test8
183 %t0 = udiv i64 %a, 56
184 %t1 = udiv i64 %t0, 56
188 define i64 @test9(i64 %a) {
189 ; CHECK-LABEL: 'test9'
190 ; CHECK-NEXT: Classifying expressions for: @test9
191 ; CHECK-NEXT: %t0 = udiv i64 %a, 100000000000000
192 ; CHECK-NEXT: --> (%a /u 100000000000000) U: [0,184468) S: [0,184468)
193 ; CHECK-NEXT: %t1 = udiv i64 %t0, 100000000000000
194 ; CHECK-NEXT: --> 0 U: [0,1) S: [0,1)
195 ; CHECK-NEXT: Determining loop execution counts for: @test9
197 %t0 = udiv i64 %a, 100000000000000
198 %t1 = udiv i64 %t0, 100000000000000
202 define i64 @test10(i64 %a, i64 %b) {
203 ; CHECK-LABEL: 'test10'
204 ; CHECK-NEXT: Classifying expressions for: @test10
205 ; CHECK-NEXT: %t0 = udiv i64 %a, 100000000000000
206 ; CHECK-NEXT: --> (%a /u 100000000000000) U: [0,184468) S: [0,184468)
207 ; CHECK-NEXT: %t1 = udiv i64 %t0, 100000000000000
208 ; CHECK-NEXT: --> 0 U: [0,1) S: [0,1)
209 ; CHECK-NEXT: %t2 = mul i64 %b, %t1
210 ; CHECK-NEXT: --> 0 U: [0,1) S: [0,1)
211 ; CHECK-NEXT: Determining loop execution counts for: @test10
213 %t0 = udiv i64 %a, 100000000000000
214 %t1 = udiv i64 %t0, 100000000000000
215 %t2 = mul i64 %b, %t1
219 define i64 @test11(i64 %a) {
220 ; CHECK-LABEL: 'test11'
221 ; CHECK-NEXT: Classifying expressions for: @test11
222 ; CHECK-NEXT: %t0 = udiv i64 0, %a
223 ; CHECK-NEXT: --> 0 U: [0,1) S: [0,1)
224 ; CHECK-NEXT: Determining loop execution counts for: @test11