1 ; RUN: opt -S -analyze -scalar-evolution < %s | FileCheck %s
3 define void @s32_max1(i32 %n, i32* %p) {
9 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
10 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
11 store i32 %i.0, i32* %arrayidx, align 4
12 %inc = add i32 %i.0, 1
13 %cmp = icmp slt i32 %i.0, %add
14 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 1 times
16 ; CHECK-LABEL: Determining loop execution counts for: @s32_max1
17 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((1 + %n) smax %n))
18 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 1, actual taken count either this or zero.
24 define void @s32_max2(i32 %n, i32* %p) {
30 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
31 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
32 store i32 %i.0, i32* %arrayidx, align 4
33 %inc = add i32 %i.0, 1
34 %cmp = icmp slt i32 %i.0, %add
35 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 2 times
37 ; CHECK-LABEL: Determining loop execution counts for: @s32_max2
38 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((2 + %n) smax %n))
39 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2, actual taken count either this or zero.
45 define void @s32_maxx(i32 %n, i32 %x, i32* %p) {
51 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
52 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
53 store i32 %i.0, i32* %arrayidx, align 4
54 %inc = add i32 %i.0, 1
55 %cmp = icmp slt i32 %i.0, %add
56 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or x times
58 ; CHECK-LABEL: Determining loop execution counts for: @s32_maxx
59 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((%n + %x) smax %n))
60 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is -1{{$}}
66 define void @s32_max2_unpredictable_exit(i32 %n, i32 %x, i32* %p) {
72 %i.0 = phi i32 [ %n, %entry ], [ %inc, %if.end ]
73 %cmp = icmp eq i32 %i.0, %x
74 br i1 %cmp, label %do.end, label %if.end ; unpredictable
77 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
78 store i32 %i.0, i32* %arrayidx, align 4
79 %inc = add i32 %i.0, 1
80 %cmp1 = icmp slt i32 %i.0, %add
81 br i1 %cmp1, label %do.body, label %do.end ; taken either 0 or 2 times
83 ; CHECK-LABEL: Determining loop execution counts for: @s32_max2_unpredictable_exit
84 ; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (((-1 * %n) + ((2 + %n) smax %n)) umin ((-1 * %n) + %x))
85 ; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x)
86 ; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) smax %n))
87 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}}
93 define void @u32_max1(i32 %n, i32* %p) {
99 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
100 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
101 store i32 %i.0, i32* %arrayidx, align 4
102 %inc = add i32 %i.0, 1
103 %cmp = icmp ult i32 %i.0, %add
104 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 1 times
106 ; CHECK-LABEL: Determining loop execution counts for: @u32_max1
107 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((1 + %n) umax %n))
108 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 1, actual taken count either this or zero.
114 define void @u32_max2(i32 %n, i32* %p) {
120 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
121 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
122 store i32 %i.0, i32* %arrayidx, align 4
123 %inc = add i32 %i.0, 1
124 %cmp = icmp ult i32 %i.0, %add
125 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 2 times
127 ; CHECK-LABEL: Determining loop execution counts for: @u32_max2
128 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((2 + %n) umax %n))
129 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2, actual taken count either this or zero.
135 define void @u32_maxx(i32 %n, i32 %x, i32* %p) {
137 %add = add i32 %x, %n
141 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
142 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
143 store i32 %i.0, i32* %arrayidx, align 4
144 %inc = add i32 %i.0, 1
145 %cmp = icmp ult i32 %i.0, %add
146 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or x times
148 ; CHECK-LABEL: Determining loop execution counts for: @u32_maxx
149 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((%n + %x) umax %n))
150 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is -1{{$}}
156 define void @u32_max2_unpredictable_exit(i32 %n, i32 %x, i32* %p) {
162 %i.0 = phi i32 [ %n, %entry ], [ %inc, %if.end ]
163 %cmp = icmp eq i32 %i.0, %x
164 br i1 %cmp, label %do.end, label %if.end ; unpredictable
167 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
168 store i32 %i.0, i32* %arrayidx, align 4
169 %inc = add i32 %i.0, 1
170 %cmp1 = icmp ult i32 %i.0, %add
171 br i1 %cmp1, label %do.body, label %do.end ; taken either 0 or 2 times
173 ; CHECK-LABEL: Determining loop execution counts for: @u32_max2_unpredictable_exit
174 ; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (((-1 * %n) + ((2 + %n) umax %n)) umin ((-1 * %n) + %x))
175 ; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x)
176 ; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) umax %n))
177 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}}