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 @s32_max1(i32 %n, i32* %p) {
10 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
11 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
12 store i32 %i.0, i32* %arrayidx, align 4
13 %inc = add i32 %i.0, 1
14 %cmp = icmp slt i32 %i.0, %add
15 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 1 times
17 ; CHECK-LABEL: Determining loop execution counts for: @s32_max1
18 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((1 + %n) smax %n))
19 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 1, actual taken count either this or zero.
25 define void @s32_max2(i32 %n, i32* %p) {
31 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
32 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
33 store i32 %i.0, i32* %arrayidx, align 4
34 %inc = add i32 %i.0, 1
35 %cmp = icmp slt i32 %i.0, %add
36 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 2 times
38 ; CHECK-LABEL: Determining loop execution counts for: @s32_max2
39 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((2 + %n) smax %n))
40 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2, actual taken count either this or zero.
46 define void @s32_maxx(i32 %n, i32 %x, i32* %p) {
52 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
53 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
54 store i32 %i.0, i32* %arrayidx, align 4
55 %inc = add i32 %i.0, 1
56 %cmp = icmp slt i32 %i.0, %add
57 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or x times
59 ; CHECK-LABEL: Determining loop execution counts for: @s32_maxx
60 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((%n + %x) smax %n))
61 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is -1{{$}}
67 define void @s32_max2_unpredictable_exit(i32 %n, i32 %x, i32* %p) {
73 %i.0 = phi i32 [ %n, %entry ], [ %inc, %if.end ]
74 %cmp = icmp eq i32 %i.0, %x
75 br i1 %cmp, label %do.end, label %if.end ; unpredictable
78 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
79 store i32 %i.0, i32* %arrayidx, align 4
80 %inc = add i32 %i.0, 1
81 %cmp1 = icmp slt i32 %i.0, %add
82 br i1 %cmp1, label %do.body, label %do.end ; taken either 0 or 2 times
84 ; CHECK-LABEL: Determining loop execution counts for: @s32_max2_unpredictable_exit
85 ; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (((-1 * %n) + ((2 + %n) smax %n)) umin ((-1 * %n) + %x))
86 ; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x)
87 ; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) smax %n))
88 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}}
94 define void @u32_max1(i32 %n, i32* %p) {
100 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
101 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
102 store i32 %i.0, i32* %arrayidx, align 4
103 %inc = add i32 %i.0, 1
104 %cmp = icmp ult i32 %i.0, %add
105 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 1 times
107 ; CHECK-LABEL: Determining loop execution counts for: @u32_max1
108 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((1 + %n) umax %n))
109 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 1, actual taken count either this or zero.
115 define void @u32_max2(i32 %n, i32* %p) {
121 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
122 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
123 store i32 %i.0, i32* %arrayidx, align 4
124 %inc = add i32 %i.0, 1
125 %cmp = icmp ult i32 %i.0, %add
126 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 2 times
128 ; CHECK-LABEL: Determining loop execution counts for: @u32_max2
129 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((2 + %n) umax %n))
130 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2, actual taken count either this or zero.
136 define void @u32_maxx(i32 %n, i32 %x, i32* %p) {
138 %add = add i32 %x, %n
142 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
143 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
144 store i32 %i.0, i32* %arrayidx, align 4
145 %inc = add i32 %i.0, 1
146 %cmp = icmp ult i32 %i.0, %add
147 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or x times
149 ; CHECK-LABEL: Determining loop execution counts for: @u32_maxx
150 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((%n + %x) umax %n))
151 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is -1{{$}}
157 define void @u32_max2_unpredictable_exit(i32 %n, i32 %x, i32* %p) {
163 %i.0 = phi i32 [ %n, %entry ], [ %inc, %if.end ]
164 %cmp = icmp eq i32 %i.0, %x
165 br i1 %cmp, label %do.end, label %if.end ; unpredictable
168 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
169 store i32 %i.0, i32* %arrayidx, align 4
170 %inc = add i32 %i.0, 1
171 %cmp1 = icmp ult i32 %i.0, %add
172 br i1 %cmp1, label %do.body, label %do.end ; taken either 0 or 2 times
174 ; CHECK-LABEL: Determining loop execution counts for: @u32_max2_unpredictable_exit
175 ; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (((-1 * %n) + ((2 + %n) umax %n)) umin ((-1 * %n) + %x))
176 ; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x)
177 ; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) umax %n))
178 ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}}