1 ; RUN: opt -S -analyze -scalar-evolution < %s | FileCheck %s
3 define void @u_0(i8 %rhs) {
4 ; E.g.: %rhs = 255, %start = 99, backedge taken 156 times
6 %start = add i8 %rhs, 100
10 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
11 %iv.inc = add nuw i8 %iv, 1 ;; Note: this never unsigned-wraps
12 %iv.cmp = icmp ult i8 %iv, %rhs
13 br i1 %iv.cmp, label %loop, label %leave
15 ; CHECK-LABEL: Determining loop execution counts for: @u_0
16 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-100 + (-1 * %rhs) + ((100 + %rhs) umax %rhs))
17 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.
23 define void @u_1(i8 %start) {
25 ; E.g.: %start = 99, %rhs = 255, backedge taken 156 times
26 %rhs = add i8 %start, -100
30 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
31 %iv.inc = add nuw i8 %iv, 1 ;; Note: this never unsigned-wraps
32 %iv.cmp = icmp ult i8 %iv, %rhs
33 br i1 %iv.cmp, label %loop, label %leave
35 ; CHECK-LABEL: Determining loop execution counts for: @u_1
36 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + ((-100 + %start) umax %start))
37 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.
43 define void @s_0(i8 %rhs) {
45 ; E.g.: %rhs = 127, %start = -29, backedge taken 156 times
46 %start = add i8 %rhs, 100
50 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
51 %iv.inc = add nsw i8 %iv, 1 ;; Note: this never signed-wraps
52 %iv.cmp = icmp slt i8 %iv, %rhs
53 br i1 %iv.cmp, label %loop, label %leave
55 ; CHECK-LABEL: Determining loop execution counts for: @s_0
56 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-100 + (-1 * %rhs) + ((100 + %rhs) smax %rhs))
57 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.
63 define void @s_1(i8 %start) {
65 ; E.g.: start = -29, %rhs = 127, %backedge taken 156 times
66 %rhs = add i8 %start, -100
70 %iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
71 %iv.inc = add nsw i8 %iv, 1
72 %iv.cmp = icmp slt i8 %iv, %rhs
73 br i1 %iv.cmp, label %loop, label %leave
75 ; CHECK-LABEL: Determining loop execution counts for: @s_1
76 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + ((-100 + %start) smax %start))
77 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -100, actual taken count either this or zero.