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.i16(double, i16) nounwind readonly
5 declare double @llvm.powi.f64.i32(double, i32) nounwind readonly
6 declare i32 @llvm.cttz.i32(i32, i1) nounwind readnone
7 declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
8 declare i1 @llvm.cttz.i1(i1, i1) nounwind readnone
9 declare i1 @llvm.ctlz.i1(i1, i1) nounwind readnone
10 declare <2 x i1> @llvm.cttz.v2i1(<2 x i1>, i1) nounwind readnone
11 declare <2 x i1> @llvm.ctlz.v2i1(<2 x i1>, i1) nounwind readnone
12 declare i32 @llvm.ctpop.i32(i32) nounwind readnone
13 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32>, i1) nounwind readnone
14 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32>, i1) nounwind readnone
15 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) nounwind readnone
16 declare i8 @llvm.ctlz.i8(i8, i1) nounwind readnone
17 declare <2 x i8> @llvm.ctlz.v2i8(<2 x i8>, i1) nounwind readnone
18 declare double @llvm.cos.f64(double %Val) nounwind readonly
19 declare double @llvm.sin.f64(double %Val) nounwind readonly
20 declare double @llvm.floor.f64(double %Val) nounwind readonly
21 declare double @llvm.ceil.f64(double %Val) nounwind readonly
22 declare double @llvm.trunc.f64(double %Val) nounwind readonly
23 declare double @llvm.rint.f64(double %Val) nounwind readonly
24 declare double @llvm.nearbyint.f64(double %Val) nounwind readonly
26 define void @powi(double %V, double *%P) {
28 ; CHECK-NEXT: [[A:%.*]] = fdiv fast double 1.000000e+00, [[V:%.*]]
29 ; CHECK-NEXT: store volatile double [[A]], double* [[P:%.*]], align 8
30 ; CHECK-NEXT: [[D:%.*]] = fmul nnan double [[V]], [[V]]
31 ; CHECK-NEXT: store volatile double [[D]], double* [[P]], align 8
32 ; CHECK-NEXT: [[A2:%.*]] = fdiv fast double 1.000000e+00, [[V]]
33 ; CHECK-NEXT: store volatile double [[A2]], double* [[P]], align 8
34 ; CHECK-NEXT: [[D2:%.*]] = fmul nnan double [[V]], [[V]]
35 ; CHECK-NEXT: store volatile double [[D2]], double* [[P]], align 8
36 ; CHECK-NEXT: ret void
38 %A = tail call fast double @llvm.powi.f64.i32(double %V, i32 -1) nounwind
39 store volatile double %A, double* %P
41 %D = tail call nnan double @llvm.powi.f64.i32(double %V, i32 2) nounwind
42 store volatile double %D, double* %P
44 %A2 = tail call fast double @llvm.powi.f64.i16(double %V, i16 -1) nounwind
45 store volatile double %A2, double* %P
47 %D2 = tail call nnan double @llvm.powi.f64.i16(double %V, i16 2) nounwind
48 store volatile double %D2, double* %P
52 define i32 @cttz(i32 %a) {
54 ; CHECK-NEXT: ret i32 3
57 %and = and i32 %or, -8
58 %count = tail call i32 @llvm.cttz.i32(i32 %and, i1 true) nounwind readnone
62 define <2 x i32> @cttz_vec(<2 x i32> %a) {
63 ; CHECK-LABEL: @cttz_vec(
64 ; CHECK-NEXT: ret <2 x i32> <i32 3, i32 3>
66 %or = or <2 x i32> %a, <i32 8, i32 8>
67 %and = and <2 x i32> %or, <i32 -8, i32 -8>
68 %count = tail call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %and, i1 true) nounwind readnone
72 ; Make sure we don't add range metadata to i1 cttz.
73 define i1 @cttz_i1(i1 %arg) {
74 ; CHECK-LABEL: @cttz_i1(
75 ; CHECK-NEXT: [[CNT:%.*]] = xor i1 [[ARG:%.*]], true
76 ; CHECK-NEXT: ret i1 [[CNT]]
78 %cnt = call i1 @llvm.cttz.i1(i1 %arg, i1 false) nounwind readnone
82 define i1 @cttz_i1_zero_is_undef(i1 %arg) {
83 ; CHECK-LABEL: @cttz_i1_zero_is_undef(
84 ; CHECK-NEXT: ret i1 false
86 %cnt = call i1 @llvm.cttz.i1(i1 %arg, i1 true) nounwind readnone
90 define <2 x i1> @cttz_v2i1(<2 x i1> %arg) {
91 ; CHECK-LABEL: @cttz_v2i1(
92 ; CHECK-NEXT: [[CNT:%.*]] = xor <2 x i1> [[ARG:%.*]], <i1 true, i1 true>
93 ; CHECK-NEXT: ret <2 x i1> [[CNT]]
95 %cnt = call <2 x i1> @llvm.cttz.v2i1(<2 x i1> %arg, i1 false) nounwind readnone
99 define <2 x i1> @cttz_v2i1_zero_is_undef(<2 x i1> %arg) {
100 ; CHECK-LABEL: @cttz_v2i1_zero_is_undef(
101 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
103 %cnt = call <2 x i1> @llvm.cttz.v2i1(<2 x i1> %arg, i1 true) nounwind readnone
107 define i1 @cttz_knownbits(i32 %arg) {
108 ; CHECK-LABEL: @cttz_knownbits(
109 ; CHECK-NEXT: ret i1 false
112 %cnt = call i32 @llvm.cttz.i32(i32 %or, i1 true) nounwind readnone
113 %res = icmp eq i32 %cnt, 4
117 define <2 x i1> @cttz_knownbits_vec(<2 x i32> %arg) {
118 ; CHECK-LABEL: @cttz_knownbits_vec(
119 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
121 %or = or <2 x i32> %arg, <i32 4, i32 4>
122 %cnt = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 true) nounwind readnone
123 %res = icmp eq <2 x i32> %cnt, <i32 4, i32 4>
127 define i32 @cttz_knownbits2(i32 %arg) {
128 ; CHECK-LABEL: @cttz_knownbits2(
129 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[ARG:%.*]], 4
130 ; CHECK-NEXT: [[CNT:%.*]] = call i32 @llvm.cttz.i32(i32 [[OR]], i1 true) #[[ATTR2:[0-9]+]], !range [[RNG0:![0-9]+]]
131 ; CHECK-NEXT: ret i32 [[CNT]]
134 %cnt = call i32 @llvm.cttz.i32(i32 %or, i1 true) nounwind readnone
138 define <2 x i32> @cttz_knownbits2_vec(<2 x i32> %arg) {
139 ; CHECK-LABEL: @cttz_knownbits2_vec(
140 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[ARG:%.*]], <i32 4, i32 4>
141 ; CHECK-NEXT: [[CNT:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[OR]], i1 true) #[[ATTR2]]
142 ; CHECK-NEXT: ret <2 x i32> [[CNT]]
144 %or = or <2 x i32> %arg, <i32 4, i32 4>
145 %cnt = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 true) nounwind readnone
149 define i1 @cttz_knownbits3(i32 %arg) {
150 ; CHECK-LABEL: @cttz_knownbits3(
151 ; CHECK-NEXT: ret i1 false
154 %cnt = call i32 @llvm.cttz.i32(i32 %or, i1 true) nounwind readnone
155 %res = icmp eq i32 %cnt, 3
159 define <2 x i1> @cttz_knownbits3_vec(<2 x i32> %arg) {
160 ; CHECK-LABEL: @cttz_knownbits3_vec(
161 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
163 %or = or <2 x i32> %arg, <i32 4, i32 4>
164 %cnt = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 true) nounwind readnone
165 %res = icmp eq <2 x i32> %cnt, <i32 3, i32 3>
169 define i8 @ctlz(i8 %a) {
170 ; CHECK-LABEL: @ctlz(
171 ; CHECK-NEXT: ret i8 2
174 %and = and i8 %or, 63
175 %count = tail call i8 @llvm.ctlz.i8(i8 %and, i1 true) nounwind readnone
179 define <2 x i8> @ctlz_vec(<2 x i8> %a) {
180 ; CHECK-LABEL: @ctlz_vec(
181 ; CHECK-NEXT: ret <2 x i8> <i8 2, i8 2>
183 %or = or <2 x i8> %a, <i8 32, i8 32>
184 %and = and <2 x i8> %or, <i8 63, i8 63>
185 %count = tail call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %and, i1 true) nounwind readnone
189 ; Make sure we don't add range metadata to i1 ctlz.
190 define i1 @ctlz_i1(i1 %arg) {
191 ; CHECK-LABEL: @ctlz_i1(
192 ; CHECK-NEXT: [[CNT:%.*]] = xor i1 [[ARG:%.*]], true
193 ; CHECK-NEXT: ret i1 [[CNT]]
195 %cnt = call i1 @llvm.ctlz.i1(i1 %arg, i1 false) nounwind readnone
199 define i1 @ctlz_i1_zero_is_undef(i1 %arg) {
200 ; CHECK-LABEL: @ctlz_i1_zero_is_undef(
201 ; CHECK-NEXT: ret i1 false
203 %cnt = call i1 @llvm.ctlz.i1(i1 %arg, i1 true) nounwind readnone
207 define <2 x i1> @ctlz_v2i1(<2 x i1> %arg) {
208 ; CHECK-LABEL: @ctlz_v2i1(
209 ; CHECK-NEXT: [[CNT:%.*]] = xor <2 x i1> [[ARG:%.*]], <i1 true, i1 true>
210 ; CHECK-NEXT: ret <2 x i1> [[CNT]]
212 %cnt = call <2 x i1> @llvm.ctlz.v2i1(<2 x i1> %arg, i1 false) nounwind readnone
216 define <2 x i1> @ctlz_v2i1_zero_is_undef(<2 x i1> %arg) {
217 ; CHECK-LABEL: @ctlz_v2i1_zero_is_undef(
218 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
220 %cnt = call <2 x i1> @llvm.ctlz.v2i1(<2 x i1> %arg, i1 true) nounwind readnone
224 define i1 @ctlz_knownbits(i8 %arg) {
225 ; CHECK-LABEL: @ctlz_knownbits(
226 ; CHECK-NEXT: ret i1 false
229 %cnt = call i8 @llvm.ctlz.i8(i8 %or, i1 true) nounwind readnone
230 %res = icmp eq i8 %cnt, 4
234 define <2 x i1> @ctlz_knownbits_vec(<2 x i8> %arg) {
235 ; CHECK-LABEL: @ctlz_knownbits_vec(
236 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
238 %or = or <2 x i8> %arg, <i8 32, i8 32>
239 %cnt = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %or, i1 true) nounwind readnone
240 %res = icmp eq <2 x i8> %cnt, <i8 4, i8 4>
244 define i8 @ctlz_knownbits2(i8 %arg) {
245 ; CHECK-LABEL: @ctlz_knownbits2(
246 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[ARG:%.*]], 32
247 ; CHECK-NEXT: [[CNT:%.*]] = call i8 @llvm.ctlz.i8(i8 [[OR]], i1 true) #[[ATTR2]], !range [[RNG1:![0-9]+]]
248 ; CHECK-NEXT: ret i8 [[CNT]]
251 %cnt = call i8 @llvm.ctlz.i8(i8 %or, i1 true) nounwind readnone
255 define <2 x i8> @ctlz_knownbits2_vec(<2 x i8> %arg) {
256 ; CHECK-LABEL: @ctlz_knownbits2_vec(
257 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[ARG:%.*]], <i8 32, i8 32>
258 ; CHECK-NEXT: [[CNT:%.*]] = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> [[OR]], i1 true) #[[ATTR2]]
259 ; CHECK-NEXT: ret <2 x i8> [[CNT]]
261 %or = or <2 x i8> %arg, <i8 32, i8 32>
262 %cnt = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %or, i1 true) nounwind readnone
266 define i1 @ctlz_knownbits3(i8 %arg) {
267 ; CHECK-LABEL: @ctlz_knownbits3(
268 ; CHECK-NEXT: ret i1 false
271 %cnt = call i8 @llvm.ctlz.i8(i8 %or, i1 true) nounwind readnone
272 %res = icmp eq i8 %cnt, 3
276 define <2 x i1> @ctlz_knownbits3_vec(<2 x i8> %arg) {
277 ; CHECK-LABEL: @ctlz_knownbits3_vec(
278 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
280 %or = or <2 x i8> %arg, <i8 32, i8 32>
281 %cnt = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %or, i1 true) nounwind readnone
282 %res = icmp eq <2 x i8> %cnt, <i8 3, i8 3>
286 define i32 @ctlz_undef(i32 %Value) {
287 ; CHECK-LABEL: @ctlz_undef(
288 ; CHECK-NEXT: ret i32 undef
290 %ctlz = call i32 @llvm.ctlz.i32(i32 0, i1 true)
294 define <2 x i32> @ctlz_undef_vec(<2 x i32> %Value) {
295 ; CHECK-LABEL: @ctlz_undef_vec(
296 ; CHECK-NEXT: ret <2 x i32> undef
298 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> zeroinitializer, i1 true)
302 define i32 @ctlz_make_undef(i32 %a) {
303 ; CHECK-LABEL: @ctlz_make_undef(
304 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[A:%.*]], 8
305 ; CHECK-NEXT: [[CTLZ:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[OR]], i1 true), !range [[RNG2:![0-9]+]]
306 ; CHECK-NEXT: ret i32 [[CTLZ]]
309 %ctlz = tail call i32 @llvm.ctlz.i32(i32 %or, i1 false)
313 define <2 x i32> @ctlz_make_undef_vec(<2 x i32> %a) {
314 ; CHECK-LABEL: @ctlz_make_undef_vec(
315 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[A:%.*]], <i32 8, i32 8>
316 ; CHECK-NEXT: [[CTLZ:%.*]] = tail call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> [[OR]], i1 true)
317 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
319 %or = or <2 x i32> %a, <i32 8, i32 8>
320 %ctlz = tail call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %or, i1 false)
324 define i32 @cttz_undef(i32 %Value) nounwind {
325 ; CHECK-LABEL: @cttz_undef(
326 ; CHECK-NEXT: ret i32 undef
328 %cttz = call i32 @llvm.cttz.i32(i32 0, i1 true)
332 define <2 x i32> @cttz_undef_vec(<2 x i32> %Value) nounwind {
333 ; CHECK-LABEL: @cttz_undef_vec(
334 ; CHECK-NEXT: ret <2 x i32> undef
336 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> zeroinitializer, i1 true)
340 define i32 @cttz_make_undef(i32 %a) {
341 ; CHECK-LABEL: @cttz_make_undef(
342 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[A:%.*]], 8
343 ; CHECK-NEXT: [[CTTZ:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[OR]], i1 true), !range [[RNG3:![0-9]+]]
344 ; CHECK-NEXT: ret i32 [[CTTZ]]
347 %cttz = tail call i32 @llvm.cttz.i32(i32 %or, i1 false)
351 define <2 x i32> @cttz_make_undef_vec(<2 x i32> %a) {
352 ; CHECK-LABEL: @cttz_make_undef_vec(
353 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[A:%.*]], <i32 8, i32 8>
354 ; CHECK-NEXT: [[CTTZ:%.*]] = tail call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[OR]], i1 true)
355 ; CHECK-NEXT: ret <2 x i32> [[CTTZ]]
357 %or = or <2 x i32> %a, <i32 8, i32 8>
358 %cttz = tail call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %or, i1 false)
362 define i32 @ctlz_select(i32 %Value) nounwind {
363 ; CHECK-LABEL: @ctlz_select(
364 ; CHECK-NEXT: [[CTLZ:%.*]] = call i32 @llvm.ctlz.i32(i32 [[VALUE:%.*]], i1 false), !range [[RNG4:![0-9]+]]
365 ; CHECK-NEXT: ret i32 [[CTLZ]]
367 %tobool = icmp ne i32 %Value, 0
368 %ctlz = call i32 @llvm.ctlz.i32(i32 %Value, i1 true)
369 %s = select i1 %tobool, i32 %ctlz, i32 32
373 define <2 x i32> @ctlz_select_vec(<2 x i32> %Value) nounwind {
374 ; CHECK-LABEL: @ctlz_select_vec(
375 ; CHECK-NEXT: [[CTLZ:%.*]] = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> [[VALUE:%.*]], i1 false)
376 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
378 %tobool = icmp ne <2 x i32> %Value, zeroinitializer
379 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %Value, i1 true)
380 %s = select <2 x i1> %tobool, <2 x i32> %ctlz, <2 x i32> <i32 32, i32 32>
384 define i32 @cttz_select(i32 %Value) nounwind {
385 ; CHECK-LABEL: @cttz_select(
386 ; CHECK-NEXT: [[CTTZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[VALUE:%.*]], i1 false), !range [[RNG4]]
387 ; CHECK-NEXT: ret i32 [[CTTZ]]
389 %tobool = icmp ne i32 %Value, 0
390 %cttz = call i32 @llvm.cttz.i32(i32 %Value, i1 true)
391 %s = select i1 %tobool, i32 %cttz, i32 32
395 define <2 x i32> @cttz_select_vec(<2 x i32> %Value) nounwind {
396 ; CHECK-LABEL: @cttz_select_vec(
397 ; CHECK-NEXT: [[CTTZ:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[VALUE:%.*]], i1 false)
398 ; CHECK-NEXT: ret <2 x i32> [[CTTZ]]
400 %tobool = icmp ne <2 x i32> %Value, zeroinitializer
401 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %Value, i1 true)
402 %s = select <2 x i1> %tobool, <2 x i32> %cttz, <2 x i32> <i32 32, i32 32>
406 define void @cos(double *%P) {
408 ; CHECK-NEXT: store volatile double 1.000000e+00, double* [[P:%.*]], align 8
409 ; CHECK-NEXT: ret void
411 %B = tail call double @llvm.cos.f64(double 0.0) nounwind
412 store volatile double %B, double* %P
417 define void @sin(double *%P) {
419 ; CHECK-NEXT: store volatile double 0.000000e+00, double* [[P:%.*]], align 8
420 ; CHECK-NEXT: ret void
422 %B = tail call double @llvm.sin.f64(double 0.0) nounwind
423 store volatile double %B, double* %P
428 define void @floor(double *%P) {
429 ; CHECK-LABEL: @floor(
430 ; CHECK-NEXT: store volatile double 1.000000e+00, double* [[P:%.*]], align 8
431 ; CHECK-NEXT: store volatile double -2.000000e+00, double* [[P]], align 8
432 ; CHECK-NEXT: ret void
434 %B = tail call double @llvm.floor.f64(double 1.5) nounwind
435 store volatile double %B, double* %P
436 %C = tail call double @llvm.floor.f64(double -1.5) nounwind
437 store volatile double %C, double* %P
441 define void @ceil(double *%P) {
442 ; CHECK-LABEL: @ceil(
443 ; CHECK-NEXT: store volatile double 2.000000e+00, double* [[P:%.*]], align 8
444 ; CHECK-NEXT: store volatile double -1.000000e+00, double* [[P]], align 8
445 ; CHECK-NEXT: ret void
447 %B = tail call double @llvm.ceil.f64(double 1.5) nounwind
448 store volatile double %B, double* %P
449 %C = tail call double @llvm.ceil.f64(double -1.5) nounwind
450 store volatile double %C, double* %P
454 define void @trunc(double *%P) {
455 ; CHECK-LABEL: @trunc(
456 ; CHECK-NEXT: store volatile double 1.000000e+00, double* [[P:%.*]], align 8
457 ; CHECK-NEXT: store volatile double -1.000000e+00, double* [[P]], align 8
458 ; CHECK-NEXT: ret void
460 %B = tail call double @llvm.trunc.f64(double 1.5) nounwind
461 store volatile double %B, double* %P
462 %C = tail call double @llvm.trunc.f64(double -1.5) nounwind
463 store volatile double %C, double* %P
467 define void @rint(double *%P) {
468 ; CHECK-LABEL: @rint(
469 ; CHECK-NEXT: store volatile double 2.000000e+00, double* [[P:%.*]], align 8
470 ; CHECK-NEXT: store volatile double -2.000000e+00, double* [[P]], align 8
471 ; CHECK-NEXT: ret void
473 %B = tail call double @llvm.rint.f64(double 1.5) nounwind
474 store volatile double %B, double* %P
475 %C = tail call double @llvm.rint.f64(double -1.5) nounwind
476 store volatile double %C, double* %P
480 define void @nearbyint(double *%P) {
481 ; CHECK-LABEL: @nearbyint(
482 ; CHECK-NEXT: store volatile double 2.000000e+00, double* [[P:%.*]], align 8
483 ; CHECK-NEXT: store volatile double -2.000000e+00, double* [[P]], align 8
484 ; CHECK-NEXT: ret void
486 %B = tail call double @llvm.nearbyint.f64(double 1.5) nounwind
487 store volatile double %B, double* %P
488 %C = tail call double @llvm.nearbyint.f64(double -1.5) nounwind
489 store volatile double %C, double* %P
493 ; CHECK: [[RNG0]] = !{i32 0, i32 3}
494 ; CHECK: [[RNG1]] = !{i8 0, i8 3}