1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 declare double @llvm.powi.f64(double, i32) nounwind readonly
5 declare i32 @llvm.cttz.i32(i32, i1) nounwind readnone
6 declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
7 declare i1 @llvm.cttz.i1(i1, i1) nounwind readnone
8 declare i1 @llvm.ctlz.i1(i1, i1) nounwind readnone
9 declare i32 @llvm.ctpop.i32(i32) nounwind readnone
10 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32>, i1) nounwind readnone
11 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32>, i1) nounwind readnone
12 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) nounwind readnone
13 declare i8 @llvm.ctlz.i8(i8, i1) nounwind readnone
14 declare <2 x i8> @llvm.ctlz.v2i8(<2 x i8>, i1) nounwind readnone
15 declare double @llvm.cos.f64(double %Val) nounwind readonly
16 declare double @llvm.sin.f64(double %Val) nounwind readonly
17 declare double @llvm.floor.f64(double %Val) nounwind readonly
18 declare double @llvm.ceil.f64(double %Val) nounwind readonly
19 declare double @llvm.trunc.f64(double %Val) nounwind readonly
20 declare double @llvm.rint.f64(double %Val) nounwind readonly
21 declare double @llvm.nearbyint.f64(double %Val) nounwind readonly
23 define void @powi(double %V, double *%P) {
24 %A = tail call double @llvm.powi.f64(double %V, i32 -1) nounwind
25 store volatile double %A, double* %P
27 %D = tail call double @llvm.powi.f64(double %V, i32 2) nounwind
28 store volatile double %D, double* %P
31 ; CHECK: %A = fdiv double 1.0{{.*}}, %V
32 ; CHECK: store volatile double %A,
33 ; CHECK: %D = fmul double %V, %V
34 ; CHECK: store volatile double %D
37 define i32 @cttz(i32 %a) {
39 ; CHECK-NEXT: ret i32 3
42 %and = and i32 %or, -8
43 %count = tail call i32 @llvm.cttz.i32(i32 %and, i1 true) nounwind readnone
47 define <2 x i32> @cttz_vec(<2 x i32> %a) {
48 ; CHECK-LABEL: @cttz_vec(
49 ; CHECK-NEXT: ret <2 x i32> <i32 3, i32 3>
51 %or = or <2 x i32> %a, <i32 8, i32 8>
52 %and = and <2 x i32> %or, <i32 -8, i32 -8>
53 %count = tail call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %and, i1 true) nounwind readnone
57 ; Make sure we don't add range metadata to i1 cttz.
58 define i1 @cttz_i1(i1 %arg) {
59 ; CHECK-LABEL: @cttz_i1(
60 ; CHECK-NEXT: [[CNT:%.*]] = call i1 @llvm.cttz.i1(i1 [[ARG:%.*]], i1 false) #2
61 ; CHECK-NEXT: ret i1 [[CNT]]
63 %cnt = call i1 @llvm.cttz.i1(i1 %arg, i1 false) nounwind readnone
67 define i1 @cttz_knownbits(i32 %arg) {
68 ; CHECK-LABEL: @cttz_knownbits(
69 ; CHECK-NEXT: ret i1 false
72 %cnt = call i32 @llvm.cttz.i32(i32 %or, i1 true) nounwind readnone
73 %res = icmp eq i32 %cnt, 4
77 define <2 x i1> @cttz_knownbits_vec(<2 x i32> %arg) {
78 ; CHECK-LABEL: @cttz_knownbits_vec(
79 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
81 %or = or <2 x i32> %arg, <i32 4, i32 4>
82 %cnt = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 true) nounwind readnone
83 %res = icmp eq <2 x i32> %cnt, <i32 4, i32 4>
87 define i32 @cttz_knownbits2(i32 %arg) {
88 ; CHECK-LABEL: @cttz_knownbits2(
89 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[ARG:%.*]], 4
90 ; CHECK-NEXT: [[CNT:%.*]] = call i32 @llvm.cttz.i32(i32 [[OR]], i1 true) #2, !range ![[$CTTZ_RANGE:[0-9]+]]
91 ; CHECK-NEXT: ret i32 [[CNT]]
94 %cnt = call i32 @llvm.cttz.i32(i32 %or, i1 true) nounwind readnone
98 define <2 x i32> @cttz_knownbits2_vec(<2 x i32> %arg) {
99 ; CHECK-LABEL: @cttz_knownbits2_vec(
100 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[ARG:%.*]], <i32 4, i32 4>
101 ; CHECK-NEXT: [[CNT:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[OR]], i1 true)
102 ; CHECK-NEXT: ret <2 x i32> [[CNT]]
104 %or = or <2 x i32> %arg, <i32 4, i32 4>
105 %cnt = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 true) nounwind readnone
109 define i1 @cttz_knownbits3(i32 %arg) {
110 ; CHECK-LABEL: @cttz_knownbits3(
111 ; CHECK-NEXT: ret i1 false
114 %cnt = call i32 @llvm.cttz.i32(i32 %or, i1 true) nounwind readnone
115 %res = icmp eq i32 %cnt, 3
119 define <2 x i1> @cttz_knownbits3_vec(<2 x i32> %arg) {
120 ; CHECK-LABEL: @cttz_knownbits3_vec(
121 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
123 %or = or <2 x i32> %arg, <i32 4, i32 4>
124 %cnt = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 true) nounwind readnone
125 %res = icmp eq <2 x i32> %cnt, <i32 3, i32 3>
129 define i8 @ctlz(i8 %a) {
130 ; CHECK-LABEL: @ctlz(
131 ; CHECK-NEXT: ret i8 2
134 %and = and i8 %or, 63
135 %count = tail call i8 @llvm.ctlz.i8(i8 %and, i1 true) nounwind readnone
139 define <2 x i8> @ctlz_vec(<2 x i8> %a) {
140 ; CHECK-LABEL: @ctlz_vec(
141 ; CHECK-NEXT: ret <2 x i8> <i8 2, i8 2>
143 %or = or <2 x i8> %a, <i8 32, i8 32>
144 %and = and <2 x i8> %or, <i8 63, i8 63>
145 %count = tail call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %and, i1 true) nounwind readnone
149 ; Make sure we don't add range metadata to i1 ctlz.
150 define i1 @ctlz_i1(i1 %arg) {
151 ; CHECK-LABEL: @ctlz_i1(
152 ; CHECK-NEXT: [[CNT:%.*]] = call i1 @llvm.ctlz.i1(i1 [[ARG:%.*]], i1 false) #2
153 ; CHECK-NEXT: ret i1 [[CNT]]
155 %cnt = call i1 @llvm.ctlz.i1(i1 %arg, i1 false) nounwind readnone
159 define i1 @ctlz_knownbits(i8 %arg) {
160 ; CHECK-LABEL: @ctlz_knownbits(
161 ; CHECK-NEXT: ret i1 false
164 %cnt = call i8 @llvm.ctlz.i8(i8 %or, i1 true) nounwind readnone
165 %res = icmp eq i8 %cnt, 4
169 define <2 x i1> @ctlz_knownbits_vec(<2 x i8> %arg) {
170 ; CHECK-LABEL: @ctlz_knownbits_vec(
171 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
173 %or = or <2 x i8> %arg, <i8 32, i8 32>
174 %cnt = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %or, i1 true) nounwind readnone
175 %res = icmp eq <2 x i8> %cnt, <i8 4, i8 4>
179 define i8 @ctlz_knownbits2(i8 %arg) {
180 ; CHECK-LABEL: @ctlz_knownbits2(
181 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[ARG:%.*]], 32
182 ; CHECK-NEXT: [[CNT:%.*]] = call i8 @llvm.ctlz.i8(i8 [[OR]], i1 true) #2, !range ![[$CTLZ_RANGE:[0-9]+]]
183 ; CHECK-NEXT: ret i8 [[CNT]]
186 %cnt = call i8 @llvm.ctlz.i8(i8 %or, i1 true) nounwind readnone
190 define <2 x i8> @ctlz_knownbits2_vec(<2 x i8> %arg) {
191 ; CHECK-LABEL: @ctlz_knownbits2_vec(
192 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[ARG:%.*]], <i8 32, i8 32>
193 ; CHECK-NEXT: [[CNT:%.*]] = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> [[OR]], i1 true)
194 ; CHECK-NEXT: ret <2 x i8> [[CNT]]
196 %or = or <2 x i8> %arg, <i8 32, i8 32>
197 %cnt = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %or, i1 true) nounwind readnone
201 define i1 @ctlz_knownbits3(i8 %arg) {
202 ; CHECK-LABEL: @ctlz_knownbits3(
203 ; CHECK-NEXT: ret i1 false
206 %cnt = call i8 @llvm.ctlz.i8(i8 %or, i1 true) nounwind readnone
207 %res = icmp eq i8 %cnt, 3
211 define <2 x i1> @ctlz_knownbits3_vec(<2 x i8> %arg) {
212 ; CHECK-LABEL: @ctlz_knownbits3_vec(
213 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
215 %or = or <2 x i8> %arg, <i8 32, i8 32>
216 %cnt = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %or, i1 true) nounwind readnone
217 %res = icmp eq <2 x i8> %cnt, <i8 3, i8 3>
221 define i32 @ctlz_undef(i32 %Value) {
222 ; CHECK-LABEL: @ctlz_undef(
223 ; CHECK-NEXT: ret i32 undef
225 %ctlz = call i32 @llvm.ctlz.i32(i32 0, i1 true)
229 define <2 x i32> @ctlz_undef_vec(<2 x i32> %Value) {
230 ; CHECK-LABEL: @ctlz_undef_vec(
231 ; CHECK-NEXT: ret <2 x i32> undef
233 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> zeroinitializer, i1 true)
237 define i32 @ctlz_make_undef(i32 %a) {
239 %ctlz = tail call i32 @llvm.ctlz.i32(i32 %or, i1 false)
241 ; CHECK-LABEL: @ctlz_make_undef(
242 ; CHECK-NEXT: %or = or i32 %a, 8
243 ; CHECK-NEXT: %ctlz = tail call i32 @llvm.ctlz.i32(i32 %or, i1 true)
244 ; CHECK-NEXT: ret i32 %ctlz
247 define <2 x i32> @ctlz_make_undef_vec(<2 x i32> %a) {
248 ; CHECK-LABEL: @ctlz_make_undef_vec(
249 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[A:%.*]], <i32 8, i32 8>
250 ; CHECK-NEXT: [[CTLZ:%.*]] = tail call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> [[OR]], i1 true)
251 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
253 %or = or <2 x i32> %a, <i32 8, i32 8>
254 %ctlz = tail call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %or, i1 false)
258 define i32 @cttz_undef(i32 %Value) nounwind {
259 ; CHECK-LABEL: @cttz_undef(
260 ; CHECK-NEXT: ret i32 undef
262 %cttz = call i32 @llvm.cttz.i32(i32 0, i1 true)
266 define <2 x i32> @cttz_undef_vec(<2 x i32> %Value) nounwind {
267 ; CHECK-LABEL: @cttz_undef_vec(
268 ; CHECK-NEXT: ret <2 x i32> undef
270 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> zeroinitializer, i1 true)
274 define i32 @cttz_make_undef(i32 %a) {
276 %cttz = tail call i32 @llvm.cttz.i32(i32 %or, i1 false)
278 ; CHECK-LABEL: @cttz_make_undef(
279 ; CHECK-NEXT: %or = or i32 %a, 8
280 ; CHECK-NEXT: %cttz = tail call i32 @llvm.cttz.i32(i32 %or, i1 true)
281 ; CHECK-NEXT: ret i32 %cttz
284 define <2 x i32> @cttz_make_undef_vec(<2 x i32> %a) {
285 ; CHECK-LABEL: @cttz_make_undef_vec(
286 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[A:%.*]], <i32 8, i32 8>
287 ; CHECK-NEXT: [[CTTZ:%.*]] = tail call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[OR]], i1 true)
288 ; CHECK-NEXT: ret <2 x i32> [[CTTZ]]
290 %or = or <2 x i32> %a, <i32 8, i32 8>
291 %cttz = tail call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 false)
295 define i32 @ctlz_select(i32 %Value) nounwind {
296 ; CHECK-LABEL: @ctlz_select(
297 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 %Value, i1 false)
298 ; CHECK-NEXT: ret i32 [[TMP1]]
300 %tobool = icmp ne i32 %Value, 0
301 %ctlz = call i32 @llvm.ctlz.i32(i32 %Value, i1 true)
302 %s = select i1 %tobool, i32 %ctlz, i32 32
306 define <2 x i32> @ctlz_select_vec(<2 x i32> %Value) nounwind {
307 ; CHECK-LABEL: @ctlz_select_vec(
308 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> [[VALUE:%.*]], i1 false)
309 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
311 %tobool = icmp ne <2 x i32> %Value, zeroinitializer
312 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %Value, i1 true)
313 %s = select <2 x i1> %tobool, <2 x i32> %ctlz, <2 x i32> <i32 32, i32 32>
317 define i32 @cttz_select(i32 %Value) nounwind {
318 ; CHECK-LABEL: @cttz_select(
319 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 %Value, i1 false)
320 ; CHECK-NEXT: ret i32 [[TMP1]]
322 %tobool = icmp ne i32 %Value, 0
323 %cttz = call i32 @llvm.cttz.i32(i32 %Value, i1 true)
324 %s = select i1 %tobool, i32 %cttz, i32 32
328 define <2 x i32> @cttz_select_vec(<2 x i32> %Value) nounwind {
329 ; CHECK-LABEL: @cttz_select_vec(
330 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[VALUE:%.*]], i1 false)
331 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
333 %tobool = icmp ne <2 x i32> %Value, zeroinitializer
334 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %Value, i1 true)
335 %s = select <2 x i1> %tobool, <2 x i32> %cttz, <2 x i32> <i32 32, i32 32>
339 define void @cos(double *%P) {
341 ; CHECK-NEXT: store volatile double 1.000000e+00, double* %P, align 8
342 ; CHECK-NEXT: ret void
344 %B = tail call double @llvm.cos.f64(double 0.0) nounwind
345 store volatile double %B, double* %P
350 define void @sin(double *%P) {
352 ; CHECK-NEXT: store volatile double 0.000000e+00, double* %P, align 8
353 ; CHECK-NEXT: ret void
355 %B = tail call double @llvm.sin.f64(double 0.0) nounwind
356 store volatile double %B, double* %P
361 define void @floor(double *%P) {
362 ; CHECK-LABEL: @floor(
363 ; CHECK-NEXT: store volatile double 1.000000e+00, double* %P, align 8
364 ; CHECK-NEXT: store volatile double -2.000000e+00, double* %P, align 8
365 ; CHECK-NEXT: ret void
367 %B = tail call double @llvm.floor.f64(double 1.5) nounwind
368 store volatile double %B, double* %P
369 %C = tail call double @llvm.floor.f64(double -1.5) nounwind
370 store volatile double %C, double* %P
374 define void @ceil(double *%P) {
375 ; CHECK-LABEL: @ceil(
376 ; CHECK-NEXT: store volatile double 2.000000e+00, double* %P, align 8
377 ; CHECK-NEXT: store volatile double -1.000000e+00, double* %P, align 8
378 ; CHECK-NEXT: ret void
380 %B = tail call double @llvm.ceil.f64(double 1.5) nounwind
381 store volatile double %B, double* %P
382 %C = tail call double @llvm.ceil.f64(double -1.5) nounwind
383 store volatile double %C, double* %P
387 define void @trunc(double *%P) {
388 ; CHECK-LABEL: @trunc(
389 ; CHECK-NEXT: store volatile double 1.000000e+00, double* %P, align 8
390 ; CHECK-NEXT: store volatile double -1.000000e+00, double* %P, align 8
391 ; CHECK-NEXT: ret void
393 %B = tail call double @llvm.trunc.f64(double 1.5) nounwind
394 store volatile double %B, double* %P
395 %C = tail call double @llvm.trunc.f64(double -1.5) nounwind
396 store volatile double %C, double* %P
400 define void @rint(double *%P) {
401 ; CHECK-LABEL: @rint(
402 ; CHECK-NEXT: store volatile double 2.000000e+00, double* %P, align 8
403 ; CHECK-NEXT: store volatile double -2.000000e+00, double* %P, align 8
404 ; CHECK-NEXT: ret void
406 %B = tail call double @llvm.rint.f64(double 1.5) nounwind
407 store volatile double %B, double* %P
408 %C = tail call double @llvm.rint.f64(double -1.5) nounwind
409 store volatile double %C, double* %P
413 define void @nearbyint(double *%P) {
414 ; CHECK-LABEL: @nearbyint(
415 ; CHECK-NEXT: store volatile double 2.000000e+00, double* %P, align 8
416 ; CHECK-NEXT: store volatile double -2.000000e+00, double* %P, align 8
417 ; CHECK-NEXT: ret void
419 %B = tail call double @llvm.nearbyint.f64(double 1.5) nounwind
420 store volatile double %B, double* %P
421 %C = tail call double @llvm.nearbyint.f64(double -1.5) nounwind
422 store volatile double %C, double* %P
426 ; CHECK: [[$CTTZ_RANGE]] = !{i32 0, i32 3}
427 ; CHECK: [[$CTLZ_RANGE]] = !{i8 0, i8 3}