1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt -analyze -scalar-evolution %s -enable-new-pm=0 | FileCheck %s
3; RUN: opt -passes='print<scalar-evolution>' -disable-output %s 2>&1 | FileCheck %s
4
5; Tests for PR47904.
6
7define void @test_trip_multiple_4(i32 %num) {
8; CHECK-LABEL: @test_trip_multiple_4
9; CHECK:       Loop %for.body: backedge-taken count is (-1 + %num)
10; CHECK-NEXT:  Loop %for.body: max backedge-taken count is -2
11; CHECK-NEXT:  Loop %for.body: Predicated backedge-taken count is (-1 + %num)
12; CHECK:       Loop %for.body: Trip multiple is 4
13;
14entry:
15  %u = urem i32 %num, 4
16  %cmp = icmp eq i32 %u, 0
17  tail call void @llvm.assume(i1 %cmp)
18  %cmp.1 = icmp uge i32 %num, 4
19  tail call void @llvm.assume(i1 %cmp.1)
20  br label %for.body
21
22for.body:
23  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
24  %inc = add nuw nsw i32 %i.010, 1
25  %cmp2 = icmp ult i32 %inc, %num
26  br i1 %cmp2, label %for.body, label %exit
27
28exit:
29  ret void
30}
31
32define void @test_trip_multiple_5(i32 %num) {
33; CHECK-LABEL: @test_trip_multiple_5
34; CHECK:       Loop %for.body: backedge-taken count is (-1 + %num)
35; CHECK-NEXT:  Loop %for.body: max backedge-taken count is -2
36; CHECK-NEXT:  Loop %for.body: Predicated backedge-taken count is (-1 + %num)
37; CHECK:       Loop %for.body: Trip multiple is 1
38;
39entry:
40  %u = urem i32 %num, 5
41  %cmp = icmp eq i32 %u, 0
42  tail call void @llvm.assume(i1 %cmp)
43  %cmp.1 = icmp uge i32 %num, 5
44  tail call void @llvm.assume(i1 %cmp.1)
45  br label %for.body
46
47for.body:
48  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
49  %inc = add nuw nsw i32 %i.010, 1
50  %cmp2 = icmp ult i32 %inc, %num
51  br i1 %cmp2, label %for.body, label %exit
52
53exit:
54  ret void
55}
56
57define void @test_trunc_operand_larger_than_urem_expr(i64 %N) {
58; CHECK-LABEL: @test_trunc_operand_larger_than_urem_expr
59; CHECK:       Loop %for.body: backedge-taken count is (-1 + %N)
60; CHECK-NEXT:  Loop %for.body: max backedge-taken count is -1
61; CHECK-NEXT:  Loop %for.body: Predicated backedge-taken count is (-1 + %N)
62;
63entry:
64  %conv = trunc i64 %N to i32
65  %and = and i32 %conv, 1
66  %cmp.pre = icmp eq i32 %and, 0
67  br i1 %cmp.pre, label %for.body, label %exit
68
69for.body:
70  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
71  %iv.next = add nuw nsw i64 %iv, 1
72  %cmp.1 = icmp ne i64 %iv.next, %N
73  br i1 %cmp.1, label %for.body, label %exit
74
75exit:
76  ret void
77}
78
79declare void @llvm.assume(i1)
80