1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
| ; RUN: opt -mtriple=thumbv8.1m.main-arm-none-eabi -hardware-loops %s -S -o - | FileCheck %s
@g = common local_unnamed_addr global i32* null, align 4
; CHECK-LABEL: do_with_i32_urem
; CHECK: entry:
; CHECK: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %n)
; CHECK: br i1 [[TEST]], label %while.body.preheader, label %while.end
; CHECK: while.body.preheader:
; CHECK-NEXT: br label %while.body
; CHECK: while.body:
; CHECK: [[REM:%[^ ]+]] = phi i32 [ %n, %while.body.preheader ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
define i32 @do_with_i32_urem(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]
%rem = urem i32 %i.09, 5
%add = add i32 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i32 %res.0.lcssa
}
; CHECK-LABEL: do_with_i32_srem
; CHECK: entry:
; CHECK: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %n)
; CHECK: br i1 [[TEST]], label %while.body.preheader, label %while.end
; CHECK: while.body.preheader:
; CHECK-NEXT: br label %while.body
; CHECK: while.body:
; CHECK: [[REM:%[^ ]+]] = phi i32 [ %n, %while.body.preheader ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
define i32 @do_with_i32_srem(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]
%rem = srem i32 %i.09, 5
%add = sub i32 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i32 %res.0.lcssa
}
; CHECK-LABEL: do_with_i32_udiv
; CHECK: entry:
; CHECK: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %n)
; CHECK: br i1 [[TEST]], label %while.body.preheader, label %while.end
; CHECK: while.body.preheader:
; CHECK-NEXT: br label %while.body
; CHECK: while.body:
; CHECK: [[REM:%[^ ]+]] = phi i32 [ %n, %while.body.preheader ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
define i32 @do_with_i32_udiv(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]
%rem = udiv i32 %i.09, 5
%add = add i32 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i32 %res.0.lcssa
}
; CHECK-LABEL: do_with_i32_sdiv
; CHECK: entry:
; CHECK: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %n)
; CHECK: br i1 [[TEST]], label %while.body.preheader, label %while.end
; CHECK: while.body.preheader:
; CHECK-NEXT: br label %while.body
; CHECK: while.body:
; CHECK: [[REM:%[^ ]+]] = phi i32 [ %n, %while.body.preheader ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
define i32 @do_with_i32_sdiv(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]
%rem = sdiv i32 %i.09, 5
%add = sub i32 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i32 %res.0.lcssa
}
; CHECK-LABEL: do_with_i64_urem
; CHECK-NOT: llvm.{{.*}}.loop.iterations
; CHECK-NOT: llvm.loop.decrement
define i64 @do_with_i64_urem(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i64 [ %add, %while.body ], [ 0, %while.body.preheader ]
%conv = zext i32 %i.09 to i64
%rem = urem i64 %conv, 5
%add = add i64 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i64 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i64 %res.0.lcssa
}
; CHECK-LABEL: do_with_i64_srem
; CHECK-NOT: llvm.{{.*}}.loop.iterations
; CHECK-NOT: llvm.loop.decrement
define i64 @do_with_i64_srem(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i64 [ %add, %while.body ], [ 0, %while.body.preheader ]
%conv = zext i32 %i.09 to i64
%rem = srem i64 %conv, 5
%add = sub i64 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i64 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i64 %res.0.lcssa
}
; CHECK-LABEL: do_with_i64_udiv
; CHECK-NOT: llvm.{{.*}}.loop.iterations
; CHECK-NOT: llvm.loop.decrement
define i64 @do_with_i64_udiv(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i64 [ %add, %while.body ], [ 0, %while.body.preheader ]
%conv = zext i32 %i.09 to i64
%rem = udiv i64 %conv, 5
%add = add i64 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i64 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i64 %res.0.lcssa
}
; CHECK-LABEL: do_with_i64_sdiv
; CHECK-NOT: call void @llvm.{{.*}}.loop.iterations
; CHECK-NOT: call i32 @llvm.loop.decrement
define i64 @do_with_i64_sdiv(i32 %n) {
entry:
%cmp7 = icmp eq i32 %n, 0
br i1 %cmp7, label %while.end, label %while.body.preheader
while.body.preheader:
br label %while.body
while.body:
%i.09 = phi i32 [ %inc1, %while.body ], [ 0, %while.body.preheader ]
%res.08 = phi i64 [ %add, %while.body ], [ 0, %while.body.preheader ]
%conv = zext i32 %i.09 to i64
%rem = sdiv i64 %conv, 5
%add = sub i64 %rem, %res.08
%inc1 = add nuw i32 %i.09, 1
%exitcond = icmp eq i32 %inc1, %n
br i1 %exitcond, label %while.end.loopexit, label %while.body
while.end.loopexit:
br label %while.end
while.end:
%res.0.lcssa = phi i64 [ 0, %entry ], [ %add, %while.end.loopexit ]
ret i64 %res.0.lcssa
}
|