1 ; RUN: opt -S -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
2 ; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
4 define void @u_0(i8 %rhs) {
5 ; E.g.: %rhs = 255, %start = 99, backedge taken 156 times
7 %start = add i8 %rhs, 100
11 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
12 %iv.inc = add nuw i8 %iv, 1 ;; Note: this never unsigned-wraps
13 %iv.cmp = icmp ult i8 %iv, %rhs
14 br i1 %iv.cmp, label %loop, label %leave
16 ; CHECK-LABEL: Determining loop execution counts for: @u_0
17 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-100 + (-1 * %rhs) + ((100 + %rhs) umax %rhs))
18 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.
24 define void @u_1(i8 %start) {
26 ; E.g.: %start = 99, %rhs = 255, backedge taken 156 times
27 %rhs = add i8 %start, -100
31 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
32 %iv.inc = add nuw i8 %iv, 1 ;; Note: this never unsigned-wraps
33 %iv.cmp = icmp ult i8 %iv, %rhs
34 br i1 %iv.cmp, label %loop, label %leave
36 ; CHECK-LABEL: Determining loop execution counts for: @u_1
37 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + ((-100 + %start) umax %start))
38 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.
44 define void @s_0(i8 %rhs) {
46 ; E.g.: %rhs = 127, %start = -29, backedge taken 156 times
47 %start = add i8 %rhs, 100
51 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
52 %iv.inc = add nsw i8 %iv, 1 ;; Note: this never signed-wraps
53 %iv.cmp = icmp slt i8 %iv, %rhs
54 br i1 %iv.cmp, label %loop, label %leave
56 ; CHECK-LABEL: Determining loop execution counts for: @s_0
57 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-100 + (-1 * %rhs) + ((100 + %rhs) smax %rhs))
58 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.
64 define void @s_1(i8 %start) {
66 ; E.g.: start = -29, %rhs = 127, %backedge taken 156 times
67 %rhs = add i8 %start, -100
71 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
72 %iv.inc = add nsw i8 %iv, 1
73 %iv.cmp = icmp slt i8 %iv, %rhs
74 br i1 %iv.cmp, label %loop, label %leave
76 ; CHECK-LABEL: Determining loop execution counts for: @s_1
77 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + ((-100 + %start) smax %start))
78 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.
84 define void @s_2(i8 %start) {
86 %rhs = add i8 %start, -100
90 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
91 %iv.inc = add nsw i8 %iv, -1
92 %iv.cmp = icmp sgt i8 %iv, %rhs
93 br i1 %iv.cmp, label %loop, label %leave
95 ; CHECK-LABEL: Determining loop execution counts for: @s_2
96 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * ((-100 + %start) smin %start)) + %start)
97 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1