xref: /llvm-project/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll (revision 8b5b294ec2cf876bc5eb5bd5fcb56ef487e36d60)
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt -passes='print<scalar-evolution>' -disable-output %s 2>&1 | FileCheck %s
3
4; Tests for PR47904.
5
6define void @test_trip_multiple_4(i32 %num) {
7; CHECK-LABEL: 'test_trip_multiple_4'
8; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4
9; CHECK-NEXT:    %u = urem i32 %num, 4
10; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
11; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
12; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
13; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
14; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
15; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4
16; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
17; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
18; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
19; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
20;
21entry:
22  %u = urem i32 %num, 4
23  %cmp = icmp eq i32 %u, 0
24  tail call void @llvm.assume(i1 %cmp)
25  %cmp.1 = icmp uge i32 %num, 4
26  tail call void @llvm.assume(i1 %cmp.1)
27  br label %for.body
28
29for.body:
30  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
31  %inc = add nuw nsw i32 %i.010, 1
32  %cmp2 = icmp ult i32 %inc, %num
33  br i1 %cmp2, label %for.body, label %exit
34
35exit:
36  ret void
37}
38
39define void @test_trip_multiple_4_guard(i32 %num) {
40; CHECK-LABEL: 'test_trip_multiple_4_guard'
41; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_guard
42; CHECK-NEXT:    %u = urem i32 %num, 4
43; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
44; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
45; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
46; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
47; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
48; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_guard
49; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
50; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
51; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
52; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
53;
54entry:
55  %u = urem i32 %num, 4
56  %cmp = icmp eq i32 %u, 0
57  call void(i1, ...) @llvm.experimental.guard(i1 %cmp) [ "deopt"() ]
58  %cmp.1 = icmp uge i32 %num, 4
59  call void(i1, ...) @llvm.experimental.guard(i1 %cmp.1) [ "deopt"() ]
60  br label %for.body
61
62for.body:
63  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
64  %inc = add nuw nsw i32 %i.010, 1
65  %cmp2 = icmp ult i32 %inc, %num
66  br i1 %cmp2, label %for.body, label %exit
67
68exit:
69  ret void
70}
71
72
73define void @test_trip_multiple_4_ugt_5(i32 %num) {
74; CHECK-LABEL: 'test_trip_multiple_4_ugt_5'
75; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_ugt_5
76; CHECK-NEXT:    %u = urem i32 %num, 4
77; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
78; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
79; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
80; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
81; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
82; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_ugt_5
83; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
84; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
85; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
86; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
87;
88entry:
89  %u = urem i32 %num, 4
90  %cmp = icmp eq i32 %u, 0
91  tail call void @llvm.assume(i1 %cmp)
92  %cmp.1 = icmp ugt i32 %num, 5
93  tail call void @llvm.assume(i1 %cmp.1)
94  br label %for.body
95
96for.body:
97  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
98  %inc = add nuw nsw i32 %i.010, 1
99  %cmp2 = icmp ult i32 %inc, %num
100  br i1 %cmp2, label %for.body, label %exit
101
102exit:
103  ret void
104}
105
106define void @test_trip_multiple_4_ugt_5_order_swapped(i32 %num) {
107; TODO: Trip multiple can be 4, it is missed due to the processing order of the assumes.
108; CHECK-LABEL: 'test_trip_multiple_4_ugt_5_order_swapped'
109; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_ugt_5_order_swapped
110; CHECK-NEXT:    %u = urem i32 %num, 4
111; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
112; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
113; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
114; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
115; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
116; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_ugt_5_order_swapped
117; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
118; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
119; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
120; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
121;
122entry:
123  %u = urem i32 %num, 4
124  %cmp.1 = icmp ugt i32 %num, 5
125  tail call void @llvm.assume(i1 %cmp.1)
126  %cmp = icmp eq i32 %u, 0
127  tail call void @llvm.assume(i1 %cmp)
128  br label %for.body
129
130for.body:
131  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
132  %inc = add nuw nsw i32 %i.010, 1
133  %cmp2 = icmp ult i32 %inc, %num
134  br i1 %cmp2, label %for.body, label %exit
135
136exit:
137  ret void
138}
139
140define void @test_trip_multiple_4_sgt_5(i32 %num) {
141; CHECK-LABEL: 'test_trip_multiple_4_sgt_5'
142; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_sgt_5
143; CHECK-NEXT:    %u = urem i32 %num, 4
144; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
145; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
146; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
147; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
148; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
149; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_sgt_5
150; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
151; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 2147483646
152; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
153; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
154;
155entry:
156  %u = urem i32 %num, 4
157  %cmp = icmp eq i32 %u, 0
158  tail call void @llvm.assume(i1 %cmp)
159  %cmp.1 = icmp sgt i32 %num, 5
160  tail call void @llvm.assume(i1 %cmp.1)
161  br label %for.body
162
163for.body:
164  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
165  %inc = add nuw nsw i32 %i.010, 1
166  %cmp2 = icmp slt i32 %inc, %num
167  br i1 %cmp2, label %for.body, label %exit
168
169exit:
170  ret void
171}
172
173define void @test_trip_multiple_4_sgt_5_order_swapped(i32 %num) {
174; TODO: Trip multiple can be 4, it is missed due to the processing order of the assumes.
175; CHECK-LABEL: 'test_trip_multiple_4_sgt_5_order_swapped'
176; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_sgt_5_order_swapped
177; CHECK-NEXT:    %u = urem i32 %num, 4
178; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
179; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
180; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
181; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
182; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
183; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_sgt_5_order_swapped
184; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
185; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 2147483646
186; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
187; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
188;
189entry:
190  %u = urem i32 %num, 4
191  %cmp.1 = icmp sgt i32 %num, 5
192  tail call void @llvm.assume(i1 %cmp.1)
193  %cmp = icmp eq i32 %u, 0
194  tail call void @llvm.assume(i1 %cmp)
195  br label %for.body
196
197for.body:
198  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
199  %inc = add nuw nsw i32 %i.010, 1
200  %cmp2 = icmp slt i32 %inc, %num
201  br i1 %cmp2, label %for.body, label %exit
202
203exit:
204  ret void
205}
206
207define void @test_trip_multiple_4_uge_5(i32 %num) {
208; CHECK-LABEL: 'test_trip_multiple_4_uge_5'
209; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_uge_5
210; CHECK-NEXT:    %u = urem i32 %num, 4
211; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
212; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
213; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
214; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
215; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
216; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_uge_5
217; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
218; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
219; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
220; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
221;
222entry:
223  %u = urem i32 %num, 4
224  %cmp = icmp eq i32 %u, 0
225  tail call void @llvm.assume(i1 %cmp)
226  %cmp.1 = icmp uge i32 %num, 5
227  tail call void @llvm.assume(i1 %cmp.1)
228  br label %for.body
229
230for.body:
231  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
232  %inc = add nuw nsw i32 %i.010, 1
233  %cmp2 = icmp ult i32 %inc, %num
234  br i1 %cmp2, label %for.body, label %exit
235
236exit:
237  ret void
238}
239
240define void @test_trip_multiple_4_uge_5_order_swapped(i32 %num) {
241; TODO: Trip multiple can be 4, it is missed due to the processing order of the assumes.
242; CHECK-LABEL: 'test_trip_multiple_4_uge_5_order_swapped'
243; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_uge_5_order_swapped
244; CHECK-NEXT:    %u = urem i32 %num, 4
245; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
246; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
247; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
248; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
249; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
250; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_uge_5_order_swapped
251; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
252; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
253; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
254; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
255;
256entry:
257  %u = urem i32 %num, 4
258  %cmp = icmp eq i32 %u, 0
259  %cmp.1 = icmp uge i32 %num, 5
260  tail call void @llvm.assume(i1 %cmp.1)
261  tail call void @llvm.assume(i1 %cmp)
262  br label %for.body
263
264for.body:
265  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
266  %inc = add nuw nsw i32 %i.010, 1
267  %cmp2 = icmp ult i32 %inc, %num
268  br i1 %cmp2, label %for.body, label %exit
269
270exit:
271  ret void
272}
273
274define void @test_trip_multiple_4_sge_5(i32 %num) {
275; TODO: Trip multiple can be 4, it is missed due to the processing order of the assumes.
276; CHECK-LABEL: 'test_trip_multiple_4_sge_5'
277; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_sge_5
278; CHECK-NEXT:    %u = urem i32 %num, 4
279; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
280; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
281; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
282; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
283; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
284; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_sge_5
285; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
286; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 2147483646
287; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
288; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
289;
290entry:
291  %u = urem i32 %num, 4
292  %cmp = icmp eq i32 %u, 0
293  tail call void @llvm.assume(i1 %cmp)
294  %cmp.1 = icmp sge i32 %num, 5
295  tail call void @llvm.assume(i1 %cmp.1)
296  br label %for.body
297
298for.body:
299  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
300  %inc = add nuw nsw i32 %i.010, 1
301  %cmp2 = icmp slt i32 %inc, %num
302  br i1 %cmp2, label %for.body, label %exit
303
304exit:
305  ret void
306}
307
308define void @test_trip_multiple_4_sge_5_order_swapped(i32 %num) {
309; CHECK-LABEL: 'test_trip_multiple_4_sge_5_order_swapped'
310; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_sge_5_order_swapped
311; CHECK-NEXT:    %u = urem i32 %num, 4
312; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
313; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
314; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
315; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
316; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
317; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_sge_5_order_swapped
318; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
319; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 2147483646
320; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
321; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
322;
323entry:
324  %u = urem i32 %num, 4
325  %cmp = icmp eq i32 %u, 0
326  %cmp.1 = icmp sge i32 %num, 5
327  tail call void @llvm.assume(i1 %cmp.1)
328  tail call void @llvm.assume(i1 %cmp)
329  br label %for.body
330
331for.body:
332  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
333  %inc = add nuw nsw i32 %i.010, 1
334  %cmp2 = icmp slt i32 %inc, %num
335  br i1 %cmp2, label %for.body, label %exit
336
337exit:
338  ret void
339}
340
341; Same as @test_trip_multiple_4 but with the icmp operands swapped.
342define void @test_trip_multiple_4_icmp_ops_swapped(i32 %num) {
343; CHECK-LABEL: 'test_trip_multiple_4_icmp_ops_swapped'
344; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_icmp_ops_swapped
345; CHECK-NEXT:    %u = urem i32 %num, 4
346; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
347; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
348; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
349; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
350; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
351; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_icmp_ops_swapped
352; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
353; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
354; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
355; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
356;
357entry:
358  %u = urem i32 %num, 4
359  %cmp = icmp eq i32 0, %u
360  tail call void @llvm.assume(i1 %cmp)
361  %cmp.1 = icmp uge i32 %num, 4
362  tail call void @llvm.assume(i1 %cmp.1)
363  br label %for.body
364
365for.body:
366  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
367  %inc = add nuw nsw i32 %i.010, 1
368  %cmp2 = icmp ult i32 %inc, %num
369  br i1 %cmp2, label %for.body, label %exit
370
371exit:
372  ret void
373}
374
375define void @test_trip_multiple_4_upper_lower_bounds(i32 %num) {
376; CHECK-LABEL: 'test_trip_multiple_4_upper_lower_bounds'
377; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_upper_lower_bounds
378; CHECK-NEXT:    %u = urem i32 %num, 4
379; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
380; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
381; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
382; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
383; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
384; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_upper_lower_bounds
385; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
386; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
387; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
388; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
389;
390entry:
391  %cmp.1 = icmp uge i32 %num, 5
392  tail call void @llvm.assume(i1 %cmp.1)
393  %u = urem i32 %num, 4
394  %cmp = icmp eq i32 %u, 0
395  tail call void @llvm.assume(i1 %cmp)
396  %cmp.2 = icmp ult i32 %num, 59000
397  tail call void @llvm.assume(i1 %cmp.2)
398  br label %for.body
399
400for.body:
401  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
402  %inc = add nuw nsw i32 %i.010, 1
403  %cmp2 = icmp ult i32 %inc, %num
404  br i1 %cmp2, label %for.body, label %exit
405
406exit:
407  ret void
408}
409
410define void @test_trip_multiple_4_upper_lower_bounds_swapped1(i32 %num) {
411; CHECK-LABEL: 'test_trip_multiple_4_upper_lower_bounds_swapped1'
412; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_upper_lower_bounds_swapped1
413; CHECK-NEXT:    %u = urem i32 %num, 4
414; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
415; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
416; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
417; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
418; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
419; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_upper_lower_bounds_swapped1
420; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
421; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
422; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
423; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
424;
425entry:
426  %cmp.1 = icmp uge i32 %num, 5
427  tail call void @llvm.assume(i1 %cmp.1)
428  %u = urem i32 %num, 4
429  %cmp = icmp eq i32 %u, 0
430  tail call void @llvm.assume(i1 %cmp)
431  %cmp.2 = icmp ult i32 %num, 59000
432  tail call void @llvm.assume(i1 %cmp.2)
433  br label %for.body
434
435for.body:
436  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
437  %inc = add nuw nsw i32 %i.010, 1
438  %cmp2 = icmp ult i32 %inc, %num
439  br i1 %cmp2, label %for.body, label %exit
440
441exit:
442  ret void
443}
444
445define void @test_trip_multiple_4_upper_lower_bounds_swapped2(i32 %num) {
446; CHECK-LABEL: 'test_trip_multiple_4_upper_lower_bounds_swapped2'
447; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_upper_lower_bounds_swapped2
448; CHECK-NEXT:    %u = urem i32 %num, 4
449; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
450; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
451; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
452; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
453; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
454; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_upper_lower_bounds_swapped2
455; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
456; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
457; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
458; CHECK-NEXT:  Loop %for.body: Trip multiple is 4
459;
460entry:
461  %cmp.1 = icmp uge i32 %num, 5
462  tail call void @llvm.assume(i1 %cmp.1)
463  %cmp.2 = icmp ult i32 %num, 59000
464  tail call void @llvm.assume(i1 %cmp.2)
465  %u = urem i32 %num, 4
466  %cmp = icmp eq i32 %u, 0
467  tail call void @llvm.assume(i1 %cmp)
468  br label %for.body
469
470for.body:
471  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
472  %inc = add nuw nsw i32 %i.010, 1
473  %cmp2 = icmp ult i32 %inc, %num
474  br i1 %cmp2, label %for.body, label %exit
475
476exit:
477  ret void
478}
479
480define void @test_trip_multiple_5(i32 %num) {
481; CHECK-LABEL: 'test_trip_multiple_5'
482; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_5
483; CHECK-NEXT:    %u = urem i32 %num, 5
484; CHECK-NEXT:    --> ((-5 * (%num /u 5)) + %num) U: full-set S: full-set
485; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
486; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
487; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
488; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
489; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_5
490; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
491; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
492; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
493; CHECK-NEXT:  Loop %for.body: Trip multiple is 5
494;
495entry:
496  %u = urem i32 %num, 5
497  %cmp = icmp eq i32 %u, 0
498  tail call void @llvm.assume(i1 %cmp)
499  %cmp.1 = icmp uge i32 %num, 5
500  tail call void @llvm.assume(i1 %cmp.1)
501  br label %for.body
502
503for.body:
504  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
505  %inc = add nuw nsw i32 %i.010, 1
506  %cmp2 = icmp ult i32 %inc, %num
507  br i1 %cmp2, label %for.body, label %exit
508
509exit:
510  ret void
511}
512
513define void @test_trunc_operand_larger_than_urem_expr(i64 %N) {
514; CHECK-LABEL: 'test_trunc_operand_larger_than_urem_expr'
515; CHECK-NEXT:  Classifying expressions for: @test_trunc_operand_larger_than_urem_expr
516; CHECK-NEXT:    %conv = trunc i64 %N to i32
517; CHECK-NEXT:    --> (trunc i64 %N to i32) U: full-set S: full-set
518; CHECK-NEXT:    %and = and i32 %conv, 1
519; CHECK-NEXT:    --> (zext i1 (trunc i64 %N to i1) to i32) U: [0,2) S: [0,2)
520; CHECK-NEXT:    %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
521; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-9223372036854775808) S: [0,-9223372036854775808) Exits: (-1 + %N) LoopDispositions: { %for.body: Computable }
522; CHECK-NEXT:    %iv.next = add nuw nsw i64 %iv, 1
523; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-9223372036854775808) S: [1,-9223372036854775808) Exits: %N LoopDispositions: { %for.body: Computable }
524; CHECK-NEXT:  Determining loop execution counts for: @test_trunc_operand_larger_than_urem_expr
525; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %N)
526; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i64 -1
527; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %N)
528; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
529;
530entry:
531  %conv = trunc i64 %N to i32
532  %and = and i32 %conv, 1
533  %cmp.pre = icmp eq i32 %and, 0
534  br i1 %cmp.pre, label %for.body, label %exit
535
536for.body:
537  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
538  %iv.next = add nuw nsw i64 %iv, 1
539  %cmp.1 = icmp ne i64 %iv.next, %N
540  br i1 %cmp.1, label %for.body, label %exit
541
542exit:
543  ret void
544}
545
546; TODO: Even though %num is known to divide by 4, and the loop's IV advances by 4, SCEV can't compute the trip count.
547define void @test_trip_multiple_4_vectorized_iv(i32 %num) {
548; CHECK-LABEL: 'test_trip_multiple_4_vectorized_iv'
549; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_vectorized_iv
550; CHECK-NEXT:    %u = urem i32 %num, 4
551; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
552; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
553; CHECK-NEXT:    --> {0,+,4}<%for.body> U: [0,-3) S: [-2147483648,2147483645) Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
554; CHECK-NEXT:    %inc = add i32 %i.010, 4
555; CHECK-NEXT:    --> {4,+,4}<%for.body> U: [0,-3) S: [-2147483648,2147483645) Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
556; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_vectorized_iv
557; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
558; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
559; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
560;
561entry:
562  %u = urem i32 %num, 4
563  %cmp = icmp eq i32 %u, 0
564  tail call void @llvm.assume(i1 %cmp)
565  br label %for.body
566
567for.body:
568  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
569  %inc = add i32 %i.010, 4
570  %cmp2 = icmp ult i32 %inc, %num
571  br i1 %cmp2, label %for.body, label %exit
572
573exit:
574  ret void
575}
576
577declare void @llvm.assume(i1)
578declare void @llvm.experimental.guard(i1, ...)
579