blob: 5e6cfe851011a9c6de5e6c918b488b173e798f3f [file] [log] [blame]
John Brawnecf79302016-10-18 10:10:53 +00001; RUN: opt -S -analyze -scalar-evolution < %s | FileCheck %s
2
3define void @s32_max1(i32 %n, i32* %p) {
4entry:
5 %add = add i32 %n, 1
6 br label %do.body
7
8do.body:
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
15
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))
John Brawn84b21832016-10-21 11:08:48 +000018; CHECK-NEXT: Loop %do.body: max backedge-taken count is 1, actual taken count either this or zero.
John Brawnecf79302016-10-18 10:10:53 +000019
20do.end:
21 ret void
22}
23
24define void @s32_max2(i32 %n, i32* %p) {
25entry:
26 %add = add i32 %n, 2
27 br label %do.body
28
29do.body:
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
36
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))
John Brawn84b21832016-10-21 11:08:48 +000039; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2, actual taken count either this or zero.
John Brawnecf79302016-10-18 10:10:53 +000040
41do.end:
42 ret void
43}
44
45define void @s32_maxx(i32 %n, i32 %x, i32* %p) {
46entry:
47 %add = add i32 %x, %n
48 br label %do.body
49
50do.body:
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
57
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))
John Brawn84b21832016-10-21 11:08:48 +000060; CHECK-NEXT: Loop %do.body: max backedge-taken count is -1{{$}}
John Brawnecf79302016-10-18 10:10:53 +000061
62do.end:
63 ret void
64}
65
66define void @s32_max2_unpredictable_exit(i32 %n, i32 %x, i32* %p) {
67entry:
68 %add = add i32 %n, 2
69 br label %do.body
70
71do.body:
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
75
76if.end:
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
82
83; CHECK-LABEL: Determining loop execution counts for: @s32_max2_unpredictable_exit
Max Kazantsev7094c8d2018-03-27 07:30:38 +000084; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (-1 + (-1 * ((-1 + (-1 * ((2 + %n) smax %n)) + %n) umax (-1 + (-1 * %x) + %n))))
John Brawn84b21832016-10-21 11:08:48 +000085; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}}
John Brawnecf79302016-10-18 10:10:53 +000086
87do.end:
88 ret void
89}
90
91define void @u32_max1(i32 %n, i32* %p) {
92entry:
93 %add = add i32 %n, 1
94 br label %do.body
95
96do.body:
97 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
98 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
99 store i32 %i.0, i32* %arrayidx, align 4
100 %inc = add i32 %i.0, 1
101 %cmp = icmp ult i32 %i.0, %add
102 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 1 times
103
104; CHECK-LABEL: Determining loop execution counts for: @u32_max1
105; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((1 + %n) umax %n))
John Brawn84b21832016-10-21 11:08:48 +0000106; CHECK-NEXT: Loop %do.body: max backedge-taken count is 1, actual taken count either this or zero.
John Brawnecf79302016-10-18 10:10:53 +0000107
108do.end:
109 ret void
110}
111
112define void @u32_max2(i32 %n, i32* %p) {
113entry:
114 %add = add i32 %n, 2
115 br label %do.body
116
117do.body:
118 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
119 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
120 store i32 %i.0, i32* %arrayidx, align 4
121 %inc = add i32 %i.0, 1
122 %cmp = icmp ult i32 %i.0, %add
123 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 2 times
124
125; CHECK-LABEL: Determining loop execution counts for: @u32_max2
126; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((2 + %n) umax %n))
John Brawn84b21832016-10-21 11:08:48 +0000127; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2, actual taken count either this or zero.
John Brawnecf79302016-10-18 10:10:53 +0000128
129do.end:
130 ret void
131}
132
133define void @u32_maxx(i32 %n, i32 %x, i32* %p) {
134entry:
135 %add = add i32 %x, %n
136 br label %do.body
137
138do.body:
139 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
140 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
141 store i32 %i.0, i32* %arrayidx, align 4
142 %inc = add i32 %i.0, 1
143 %cmp = icmp ult i32 %i.0, %add
144 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or x times
145
146; CHECK-LABEL: Determining loop execution counts for: @u32_maxx
147; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((%n + %x) umax %n))
John Brawn84b21832016-10-21 11:08:48 +0000148; CHECK-NEXT: Loop %do.body: max backedge-taken count is -1{{$}}
John Brawnecf79302016-10-18 10:10:53 +0000149
150do.end:
151 ret void
152}
153
154define void @u32_max2_unpredictable_exit(i32 %n, i32 %x, i32* %p) {
155entry:
156 %add = add i32 %n, 2
157 br label %do.body
158
159do.body:
160 %i.0 = phi i32 [ %n, %entry ], [ %inc, %if.end ]
161 %cmp = icmp eq i32 %i.0, %x
162 br i1 %cmp, label %do.end, label %if.end ; unpredictable
163
164if.end:
165 %arrayidx = getelementptr i32, i32* %p, i32 %i.0
166 store i32 %i.0, i32* %arrayidx, align 4
167 %inc = add i32 %i.0, 1
168 %cmp1 = icmp ult i32 %i.0, %add
169 br i1 %cmp1, label %do.body, label %do.end ; taken either 0 or 2 times
170
171; CHECK-LABEL: Determining loop execution counts for: @u32_max2_unpredictable_exit
Max Kazantsev7094c8d2018-03-27 07:30:38 +0000172; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (-1 + (-1 * ((-1 + (-1 * ((2 + %n) umax %n)) + %n) umax (-1 + (-1 * %x) + %n))))
John Brawn84b21832016-10-21 11:08:48 +0000173; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}}
John Brawnecf79302016-10-18 10:10:53 +0000174
175do.end:
176 ret void
177}