1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
3 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
5 declare {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a, i8 %b)
6 declare {i8, i1} @llvm.sadd.with.overflow.i8(i8 %a, i8 %b)
7 declare {i8, i1} @llvm.usub.with.overflow.i8(i8 %a, i8 %b)
8 declare {i8, i1} @llvm.ssub.with.overflow.i8(i8 %a, i8 %b)
9 declare {i8, i1} @llvm.umul.with.overflow.i8(i8 %a, i8 %b)
10 declare {i8, i1} @llvm.smul.with.overflow.i8(i8 %a, i8 %b)
12 define i1 @test_uadd1() {
13 ; CHECK-LABEL: @test_uadd1(
14 ; CHECK-NEXT: ret i1 true
16 %x = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 254, i8 3)
17 %overflow = extractvalue {i8, i1} %x, 1
21 define i8 @test_uadd2() {
22 ; CHECK-LABEL: @test_uadd2(
23 ; CHECK-NEXT: ret i8 42
25 %x = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 254, i8 44)
26 %result = extractvalue {i8, i1} %x, 0
30 define {i8, i1} @test_uadd3(i8 %v) {
31 ; CHECK-LABEL: @test_uadd3(
32 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
34 %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v, i8 undef)
38 define {i8, i1} @test_uadd3_poison(i8 %v) {
39 ; CHECK-LABEL: @test_uadd3_poison(
40 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
42 %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v, i8 poison)
46 define {i8, i1} @test_uadd4(i8 %v) {
47 ; CHECK-LABEL: @test_uadd4(
48 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
50 %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 undef, i8 %v)
54 define {i8, i1} @test_uadd4_poison(i8 %v) {
55 ; CHECK-LABEL: @test_uadd4_poison(
56 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
58 %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 poison, i8 %v)
62 define i1 @test_sadd1() {
63 ; CHECK-LABEL: @test_sadd1(
64 ; CHECK-NEXT: ret i1 true
66 %x = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 126, i8 3)
67 %overflow = extractvalue {i8, i1} %x, 1
71 define i8 @test_sadd2() {
72 ; CHECK-LABEL: @test_sadd2(
73 ; CHECK-NEXT: ret i8 -86
75 %x = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 126, i8 44)
76 %result = extractvalue {i8, i1} %x, 0
80 define {i8, i1} @test_sadd3(i8 %v) {
81 ; CHECK-LABEL: @test_sadd3(
82 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
84 %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v, i8 undef)
88 define {i8, i1} @test_sadd3_poison(i8 %v) {
89 ; CHECK-LABEL: @test_sadd3_poison(
90 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
92 %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v, i8 poison)
96 define {i8, i1} @test_sadd4(i8 %v) {
97 ; CHECK-LABEL: @test_sadd4(
98 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
100 %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 undef, i8 %v)
104 define {i8, i1} @test_sadd4_poison(i8 %v) {
105 ; CHECK-LABEL: @test_sadd4_poison(
106 ; CHECK-NEXT: ret { i8, i1 } { i8 -1, i1 false }
108 %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 poison, i8 %v)
112 define {i8, i1} @test_usub1(i8 %V) {
113 ; CHECK-LABEL: @test_usub1(
114 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
116 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 %V)
120 define {i8, i1} @test_usub2(i8 %V) {
121 ; CHECK-LABEL: @test_usub2(
122 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
124 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 undef)
128 define {i8, i1} @test_usub2_poison(i8 %V) {
129 ; CHECK-LABEL: @test_usub2_poison(
130 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
132 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 poison)
136 define {i8, i1} @test_usub3(i8 %V) {
137 ; CHECK-LABEL: @test_usub3(
138 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
140 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 undef, i8 %V)
144 define {i8, i1} @test_usub3_poison(i8 %V) {
145 ; CHECK-LABEL: @test_usub3_poison(
146 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
148 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 poison, i8 %V)
152 define {i8, i1} @test_ssub1(i8 %V) {
153 ; CHECK-LABEL: @test_ssub1(
154 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
156 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 %V)
160 define {i8, i1} @test_ssub2(i8 %V) {
161 ; CHECK-LABEL: @test_ssub2(
162 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
164 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 undef)
168 define {i8, i1} @test_ssub2_poison(i8 %V) {
169 ; CHECK-LABEL: @test_ssub2_poison(
170 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
172 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 poison)
176 define {i8, i1} @test_ssub3(i8 %V) {
177 ; CHECK-LABEL: @test_ssub3(
178 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
180 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 undef, i8 %V)
184 define {i8, i1} @test_ssub3_poison(i8 %V) {
185 ; CHECK-LABEL: @test_ssub3_poison(
186 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
188 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 poison, i8 %V)
192 define {i8, i1} @test_umul1(i8 %V) {
193 ; CHECK-LABEL: @test_umul1(
194 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
196 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 0)
200 define {i8, i1} @test_umul2(i8 %V) {
201 ; CHECK-LABEL: @test_umul2(
202 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
204 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 undef)
208 define {i8, i1} @test_umul2_poison(i8 %V) {
209 ; CHECK-LABEL: @test_umul2_poison(
210 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
212 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 poison)
216 define {i8, i1} @test_umul3(i8 %V) {
217 ; CHECK-LABEL: @test_umul3(
218 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
220 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 0, i8 %V)
224 define {i8, i1} @test_umul4(i8 %V) {
225 ; CHECK-LABEL: @test_umul4(
226 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
228 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 undef, i8 %V)
232 define {i8, i1} @test_umul4_poison(i8 %V) {
233 ; CHECK-LABEL: @test_umul4_poison(
234 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
236 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 poison, i8 %V)
240 define {i8, i1} @test_smul1(i8 %V) {
241 ; CHECK-LABEL: @test_smul1(
242 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
244 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 0)
248 define {i8, i1} @test_smul2(i8 %V) {
249 ; CHECK-LABEL: @test_smul2(
250 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
252 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 undef)
256 define {i8, i1} @test_smul2_poison(i8 %V) {
257 ; CHECK-LABEL: @test_smul2_poison(
258 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
260 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 poison)
264 define {i8, i1} @test_smul3(i8 %V) {
265 ; CHECK-LABEL: @test_smul3(
266 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
268 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 0, i8 %V)
272 define {i8, i1} @test_smul4(i8 %V) {
273 ; CHECK-LABEL: @test_smul4(
274 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
276 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 undef, i8 %V)
280 define {i8, i1} @test_smul4_poison(i8 %V) {
281 ; CHECK-LABEL: @test_smul4_poison(
282 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
284 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 poison, i8 %V)
288 ; Test a non-intrinsic that we know about as a library call.
289 declare float @fabs(float %x)
291 define float @test_fabs_libcall() {
292 ; CHECK-LABEL: @test_fabs_libcall(
293 ; CHECK-NEXT: [[X:%.*]] = call float @fabs(float -4.200000e+01)
294 ; CHECK-NEXT: ret float 4.200000e+01
297 %x = call float @fabs(float -42.0)
298 ; This is still a real function call, so instsimplify won't nuke it -- other
299 ; passes have to do that.
305 declare float @llvm.fabs.f32(float) nounwind readnone
306 declare float @llvm.floor.f32(float) nounwind readnone
307 declare float @llvm.ceil.f32(float) nounwind readnone
308 declare float @llvm.trunc.f32(float) nounwind readnone
309 declare float @llvm.rint.f32(float) nounwind readnone
310 declare float @llvm.nearbyint.f32(float) nounwind readnone
311 declare float @llvm.canonicalize.f32(float) nounwind readnone
313 ; Test idempotent intrinsics
314 define float @test_idempotence(float %a) {
315 ; CHECK-LABEL: @test_idempotence(
316 ; CHECK-NEXT: [[A0:%.*]] = call float @llvm.fabs.f32(float [[A:%.*]])
317 ; CHECK-NEXT: [[B0:%.*]] = call float @llvm.floor.f32(float [[A]])
318 ; CHECK-NEXT: [[C0:%.*]] = call float @llvm.ceil.f32(float [[A]])
319 ; CHECK-NEXT: [[D0:%.*]] = call float @llvm.trunc.f32(float [[A]])
320 ; CHECK-NEXT: [[E0:%.*]] = call float @llvm.rint.f32(float [[A]])
321 ; CHECK-NEXT: [[F0:%.*]] = call float @llvm.nearbyint.f32(float [[A]])
322 ; CHECK-NEXT: [[G0:%.*]] = call float @llvm.canonicalize.f32(float [[A]])
323 ; CHECK-NEXT: [[R0:%.*]] = fadd float [[A0]], [[B0]]
324 ; CHECK-NEXT: [[R1:%.*]] = fadd float [[R0]], [[C0]]
325 ; CHECK-NEXT: [[R2:%.*]] = fadd float [[R1]], [[D0]]
326 ; CHECK-NEXT: [[R3:%.*]] = fadd float [[R2]], [[E0]]
327 ; CHECK-NEXT: [[R4:%.*]] = fadd float [[R3]], [[F0]]
328 ; CHECK-NEXT: [[R5:%.*]] = fadd float [[R4]], [[G0]]
329 ; CHECK-NEXT: ret float [[R5]]
332 %a0 = call float @llvm.fabs.f32(float %a)
333 %a1 = call float @llvm.fabs.f32(float %a0)
335 %b0 = call float @llvm.floor.f32(float %a)
336 %b1 = call float @llvm.floor.f32(float %b0)
338 %c0 = call float @llvm.ceil.f32(float %a)
339 %c1 = call float @llvm.ceil.f32(float %c0)
341 %d0 = call float @llvm.trunc.f32(float %a)
342 %d1 = call float @llvm.trunc.f32(float %d0)
344 %e0 = call float @llvm.rint.f32(float %a)
345 %e1 = call float @llvm.rint.f32(float %e0)
347 %f0 = call float @llvm.nearbyint.f32(float %a)
348 %f1 = call float @llvm.nearbyint.f32(float %f0)
350 %g0 = call float @llvm.canonicalize.f32(float %a)
351 %g1 = call float @llvm.canonicalize.f32(float %g0)
353 %r0 = fadd float %a1, %b1
354 %r1 = fadd float %r0, %c1
355 %r2 = fadd float %r1, %d1
356 %r3 = fadd float %r2, %e1
357 %r4 = fadd float %r3, %f1
358 %r5 = fadd float %r4, %g1
363 define i8* @operator_new() {
364 ; CHECK-LABEL: @operator_new(
366 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @_Znwm(i64 8)
367 ; CHECK-NEXT: br i1 false, label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]]
368 ; CHECK: cast.notnull:
369 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4
370 ; CHECK-NEXT: br label [[CAST_END]]
372 ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ]
373 ; CHECK-NEXT: ret i8* [[CAST_RESULT]]
376 %call = tail call noalias i8* @_Znwm(i64 8)
377 %cmp = icmp eq i8* %call, null
378 br i1 %cmp, label %cast.end, label %cast.notnull
380 cast.notnull: ; preds = %entry
381 %add.ptr = getelementptr inbounds i8, i8* %call, i64 4
384 cast.end: ; preds = %cast.notnull, %entry
385 %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ]
390 declare nonnull noalias i8* @_Znwm(i64)
392 %"struct.std::nothrow_t" = type { i8 }
393 @_ZSt7nothrow = external global %"struct.std::nothrow_t"
395 define i8* @operator_new_nothrow_t() {
396 ; CHECK-LABEL: @operator_new_nothrow_t(
398 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @_ZnamRKSt9nothrow_t(i64 8, %"struct.std::nothrow_t"* @_ZSt7nothrow)
399 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null
400 ; CHECK-NEXT: br i1 [[CMP]], label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]]
401 ; CHECK: cast.notnull:
402 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4
403 ; CHECK-NEXT: br label [[CAST_END]]
405 ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ]
406 ; CHECK-NEXT: ret i8* [[CAST_RESULT]]
409 %call = tail call noalias i8* @_ZnamRKSt9nothrow_t(i64 8, %"struct.std::nothrow_t"* @_ZSt7nothrow)
410 %cmp = icmp eq i8* %call, null
411 br i1 %cmp, label %cast.end, label %cast.notnull
413 cast.notnull: ; preds = %entry
414 %add.ptr = getelementptr inbounds i8, i8* %call, i64 4
417 cast.end: ; preds = %cast.notnull, %entry
418 %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ]
423 declare i8* @_ZnamRKSt9nothrow_t(i64, %"struct.std::nothrow_t"*) nounwind
425 define i8* @malloc_can_return_null() {
426 ; CHECK-LABEL: @malloc_can_return_null(
428 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @malloc(i64 8)
429 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null
430 ; CHECK-NEXT: br i1 [[CMP]], label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]]
431 ; CHECK: cast.notnull:
432 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4
433 ; CHECK-NEXT: br label [[CAST_END]]
435 ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ]
436 ; CHECK-NEXT: ret i8* [[CAST_RESULT]]
439 %call = tail call noalias i8* @malloc(i64 8)
440 %cmp = icmp eq i8* %call, null
441 br i1 %cmp, label %cast.end, label %cast.notnull
443 cast.notnull: ; preds = %entry
444 %add.ptr = getelementptr inbounds i8, i8* %call, i64 4
447 cast.end: ; preds = %cast.notnull, %entry
448 %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ]
453 define i32 @call_null() {
454 ; CHECK-LABEL: @call_null(
456 ; CHECK-NEXT: [[CALL:%.*]] = call i32 null()
457 ; CHECK-NEXT: ret i32 poison
460 %call = call i32 null()
464 define i32 @call_undef() {
465 ; CHECK-LABEL: @call_undef(
467 ; CHECK-NEXT: [[CALL:%.*]] = call i32 undef()
468 ; CHECK-NEXT: ret i32 poison
471 %call = call i32 undef()
475 @GV = private constant [8 x i32] [i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49]
477 define <8 x i32> @partial_masked_load() {
478 ; CHECK-LABEL: @partial_masked_load(
479 ; CHECK-NEXT: ret <8 x i32> <i32 undef, i32 undef, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47>
481 %masked.load = call <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>* bitcast (i32* getelementptr ([8 x i32], [8 x i32]* @GV, i64 0, i64 -2) to <8 x i32>*), i32 4, <8 x i1> <i1 false, i1 false, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
482 ret <8 x i32> %masked.load
485 define <8 x i32> @masked_load_undef_mask(<8 x i32>* %V) {
486 ; CHECK-LABEL: @masked_load_undef_mask(
487 ; CHECK-NEXT: ret <8 x i32> <i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0>
489 %masked.load = call <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>* %V, i32 4, <8 x i1> undef, <8 x i32> <i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0>)
490 ret <8 x i32> %masked.load
493 declare noalias i8* @malloc(i64)
495 declare <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>*, i32, <8 x i1>, <8 x i32>)
497 declare double @llvm.powi.f64.i16(double, i16)
498 declare <2 x double> @llvm.powi.v2f64.i16(<2 x double>, i16)
499 declare double @llvm.powi.f64.i32(double, i32)
500 declare <2 x double> @llvm.powi.v2f64.i32(<2 x double>, i32)
502 define double @constant_fold_powi() {
503 ; CHECK-LABEL: @constant_fold_powi(
504 ; CHECK-NEXT: ret double 9.000000e+00
506 %t0 = call double @llvm.powi.f64.i32(double 3.00000e+00, i32 2)
510 define double @constant_fold_powi_i16() {
511 ; CHECK-LABEL: @constant_fold_powi_i16(
512 ; CHECK-NEXT: ret double 9.000000e+00
514 %t0 = call double @llvm.powi.f64.i16(double 3.00000e+00, i16 2)
518 define <2 x double> @constant_fold_powi_vec() {
519 ; CHECK-LABEL: @constant_fold_powi_vec(
520 ; CHECK-NEXT: ret <2 x double> <double 9.000000e+00, double 2.500000e+01>
522 %t0 = call <2 x double> @llvm.powi.v2f64.i32(<2 x double> <double 3.00000e+00, double 5.00000e+00>, i32 2)
526 define <2 x double> @constant_fold_powi_vec_i16() {
527 ; CHECK-LABEL: @constant_fold_powi_vec_i16(
528 ; CHECK-NEXT: ret <2 x double> <double 9.000000e+00, double 2.500000e+01>
530 %t0 = call <2 x double> @llvm.powi.v2f64.i16(<2 x double> <double 3.00000e+00, double 5.00000e+00>, i16 2)
534 declare i8 @llvm.fshl.i8(i8, i8, i8)
535 declare i9 @llvm.fshr.i9(i9, i9, i9)
536 declare <2 x i7> @llvm.fshl.v2i7(<2 x i7>, <2 x i7>, <2 x i7>)
537 declare <2 x i8> @llvm.fshr.v2i8(<2 x i8>, <2 x i8>, <2 x i8>)
539 define i8 @fshl_no_shift(i8 %x, i8 %y) {
540 ; CHECK-LABEL: @fshl_no_shift(
541 ; CHECK-NEXT: ret i8 [[X:%.*]]
543 %z = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 0)
547 define i9 @fshr_no_shift(i9 %x, i9 %y) {
548 ; CHECK-LABEL: @fshr_no_shift(
549 ; CHECK-NEXT: ret i9 [[Y:%.*]]
551 %z = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 0)
555 define i8 @fshl_no_shift_modulo_bitwidth(i8 %x, i8 %y) {
556 ; CHECK-LABEL: @fshl_no_shift_modulo_bitwidth(
557 ; CHECK-NEXT: ret i8 [[X:%.*]]
559 %z = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 40)
563 define i9 @fshr_no_shift_modulo_bitwidth(i9 %x, i9 %y) {
564 ; CHECK-LABEL: @fshr_no_shift_modulo_bitwidth(
565 ; CHECK-NEXT: ret i9 [[Y:%.*]]
567 %z = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 189)
571 define <2 x i7> @fshl_no_shift_modulo_bitwidth_splat(<2 x i7> %x, <2 x i7> %y) {
572 ; CHECK-LABEL: @fshl_no_shift_modulo_bitwidth_splat(
573 ; CHECK-NEXT: ret <2 x i7> [[X:%.*]]
575 %z = call <2 x i7> @llvm.fshl.v2i7(<2 x i7> %x, <2 x i7> %y, <2 x i7> <i7 21, i7 21>)
579 define <2 x i8> @fshr_no_shift_modulo_bitwidth_splat(<2 x i8> %x, <2 x i8> %y) {
580 ; CHECK-LABEL: @fshr_no_shift_modulo_bitwidth_splat(
581 ; CHECK-NEXT: ret <2 x i8> [[Y:%.*]]
583 %z = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> %x, <2 x i8> %y, <2 x i8> <i8 72, i8 72>)
587 ; If y is poison, eliminating the guard is not safe.
589 define i8 @fshl_zero_shift_guard(i8 %x, i8 %y, i8 %sh) {
590 ; CHECK-LABEL: @fshl_zero_shift_guard(
591 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[SH:%.*]], 0
592 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[SH]])
593 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[F]]
594 ; CHECK-NEXT: ret i8 [[S]]
596 %c = icmp eq i8 %sh, 0
597 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
598 %s = select i1 %c, i8 %x, i8 %f
602 ; If y is poison, eliminating the guard is not safe.
604 define i8 @fshl_zero_shift_guard_swapped(i8 %x, i8 %y, i8 %sh) {
605 ; CHECK-LABEL: @fshl_zero_shift_guard_swapped(
606 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[SH:%.*]], 0
607 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[SH]])
608 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[F]], i8 [[X]]
609 ; CHECK-NEXT: ret i8 [[S]]
611 %c = icmp ne i8 %sh, 0
612 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
613 %s = select i1 %c, i8 %f, i8 %x
617 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
619 define i8 @fshl_zero_shift_guard_inverted(i8 %x, i8 %y, i8 %sh) {
620 ; CHECK-LABEL: @fshl_zero_shift_guard_inverted(
621 ; CHECK-NEXT: ret i8 [[X:%.*]]
623 %c = icmp eq i8 %sh, 0
624 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
625 %s = select i1 %c, i8 %f, i8 %x
629 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
631 define i8 @fshl_zero_shift_guard_inverted_swapped(i8 %x, i8 %y, i8 %sh) {
632 ; CHECK-LABEL: @fshl_zero_shift_guard_inverted_swapped(
633 ; CHECK-NEXT: ret i8 [[X:%.*]]
635 %c = icmp ne i8 %sh, 0
636 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
637 %s = select i1 %c, i8 %x, i8 %f
641 ; If x is poison, eliminating the guard is not safe.
643 define i9 @fshr_zero_shift_guard(i9 %x, i9 %y, i9 %sh) {
644 ; CHECK-LABEL: @fshr_zero_shift_guard(
645 ; CHECK-NEXT: [[C:%.*]] = icmp eq i9 [[SH:%.*]], 0
646 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[Y:%.*]], i9 [[SH]])
647 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i9 [[Y]], i9 [[F]]
648 ; CHECK-NEXT: ret i9 [[S]]
650 %c = icmp eq i9 %sh, 0
651 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
652 %s = select i1 %c, i9 %y, i9 %f
656 ; If x is poison, eliminating the guard is not safe.
658 define i9 @fshr_zero_shift_guard_swapped(i9 %x, i9 %y, i9 %sh) {
659 ; CHECK-LABEL: @fshr_zero_shift_guard_swapped(
660 ; CHECK-NEXT: [[C:%.*]] = icmp ne i9 [[SH:%.*]], 0
661 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[Y:%.*]], i9 [[SH]])
662 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i9 [[F]], i9 [[Y]]
663 ; CHECK-NEXT: ret i9 [[S]]
665 %c = icmp ne i9 %sh, 0
666 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
667 %s = select i1 %c, i9 %f, i9 %y
671 ; When the shift amount is 0, fshr returns its 2nd parameter (y), so everything is deleted.
673 define i9 @fshr_zero_shift_guard_inverted(i9 %x, i9 %y, i9 %sh) {
674 ; CHECK-LABEL: @fshr_zero_shift_guard_inverted(
675 ; CHECK-NEXT: ret i9 [[Y:%.*]]
677 %c = icmp eq i9 %sh, 0
678 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
679 %s = select i1 %c, i9 %f, i9 %y
683 ; When the shift amount is 0, fshr returns its 2nd parameter (y), so everything is deleted.
685 define i9 @fshr_zero_shift_guard_inverted_swapped(i9 %x, i9 %y, i9 %sh) {
686 ; CHECK-LABEL: @fshr_zero_shift_guard_inverted_swapped(
687 ; CHECK-NEXT: ret i9 [[Y:%.*]]
689 %c = icmp ne i9 %sh, 0
690 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
691 %s = select i1 %c, i9 %y, i9 %f
695 ; When the shift amount is 0, fshl returns its 1st parameter (x), so the guard is not needed.
697 define i8 @rotl_zero_shift_guard(i8 %x, i8 %sh) {
698 ; CHECK-LABEL: @rotl_zero_shift_guard(
699 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[SH:%.*]])
700 ; CHECK-NEXT: ret i8 [[F]]
702 %c = icmp eq i8 %sh, 0
703 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
704 %s = select i1 %c, i8 %x, i8 %f
708 ; When the shift amount is 0, fshl returns its 1st parameter (x), so the guard is not needed.
710 define i8 @rotl_zero_shift_guard_swapped(i8 %x, i8 %sh) {
711 ; CHECK-LABEL: @rotl_zero_shift_guard_swapped(
712 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[SH:%.*]])
713 ; CHECK-NEXT: ret i8 [[F]]
715 %c = icmp ne i8 %sh, 0
716 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
717 %s = select i1 %c, i8 %f, i8 %x
721 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
723 define i8 @rotl_zero_shift_guard_inverted(i8 %x, i8 %sh) {
724 ; CHECK-LABEL: @rotl_zero_shift_guard_inverted(
725 ; CHECK-NEXT: ret i8 [[X:%.*]]
727 %c = icmp eq i8 %sh, 0
728 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
729 %s = select i1 %c, i8 %f, i8 %x
733 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
735 define i8 @rotl_zero_shift_guard_inverted_swapped(i8 %x, i8 %sh) {
736 ; CHECK-LABEL: @rotl_zero_shift_guard_inverted_swapped(
737 ; CHECK-NEXT: ret i8 [[X:%.*]]
739 %c = icmp ne i8 %sh, 0
740 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
741 %s = select i1 %c, i8 %x, i8 %f
745 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so the guard is not needed.
747 define i9 @rotr_zero_shift_guard(i9 %x, i9 %sh) {
748 ; CHECK-LABEL: @rotr_zero_shift_guard(
749 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[X]], i9 [[SH:%.*]])
750 ; CHECK-NEXT: ret i9 [[F]]
752 %c = icmp eq i9 %sh, 0
753 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
754 %s = select i1 %c, i9 %x, i9 %f
758 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so the guard is not needed.
760 define i9 @rotr_zero_shift_guard_swapped(i9 %x, i9 %sh) {
761 ; CHECK-LABEL: @rotr_zero_shift_guard_swapped(
762 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[X]], i9 [[SH:%.*]])
763 ; CHECK-NEXT: ret i9 [[F]]
765 %c = icmp ne i9 %sh, 0
766 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
767 %s = select i1 %c, i9 %f, i9 %x
771 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so everything is deleted.
773 define i9 @rotr_zero_shift_guard_inverted(i9 %x, i9 %sh) {
774 ; CHECK-LABEL: @rotr_zero_shift_guard_inverted(
775 ; CHECK-NEXT: ret i9 [[X:%.*]]
777 %c = icmp eq i9 %sh, 0
778 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
779 %s = select i1 %c, i9 %f, i9 %x
783 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so everything is deleted.
785 define i9 @rotr_zero_shift_guard_inverted_swapped(i9 %x, i9 %sh) {
786 ; CHECK-LABEL: @rotr_zero_shift_guard_inverted_swapped(
787 ; CHECK-NEXT: ret i9 [[X:%.*]]
789 %c = icmp ne i9 %sh, 0
790 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
791 %s = select i1 %c, i9 %x, i9 %f
795 ; Negative test - make sure we're matching the correct parameter of fshl.
797 define i8 @fshl_zero_shift_guard_wrong_select_op(i8 %x, i8 %y, i8 %sh) {
798 ; CHECK-LABEL: @fshl_zero_shift_guard_wrong_select_op(
799 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[SH:%.*]], 0
800 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[SH]])
801 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[Y]], i8 [[F]]
802 ; CHECK-NEXT: ret i8 [[S]]
804 %c = icmp eq i8 %sh, 0
805 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
806 %s = select i1 %c, i8 %y, i8 %f
810 ; Vector types work too.
812 define <2 x i8> @rotr_zero_shift_guard_splat(<2 x i8> %x, <2 x i8> %sh) {
813 ; CHECK-LABEL: @rotr_zero_shift_guard_splat(
814 ; CHECK-NEXT: [[F:%.*]] = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[X]], <2 x i8> [[SH:%.*]])
815 ; CHECK-NEXT: ret <2 x i8> [[F]]
817 %c = icmp eq <2 x i8> %sh, zeroinitializer
818 %f = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> %x, <2 x i8> %x, <2 x i8> %sh)
819 %s = select <2 x i1> %c, <2 x i8> %x, <2 x i8> %f
823 ; If first two operands of funnel shift are undef, the result is undef
825 define i8 @fshl_ops_undef(i8 %shamt) {
826 ; CHECK-LABEL: @fshl_ops_undef(
827 ; CHECK-NEXT: ret i8 undef
829 %r = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 %shamt)
833 define i9 @fshr_ops_undef(i9 %shamt) {
834 ; CHECK-LABEL: @fshr_ops_undef(
835 ; CHECK-NEXT: ret i9 undef
837 %r = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 %shamt)
841 ; If shift amount is undef, treat it as zero, returning operand 0 or 1
843 define i8 @fshl_shift_undef(i8 %x, i8 %y) {
844 ; CHECK-LABEL: @fshl_shift_undef(
845 ; CHECK-NEXT: ret i8 [[X:%.*]]
847 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 undef)
851 define i9 @fshr_shift_undef(i9 %x, i9 %y) {
852 ; CHECK-LABEL: @fshr_shift_undef(
853 ; CHECK-NEXT: ret i9 [[Y:%.*]]
855 %r = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 undef)
859 ; If one of operands is poison, the result is poison
860 ; TODO: these should be poison
861 define i8 @fshl_ops_poison(i8 %b, i8 %shamt) {
862 ; CHECK-LABEL: @fshl_ops_poison(
863 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 poison, i8 [[B:%.*]], i8 [[SHAMT:%.*]])
864 ; CHECK-NEXT: ret i8 [[R]]
866 %r = call i8 @llvm.fshl.i8(i8 poison, i8 %b, i8 %shamt)
870 define i8 @fshl_ops_poison2(i8 %shamt) {
871 ; CHECK-LABEL: @fshl_ops_poison2(
872 ; CHECK-NEXT: ret i8 undef
874 %r = call i8 @llvm.fshl.i8(i8 poison, i8 undef, i8 %shamt)
878 define i8 @fshl_ops_poison3(i8 %a, i8 %shamt) {
879 ; CHECK-LABEL: @fshl_ops_poison3(
880 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 [[A:%.*]], i8 poison, i8 [[SHAMT:%.*]])
881 ; CHECK-NEXT: ret i8 [[R]]
883 %r = call i8 @llvm.fshl.i8(i8 %a, i8 poison, i8 %shamt)
887 define i8 @fshl_ops_poison4(i8 %shamt) {
888 ; CHECK-LABEL: @fshl_ops_poison4(
889 ; CHECK-NEXT: ret i8 undef
891 %r = call i8 @llvm.fshl.i8(i8 undef, i8 poison, i8 %shamt)
895 define i8 @fshl_ops_poison5(i8 %a, i8 %b) {
896 ; CHECK-LABEL: @fshl_ops_poison5(
897 ; CHECK-NEXT: ret i8 [[A:%.*]]
899 %r = call i8 @llvm.fshl.i8(i8 %a, i8 %b, i8 poison)
903 define i8 @fshl_ops_poison6() {
904 ; CHECK-LABEL: @fshl_ops_poison6(
905 ; CHECK-NEXT: ret i8 undef
907 %r = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 poison)
911 define i9 @fshr_ops_poison(i9 %b, i9 %shamt) {
912 ; CHECK-LABEL: @fshr_ops_poison(
913 ; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 poison, i9 [[B:%.*]], i9 [[SHAMT:%.*]])
914 ; CHECK-NEXT: ret i9 [[R]]
916 %r = call i9 @llvm.fshr.i9(i9 poison, i9 %b, i9 %shamt)
920 define i9 @fshr_ops_poison2(i9 %shamt) {
921 ; CHECK-LABEL: @fshr_ops_poison2(
922 ; CHECK-NEXT: ret i9 undef
924 %r = call i9 @llvm.fshr.i9(i9 poison, i9 undef, i9 %shamt)
928 define i9 @fshr_ops_poison3(i9 %a, i9 %shamt) {
929 ; CHECK-LABEL: @fshr_ops_poison3(
930 ; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 [[A:%.*]], i9 poison, i9 [[SHAMT:%.*]])
931 ; CHECK-NEXT: ret i9 [[R]]
933 %r = call i9 @llvm.fshr.i9(i9 %a, i9 poison, i9 %shamt)
937 define i9 @fshr_ops_poison4(i9 %shamt) {
938 ; CHECK-LABEL: @fshr_ops_poison4(
939 ; CHECK-NEXT: ret i9 undef
941 %r = call i9 @llvm.fshr.i9(i9 undef, i9 poison, i9 %shamt)
945 define i9 @fshr_ops_poison5(i9 %a, i9 %b) {
946 ; CHECK-LABEL: @fshr_ops_poison5(
947 ; CHECK-NEXT: ret i9 [[B:%.*]]
949 %r = call i9 @llvm.fshr.i9(i9 %a, i9 %b, i9 poison)
953 define i9 @fshr_ops_poison6() {
954 ; CHECK-LABEL: @fshr_ops_poison6(
955 ; CHECK-NEXT: ret i9 undef
957 %r = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 poison)
961 declare double @llvm.fma.f64(double,double,double)
962 declare double @llvm.fmuladd.f64(double,double,double)
964 define double @fma_undef_op0(double %x, double %y) {
965 ; CHECK-LABEL: @fma_undef_op0(
966 ; CHECK-NEXT: ret double 0x7FF8000000000000
968 %r = call double @llvm.fma.f64(double undef, double %x, double %y)
972 define double @fma_poison_op0(double %x, double %y) {
973 ; CHECK-LABEL: @fma_poison_op0(
974 ; CHECK-NEXT: ret double poison
976 %r = call double @llvm.fma.f64(double poison, double %x, double %y)
980 define double @fma_undef_op1(double %x, double %y) {
981 ; CHECK-LABEL: @fma_undef_op1(
982 ; CHECK-NEXT: ret double 0x7FF8000000000000
984 %r = call double @llvm.fma.f64(double %x, double undef, double %y)
988 define double @fma_poison_op1(double %x, double %y) {
989 ; CHECK-LABEL: @fma_poison_op1(
990 ; CHECK-NEXT: ret double poison
992 %r = call double @llvm.fma.f64(double %x, double poison, double %y)
996 define double @fma_undef_op2(double %x, double %y) {
997 ; CHECK-LABEL: @fma_undef_op2(
998 ; CHECK-NEXT: ret double 0x7FF8000000000000
1000 %r = call double @llvm.fma.f64(double %x, double %y, double undef)
1004 define double @fma_poison_op2(double %x, double %y) {
1005 ; CHECK-LABEL: @fma_poison_op2(
1006 ; CHECK-NEXT: ret double poison
1008 %r = call double @llvm.fma.f64(double %x, double %y, double poison)
1012 define double @fma_undef_op0_poison_op1(double %x) {
1013 ; CHECK-LABEL: @fma_undef_op0_poison_op1(
1014 ; CHECK-NEXT: ret double poison
1016 %r = call double @llvm.fma.f64(double undef, double poison, double %x)
1020 define double @fma_undef_op0_poison_op2(double %x) {
1021 ; CHECK-LABEL: @fma_undef_op0_poison_op2(
1022 ; CHECK-NEXT: ret double poison
1024 %r = call double @llvm.fma.f64(double undef, double %x, double poison)
1028 define double @fmuladd_undef_op0(double %x, double %y) {
1029 ; CHECK-LABEL: @fmuladd_undef_op0(
1030 ; CHECK-NEXT: ret double 0x7FF8000000000000
1032 %r = call double @llvm.fmuladd.f64(double undef, double %x, double %y)
1036 define double @fmuladd_poison_op0(double %x, double %y) {
1037 ; CHECK-LABEL: @fmuladd_poison_op0(
1038 ; CHECK-NEXT: ret double poison
1040 %r = call double @llvm.fmuladd.f64(double poison, double %x, double %y)
1044 define double @fmuladd_undef_op1(double %x, double %y) {
1045 ; CHECK-LABEL: @fmuladd_undef_op1(
1046 ; CHECK-NEXT: ret double 0x7FF8000000000000
1048 %r = call double @llvm.fmuladd.f64(double %x, double undef, double %y)
1052 define double @fmuladd_poison_op1(double %x, double %y) {
1053 ; CHECK-LABEL: @fmuladd_poison_op1(
1054 ; CHECK-NEXT: ret double poison
1056 %r = call double @llvm.fmuladd.f64(double %x, double poison, double %y)
1060 define double @fmuladd_undef_op2(double %x, double %y) {
1061 ; CHECK-LABEL: @fmuladd_undef_op2(
1062 ; CHECK-NEXT: ret double 0x7FF8000000000000
1064 %r = call double @llvm.fmuladd.f64(double %x, double %y, double undef)
1068 define double @fmuladd_poison_op2(double %x, double %y) {
1069 ; CHECK-LABEL: @fmuladd_poison_op2(
1070 ; CHECK-NEXT: ret double poison
1072 %r = call double @llvm.fmuladd.f64(double %x, double %y, double poison)
1076 define double @fmuladd_nan_op0_poison_op1(double %x) {
1077 ; CHECK-LABEL: @fmuladd_nan_op0_poison_op1(
1078 ; CHECK-NEXT: ret double poison
1080 %r = call double @llvm.fmuladd.f64(double 0x7ff8000000000000, double poison, double %x)
1084 define double @fmuladd_nan_op1_poison_op2(double %x) {
1085 ; CHECK-LABEL: @fmuladd_nan_op1_poison_op2(
1086 ; CHECK-NEXT: ret double poison
1088 %r = call double @llvm.fmuladd.f64(double %x, double 0x7ff8000000000000, double poison)
1092 define double @fma_nan_op0(double %x, double %y) {
1093 ; CHECK-LABEL: @fma_nan_op0(
1094 ; CHECK-NEXT: ret double 0x7FF8000000000000
1096 %r = call double @llvm.fma.f64(double 0x7ff8000000000000, double %x, double %y)
1100 define double @fma_nan_op1(double %x, double %y) {
1101 ; CHECK-LABEL: @fma_nan_op1(
1102 ; CHECK-NEXT: ret double 0x7FF8000000000001
1104 %r = call double @llvm.fma.f64(double %x, double 0x7ff8000000000001, double %y)
1108 define double @fma_nan_op2(double %x, double %y) {
1109 ; CHECK-LABEL: @fma_nan_op2(
1110 ; CHECK-NEXT: ret double 0x7FF8000000000002
1112 %r = call double @llvm.fma.f64(double %x, double %y, double 0x7ff8000000000002)
1116 define double @fmuladd_nan_op0_op1(double %x) {
1117 ; CHECK-LABEL: @fmuladd_nan_op0_op1(
1118 ; CHECK-NEXT: ret double 0x7FF8000000001234
1120 %r = call double @llvm.fmuladd.f64(double 0x7ff8000000001234, double 0x7ff800000000dead, double %x)
1124 define double @fmuladd_nan_op0_op2(double %x) {
1125 ; CHECK-LABEL: @fmuladd_nan_op0_op2(
1126 ; CHECK-NEXT: ret double 0x7FF8000000005678
1128 %r = call double @llvm.fmuladd.f64(double 0x7ff8000000005678, double %x, double 0x7ff800000000dead)
1132 define double @fmuladd_nan_op1_op2(double %x) {
1133 ; CHECK-LABEL: @fmuladd_nan_op1_op2(
1134 ; CHECK-NEXT: ret double 0x7FF80000AAAAAAAA
1136 %r = call double @llvm.fmuladd.f64(double %x, double 0x7ff80000aaaaaaaa, double 0x7ff800000000dead)
1140 define double @fma_nan_multiplicand_inf_zero(double %x) {
1141 ; CHECK-LABEL: @fma_nan_multiplicand_inf_zero(
1142 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double 0x7FF0000000000000, double 0.000000e+00, double [[X:%.*]])
1143 ; CHECK-NEXT: ret double [[R]]
1145 %r = call double @llvm.fma.f64(double 0x7ff0000000000000, double 0.0, double %x)
1149 define double @fma_nan_multiplicand_zero_inf(double %x) {
1150 ; CHECK-LABEL: @fma_nan_multiplicand_zero_inf(
1151 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double 0.000000e+00, double 0x7FF0000000000000, double [[X:%.*]])
1152 ; CHECK-NEXT: ret double [[R]]
1154 %r = call double @llvm.fma.f64(double 0.0, double 0x7ff0000000000000, double %x)
1158 define double @fma_nan_addend_inf_neginf(double %x, i32 %y) {
1159 ; CHECK-LABEL: @fma_nan_addend_inf_neginf(
1160 ; CHECK-NEXT: [[NOTNAN:%.*]] = uitofp i32 [[Y:%.*]] to double
1161 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double 0x7FF0000000000000, double [[NOTNAN]], double 0xFFF0000000000000)
1162 ; CHECK-NEXT: ret double [[R]]
1164 %notnan = uitofp i32 %y to double
1165 %r = call double @llvm.fma.f64(double 0x7ff0000000000000, double %notnan, double 0xfff0000000000000)
1169 define double @fma_nan_addend_neginf_inf(double %x, i1 %y) {
1170 ; CHECK-LABEL: @fma_nan_addend_neginf_inf(
1171 ; CHECK-NEXT: [[NOTNAN:%.*]] = select i1 [[Y:%.*]], double 4.200000e+01, double -1.000000e-01
1172 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double [[NOTNAN]], double 0xFFF0000000000000, double 0x7FF0000000000000)
1173 ; CHECK-NEXT: ret double [[R]]
1175 %notnan = select i1 %y, double 42.0, double -0.1
1176 %r = call double @llvm.fma.f64(double %notnan, double 0xfff0000000000000, double 0x7ff0000000000000)
1180 define double @fmuladd_nan_multiplicand_neginf_zero(double %x) {
1181 ; CHECK-LABEL: @fmuladd_nan_multiplicand_neginf_zero(
1182 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double 0xFFF0000000000000, double 0.000000e+00, double [[X:%.*]])
1183 ; CHECK-NEXT: ret double [[R]]
1185 %r = call double @llvm.fmuladd.f64(double 0xfff0000000000000, double 0.0, double %x)
1189 define double @fmuladd_nan_multiplicand_negzero_inf(double %x) {
1190 ; CHECK-LABEL: @fmuladd_nan_multiplicand_negzero_inf(
1191 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double -0.000000e+00, double 0x7FF0000000000000, double [[X:%.*]])
1192 ; CHECK-NEXT: ret double [[R]]
1194 %r = call double @llvm.fmuladd.f64(double -0.0, double 0x7ff0000000000000, double %x)
1198 define double @fmuladd_nan_addend_inf_neginf(double %x, i32 %y) {
1199 ; CHECK-LABEL: @fmuladd_nan_addend_inf_neginf(
1200 ; CHECK-NEXT: [[NOTNAN:%.*]] = sitofp i32 [[Y:%.*]] to double
1201 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double 0x7FF0000000000000, double [[NOTNAN]], double 0xFFF0000000000000)
1202 ; CHECK-NEXT: ret double [[R]]
1204 %notnan = sitofp i32 %y to double
1205 %r = call double @llvm.fmuladd.f64(double 0x7ff0000000000000, double %notnan, double 0xfff0000000000000)
1209 define double @fmuladd_nan_addend_neginf_inf(double %x, i1 %y) {
1210 ; CHECK-LABEL: @fmuladd_nan_addend_neginf_inf(
1211 ; CHECK-NEXT: [[NOTNAN:%.*]] = select i1 [[Y:%.*]], double 4.200000e+01, double -1.000000e-01
1212 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double [[NOTNAN]], double 0xFFF0000000000000, double 0x7FF0000000000000)
1213 ; CHECK-NEXT: ret double [[R]]
1215 %notnan = select i1 %y, double 42.0, double -0.1
1216 %r = call double @llvm.fmuladd.f64(double %notnan, double 0xfff0000000000000, double 0x7ff0000000000000)
1220 declare float @llvm.copysign.f32(float, float)
1221 declare <2 x double> @llvm.copysign.v2f64(<2 x double>, <2 x double>)
1223 define float @copysign_same_operand(float %x) {
1224 ; CHECK-LABEL: @copysign_same_operand(
1225 ; CHECK-NEXT: ret float [[X:%.*]]
1227 %r = call float @llvm.copysign.f32(float %x, float %x)
1231 define <2 x double> @copysign_same_operand_vec(<2 x double> %x) {
1232 ; CHECK-LABEL: @copysign_same_operand_vec(
1233 ; CHECK-NEXT: ret <2 x double> [[X:%.*]]
1235 %r = call <2 x double> @llvm.copysign.v2f64(<2 x double> %x, <2 x double> %x)
1239 define float @negated_sign_arg(float %x) {
1240 ; CHECK-LABEL: @negated_sign_arg(
1241 ; CHECK-NEXT: [[NEGX:%.*]] = fsub ninf float -0.000000e+00, [[X:%.*]]
1242 ; CHECK-NEXT: ret float [[NEGX]]
1244 %negx = fsub ninf float -0.0, %x
1245 %r = call arcp float @llvm.copysign.f32(float %x, float %negx)
1249 define <2 x double> @negated_sign_arg_vec(<2 x double> %x) {
1250 ; CHECK-LABEL: @negated_sign_arg_vec(
1251 ; CHECK-NEXT: [[NEGX:%.*]] = fneg afn <2 x double> [[X:%.*]]
1252 ; CHECK-NEXT: ret <2 x double> [[NEGX]]
1254 %negx = fneg afn <2 x double> %x
1255 %r = call arcp <2 x double> @llvm.copysign.v2f64(<2 x double> %x, <2 x double> %negx)
1259 define float @negated_mag_arg(float %x) {
1260 ; CHECK-LABEL: @negated_mag_arg(
1261 ; CHECK-NEXT: ret float [[X:%.*]]
1263 %negx = fneg nnan float %x
1264 %r = call ninf float @llvm.copysign.f32(float %negx, float %x)
1268 define <2 x double> @negated_mag_arg_vec(<2 x double> %x) {
1269 ; CHECK-LABEL: @negated_mag_arg_vec(
1270 ; CHECK-NEXT: ret <2 x double> [[X:%.*]]
1272 %negx = fneg afn <2 x double> %x
1273 %r = call arcp <2 x double> @llvm.copysign.v2f64(<2 x double> %negx, <2 x double> %x)
1277 ; We handle the "returned" attribute only in InstCombine, because the fact
1278 ; that this simplification may replace one call with another may cause issues
1279 ; for call graph passes.
1281 declare i32 @passthru_i32(i32 returned)
1282 declare i8* @passthru_p8(i8* returned)
1284 define i32 @returned_const_int_arg() {
1285 ; CHECK-LABEL: @returned_const_int_arg(
1286 ; CHECK-NEXT: [[X:%.*]] = call i32 @passthru_i32(i32 42)
1287 ; CHECK-NEXT: ret i32 [[X]]
1289 %x = call i32 @passthru_i32(i32 42)
1293 define i8* @returned_const_ptr_arg() {
1294 ; CHECK-LABEL: @returned_const_ptr_arg(
1295 ; CHECK-NEXT: [[X:%.*]] = call i8* @passthru_p8(i8* null)
1296 ; CHECK-NEXT: ret i8* [[X]]
1298 %x = call i8* @passthru_p8(i8* null)
1302 define i32 @returned_var_arg(i32 %arg) {
1303 ; CHECK-LABEL: @returned_var_arg(
1304 ; CHECK-NEXT: [[X:%.*]] = call i32 @passthru_i32(i32 [[ARG:%.*]])
1305 ; CHECK-NEXT: ret i32 [[X]]
1307 %x = call i32 @passthru_i32(i32 %arg)
1311 define i32 @returned_const_int_arg_musttail(i32 %arg) {
1312 ; CHECK-LABEL: @returned_const_int_arg_musttail(
1313 ; CHECK-NEXT: [[X:%.*]] = musttail call i32 @passthru_i32(i32 42)
1314 ; CHECK-NEXT: ret i32 [[X]]
1316 %x = musttail call i32 @passthru_i32(i32 42)
1320 define i32 @returned_var_arg_musttail(i32 %arg) {
1321 ; CHECK-LABEL: @returned_var_arg_musttail(
1322 ; CHECK-NEXT: [[X:%.*]] = musttail call i32 @passthru_i32(i32 [[ARG:%.*]])
1323 ; CHECK-NEXT: ret i32 [[X]]
1325 %x = musttail call i32 @passthru_i32(i32 %arg)
1329 define i32 @call_undef_musttail() {
1330 ; CHECK-LABEL: @call_undef_musttail(
1331 ; CHECK-NEXT: [[X:%.*]] = musttail call i32 undef()
1332 ; CHECK-NEXT: ret i32 [[X]]
1334 %x = musttail call i32 undef()
1338 ; This is not the builtin fmax, so we don't know anything about its behavior.
1340 declare float @fmaxf(float, float)
1342 define float @nobuiltin_fmax() {
1343 ; CHECK-LABEL: @nobuiltin_fmax(
1344 ; CHECK-NEXT: [[M:%.*]] = call float @fmaxf(float 0.000000e+00, float 1.000000e+00) #[[ATTR3:[0-9]+]]
1345 ; CHECK-NEXT: [[R:%.*]] = call float @llvm.fabs.f32(float [[M]])
1346 ; CHECK-NEXT: ret float [[R]]
1348 %m = call float @fmaxf(float 0.0, float 1.0) #0
1349 %r = call float @llvm.fabs.f32(float %m)
1354 declare i32 @llvm.ctpop.i32(i32)
1355 declare <3 x i33> @llvm.ctpop.v3i33(<3 x i33>)
1356 declare i1 @llvm.ctpop.i1(i1)
1358 define i32 @ctpop_lowbit(i32 %x) {
1359 ; CHECK-LABEL: @ctpop_lowbit(
1360 ; CHECK-NEXT: [[B:%.*]] = and i32 [[X:%.*]], 1
1361 ; CHECK-NEXT: ret i32 [[B]]
1364 %r = call i32 @llvm.ctpop.i32(i32 %b)
1368 ; Negative test - only low bit allowed
1369 ; This could be reduced by instcombine to and+shift.
1371 define i32 @ctpop_pow2(i32 %x) {
1372 ; CHECK-LABEL: @ctpop_pow2(
1373 ; CHECK-NEXT: [[B:%.*]] = and i32 [[X:%.*]], 4
1374 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.ctpop.i32(i32 [[B]])
1375 ; CHECK-NEXT: ret i32 [[R]]
1378 %r = call i32 @llvm.ctpop.i32(i32 %b)
1382 define <3 x i33> @ctpop_signbit(<3 x i33> %x) {
1383 ; CHECK-LABEL: @ctpop_signbit(
1384 ; CHECK-NEXT: [[B:%.*]] = lshr <3 x i33> [[X:%.*]], <i33 32, i33 32, i33 32>
1385 ; CHECK-NEXT: ret <3 x i33> [[B]]
1387 %b = lshr <3 x i33> %x, <i33 32, i33 32, i33 32>
1388 %r = tail call <3 x i33> @llvm.ctpop.v3i33(<3 x i33> %b)
1392 ; Negative test - only 1 bit allowed
1394 define <3 x i33> @ctpop_notsignbit(<3 x i33> %x) {
1395 ; CHECK-LABEL: @ctpop_notsignbit(
1396 ; CHECK-NEXT: [[B:%.*]] = lshr <3 x i33> [[X:%.*]], <i33 31, i33 31, i33 31>
1397 ; CHECK-NEXT: [[R:%.*]] = tail call <3 x i33> @llvm.ctpop.v3i33(<3 x i33> [[B]])
1398 ; CHECK-NEXT: ret <3 x i33> [[R]]
1400 %b = lshr <3 x i33> %x, <i33 31, i33 31, i33 31>
1401 %r = tail call <3 x i33> @llvm.ctpop.v3i33(<3 x i33> %b)
1405 define i1 @ctpop_bool(i1 %x) {
1406 ; CHECK-LABEL: @ctpop_bool(
1407 ; CHECK-NEXT: ret i1 [[X:%.*]]
1409 %r = tail call i1 @llvm.ctpop.i1(i1 %x)
1413 declare i32 @llvm.cttz.i32(i32, i1)
1414 declare <3 x i33> @llvm.cttz.v3i33(<3 x i33>, i1)
1416 define i32 @cttz_shl1(i32 %x) {
1417 ; CHECK-LABEL: @cttz_shl1(
1418 ; CHECK-NEXT: ret i32 [[X:%.*]]
1421 %r = call i32 @llvm.cttz.i32(i32 %s, i1 true)
1425 define <3 x i33> @cttz_shl1_vec(<3 x i33> %x) {
1426 ; CHECK-LABEL: @cttz_shl1_vec(
1427 ; CHECK-NEXT: ret <3 x i33> [[X:%.*]]
1429 %s = shl <3 x i33> <i33 1, i33 1, i33 undef>, %x
1430 %r = call <3 x i33> @llvm.cttz.v3i33(<3 x i33> %s, i1 false)
1434 ; Negative test - this could be generalized in instcombine though.
1436 define i32 @cttz_shl_not_low_bit(i32 %x) {
1437 ; CHECK-LABEL: @cttz_shl_not_low_bit(
1438 ; CHECK-NEXT: [[S:%.*]] = shl i32 2, [[X:%.*]]
1439 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.cttz.i32(i32 [[S]], i1 true)
1440 ; CHECK-NEXT: ret i32 [[R]]
1443 %r = call i32 @llvm.cttz.i32(i32 %s, i1 true)
1447 declare i32 @llvm.ctlz.i32(i32, i1)
1448 declare <3 x i33> @llvm.ctlz.v3i33(<3 x i33>, i1)
1450 define i32 @ctlz_lshr_sign_bit(i32 %x) {
1451 ; CHECK-LABEL: @ctlz_lshr_sign_bit(
1452 ; CHECK-NEXT: ret i32 [[X:%.*]]
1454 %s = lshr i32 2147483648, %x
1455 %r = call i32 @llvm.ctlz.i32(i32 %s, i1 true)
1459 define i32 @ctlz_lshr_negative(i32 %x) {
1460 ; CHECK-LABEL: @ctlz_lshr_negative(
1461 ; CHECK-NEXT: ret i32 [[X:%.*]]
1463 %s = lshr i32 -42, %x
1464 %r = call i32 @llvm.ctlz.i32(i32 %s, i1 true)
1468 define <3 x i33> @ctlz_lshr_sign_bit_vec(<3 x i33> %x) {
1469 ; CHECK-LABEL: @ctlz_lshr_sign_bit_vec(
1470 ; CHECK-NEXT: ret <3 x i33> [[X:%.*]]
1472 %s = lshr <3 x i33> <i33 undef, i33 4294967296, i33 4294967296>, %x
1473 %r = call <3 x i33> @llvm.ctlz.v3i33(<3 x i33> %s, i1 false)
1477 ; Negative test - this could be generalized in instcombine though.
1479 define i32 @ctlz_lshr_not_negative(i32 %x) {
1480 ; CHECK-LABEL: @ctlz_lshr_not_negative(
1481 ; CHECK-NEXT: [[S:%.*]] = lshr i32 42, [[X:%.*]]
1482 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.ctlz.i32(i32 [[S]], i1 true)
1483 ; CHECK-NEXT: ret i32 [[R]]
1485 %s = lshr i32 42, %x
1486 %r = call i32 @llvm.ctlz.i32(i32 %s, i1 true)
1490 define i32 @ctlz_ashr_sign_bit(i32 %x) {
1491 ; CHECK-LABEL: @ctlz_ashr_sign_bit(
1492 ; CHECK-NEXT: ret i32 0
1494 %s = ashr i32 2147483648, %x
1495 %r = call i32 @llvm.ctlz.i32(i32 %s, i1 false)
1499 define i32 @ctlz_ashr_negative(i32 %x) {
1500 ; CHECK-LABEL: @ctlz_ashr_negative(
1501 ; CHECK-NEXT: ret i32 0
1503 %s = ashr i32 -42, %x
1504 %r = call i32 @llvm.ctlz.i32(i32 %s, i1 false)
1508 define <3 x i33> @ctlz_ashr_sign_bit_vec(<3 x i33> %x) {
1509 ; CHECK-LABEL: @ctlz_ashr_sign_bit_vec(
1510 ; CHECK-NEXT: ret <3 x i33> zeroinitializer
1512 %s = ashr <3 x i33> <i33 4294967296, i33 undef, i33 4294967296>, %x
1513 %r = call <3 x i33> @llvm.ctlz.v3i33(<3 x i33> %s, i1 true)
1517 attributes #0 = { nobuiltin readnone }