1; RUN: opt < %s -analyze -enable-new-pm=0 -scalar-evolution | FileCheck %s
2; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
3
4; CHECK: %tmp9 = shl i64 %tmp8, 33
5; CHECK-NEXT: --> {{.*}} Exits: (-8589934592 + (8589934592 * (zext i32 %arg2 to i64)))
6; CHECK: %tmp10 = ashr exact i64 %tmp9, 32
7; CHECK-NEXT: --> {{.*}} Exits: (sext i32 (-2 + (2 * %arg2)) to i64)
8; CHECK: %tmp11 = getelementptr inbounds i32, i32* %arg, i64 %tmp10
9; CHECK-NEXT: --> {{.*}} Exits: ((4 * (sext i32 (-2 + (2 * %arg2)) to i64))<nsw> + %arg)
10; CHECK:  %tmp14 = or i64 %tmp10, 1
11; CHECK-NEXT: --> {{.*}} Exits: (1 + (sext i32 (-2 + (2 * %arg2)) to i64))<nuw><nsw>
12; CHECK: %tmp15 = getelementptr inbounds i32, i32* %arg, i64 %tmp14
13; CHECK-NEXT: --> {{.*}} Exits: (4 + (4 * (sext i32 (-2 + (2 * %arg2)) to i64))<nsw> + %arg)
14; CHECK:Loop %bb7: backedge-taken count is (-1 + (zext i32 %arg2 to i64))<nsw>
15; CHECK-NEXT:Loop %bb7: max backedge-taken count is 2147483646
16; CHECK-NEXT:Loop %bb7: Predicated backedge-taken count is (-1 + (zext i32 %arg2 to i64))<nsw>
17
18define void @foo(i32* nocapture %arg, i32 %arg1, i32 %arg2) {
19bb:
20  %tmp = icmp sgt i32 %arg2, 0
21  br i1 %tmp, label %bb3, label %bb6
22
23bb3:                                              ; preds = %bb
24  %tmp4 = zext i32 %arg2 to i64
25  br label %bb7
26
27bb5:                                              ; preds = %bb7
28  br label %bb6
29
30bb6:                                              ; preds = %bb5, %bb
31  ret void
32
33bb7:                                              ; preds = %bb7, %bb3
34  %tmp8 = phi i64 [ %tmp18, %bb7 ], [ 0, %bb3 ]
35  %tmp9 = shl i64 %tmp8, 33
36  %tmp10 = ashr exact i64 %tmp9, 32
37  %tmp11 = getelementptr inbounds i32, i32* %arg, i64 %tmp10
38  %tmp12 = load i32, i32* %tmp11, align 4
39  %tmp13 = sub nsw i32 %tmp12, %arg1
40  store i32 %tmp13, i32* %tmp11, align 4
41  %tmp14 = or i64 %tmp10, 1
42  %tmp15 = getelementptr inbounds i32, i32* %arg, i64 %tmp14
43  %tmp16 = load i32, i32* %tmp15, align 4
44  %tmp17 = mul nsw i32 %tmp16, %arg1
45  store i32 %tmp17, i32* %tmp15, align 4
46  %tmp18 = add nuw nsw i64 %tmp8, 1
47  %tmp19 = icmp eq i64 %tmp18, %tmp4
48  br i1 %tmp19, label %bb5, label %bb7
49}
50
51; CHECK: %t10 = ashr exact i128 %t9, 1
52; CHECK-NEXT: --> {{.*}} Exits: (sext i127 (-633825300114114700748351602688 + (633825300114114700748351602688 * (zext i32 %arg5 to i127))) to i128)
53; CHECK: %t14 = or i128 %t10, 1
54; CHECK-NEXT: --> {{.*}} Exits: (1 + (sext i127 (-633825300114114700748351602688 + (633825300114114700748351602688 * (zext i32 %arg5 to i127))) to i128))<nuw><nsw>
55; CHECK: Loop %bb7: backedge-taken count is (-1 + (zext i32 %arg5 to i128))<nsw>
56; CHECK-NEXT: Loop %bb7: max backedge-taken count is 2147483646
57; CHECK-NEXT: Loop %bb7: Predicated backedge-taken count is (-1 + (zext i32 %arg5 to i128))<nsw>
58
59define void @goo(i32* nocapture %arg3, i32 %arg4, i32 %arg5) {
60bb:
61  %t = icmp sgt i32 %arg5, 0
62  br i1 %t, label %bb3, label %bb6
63
64bb3:                                              ; preds = %bb
65  %t4 = zext i32 %arg5 to i128
66  br label %bb7
67
68bb5:                                              ; preds = %bb7
69  br label %bb6
70
71bb6:                                              ; preds = %bb5, %bb
72  ret void
73
74bb7:                                              ; preds = %bb7, %bb3
75  %t8 = phi i128 [ %t18, %bb7 ], [ 0, %bb3 ]
76  %t9 = shl i128 %t8, 100
77  %t10 = ashr exact i128 %t9, 1
78  %t11 = getelementptr inbounds i32, i32* %arg3, i128 %t10
79  %t12 = load i32, i32* %t11, align 4
80  %t13 = sub nsw i32 %t12, %arg4
81  store i32 %t13, i32* %t11, align 4
82  %t14 = or i128 %t10, 1
83  %t15 = getelementptr inbounds i32, i32* %arg3, i128 %t14
84  %t16 = load i32, i32* %t15, align 4
85  %t17 = mul nsw i32 %t16, %arg4
86  store i32 %t17, i32* %t15, align 4
87  %t18 = add nuw nsw i128 %t8, 1
88  %t19 = icmp eq i128 %t18, %t4
89  br i1 %t19, label %bb5, label %bb7
90}
91