Skip to content

Commit 765b5b8

Browse files
committed
[ConstProp] add tests for intrinsics with poison ops; NFC
1 parent 05337a7 commit 765b5b8

File tree

2 files changed

+198
-4
lines changed

2 files changed

+198
-4
lines changed

llvm/test/Transforms/InstSimplify/ConstProp/min-max.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ define <5 x i8> @smax_vec() {
293293
; CHECK-LABEL: @smax_vec(
294294
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 127, i8 127, i8 42, i8 127>
295295
;
296-
%r = call <5 x i8> @llvm.smax.v5i8(<5 x i8> <i8 undef, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 undef, i8 42, i8 127>)
296+
%r = call <5 x i8> @llvm.smax.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 127>)
297297
ret <5 x i8> %r
298298
}
299299

@@ -309,7 +309,7 @@ define <5 x i8> @smin_vec() {
309309
; CHECK-LABEL: @smin_vec(
310310
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 -128, i8 -128, i8 42, i8 -127>
311311
;
312-
%r = call <5 x i8> @llvm.smin.v5i8(<5 x i8> <i8 undef, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 undef, i8 42, i8 129>)
312+
%r = call <5 x i8> @llvm.smin.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 129>)
313313
ret <5 x i8> %r
314314
}
315315

@@ -325,7 +325,7 @@ define <5 x i8> @umax_vec() {
325325
; CHECK-LABEL: @umax_vec(
326326
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 -1, i8 -1, i8 42, i8 -128>
327327
;
328-
%r = call <5 x i8> @llvm.umax.v5i8(<5 x i8> <i8 undef, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 undef, i8 42, i8 128>)
328+
%r = call <5 x i8> @llvm.umax.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 128>)
329329
ret <5 x i8> %r
330330
}
331331

@@ -341,6 +341,6 @@ define <5 x i8> @umin_vec() {
341341
; CHECK-LABEL: @umin_vec(
342342
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 0, i8 0, i8 42, i8 42>
343343
;
344-
%r = call <5 x i8> @llvm.umin.v5i8(<5 x i8> <i8 undef, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 undef, i8 42, i8 128>)
344+
%r = call <5 x i8> @llvm.umin.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 128>)
345345
ret <5 x i8> %r
346346
}

llvm/test/Transforms/InstSimplify/ConstProp/saturating-add-sub.ll

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,197 @@ define <2 x i8> @test_ssub_vector_op1_undef_mix2() {
364364
%x = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> <i8 undef, i8 10>, <2 x i8> <i8 20, i8 undef>)
365365
ret <2 x i8> %x
366366
}
367+
368+
; Tests for poison handling
369+
370+
define i8 @test_uadd_scalar_both_poison() {
371+
; CHECK-LABEL: @test_uadd_scalar_both_poison(
372+
; CHECK-NEXT: ret i8 undef
373+
;
374+
%x = call i8 @llvm.uadd.sat.i8(i8 poison, i8 poison)
375+
ret i8 %x
376+
}
377+
378+
define i8 @test_sadd_scalar_both_poison() {
379+
; CHECK-LABEL: @test_sadd_scalar_both_poison(
380+
; CHECK-NEXT: ret i8 undef
381+
;
382+
%x = call i8 @llvm.sadd.sat.i8(i8 poison, i8 poison)
383+
ret i8 %x
384+
}
385+
386+
define i8 @test_usub_scalar_both_poison() {
387+
; CHECK-LABEL: @test_usub_scalar_both_poison(
388+
; CHECK-NEXT: ret i8 undef
389+
;
390+
%x = call i8 @llvm.usub.sat.i8(i8 poison, i8 poison)
391+
ret i8 %x
392+
}
393+
394+
define i8 @test_ssub_scalar_both_poison() {
395+
; CHECK-LABEL: @test_ssub_scalar_both_poison(
396+
; CHECK-NEXT: ret i8 undef
397+
;
398+
%x = call i8 @llvm.ssub.sat.i8(i8 poison, i8 poison)
399+
ret i8 %x
400+
}
401+
402+
define i8 @test_uadd_scalar_op2_poison() {
403+
; CHECK-LABEL: @test_uadd_scalar_op2_poison(
404+
; CHECK-NEXT: ret i8 -1
405+
;
406+
%x = call i8 @llvm.uadd.sat.i8(i8 10, i8 poison)
407+
ret i8 %x
408+
}
409+
410+
define i8 @test_sadd_scalar_op1_poison() {
411+
; CHECK-LABEL: @test_sadd_scalar_op1_poison(
412+
; CHECK-NEXT: ret i8 -1
413+
;
414+
%x = call i8 @llvm.sadd.sat.i8(i8 poison, i8 10)
415+
ret i8 %x
416+
}
417+
418+
define i8 @test_usub_scalar_op2_poison() {
419+
; CHECK-LABEL: @test_usub_scalar_op2_poison(
420+
; CHECK-NEXT: ret i8 0
421+
;
422+
%x = call i8 @llvm.usub.sat.i8(i8 10, i8 poison)
423+
ret i8 %x
424+
}
425+
426+
define i8 @test_usub_scalar_op1_poison() {
427+
; CHECK-LABEL: @test_usub_scalar_op1_poison(
428+
; CHECK-NEXT: ret i8 0
429+
;
430+
%x = call i8 @llvm.usub.sat.i8(i8 poison, i8 10)
431+
ret i8 %x
432+
}
433+
434+
define <2 x i8> @test_uadd_vector_both_poison_splat() {
435+
; CHECK-LABEL: @test_uadd_vector_both_poison_splat(
436+
; CHECK-NEXT: ret <2 x i8> undef
437+
;
438+
%x = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> poison, <2 x i8> poison)
439+
ret <2 x i8> %x
440+
}
441+
442+
define <2 x i8> @test_sadd_vector_both_poison_splat() {
443+
; CHECK-LABEL: @test_sadd_vector_both_poison_splat(
444+
; CHECK-NEXT: ret <2 x i8> undef
445+
;
446+
%x = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> poison, <2 x i8> poison)
447+
ret <2 x i8> %x
448+
}
449+
450+
define <2 x i8> @test_usub_vector_both_poison_splat() {
451+
; CHECK-LABEL: @test_usub_vector_both_poison_splat(
452+
; CHECK-NEXT: ret <2 x i8> undef
453+
;
454+
%x = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> poison, <2 x i8> poison)
455+
ret <2 x i8> %x
456+
}
457+
458+
define <2 x i8> @test_ssub_vector_both_poison_splat() {
459+
; CHECK-LABEL: @test_ssub_vector_both_poison_splat(
460+
; CHECK-NEXT: ret <2 x i8> undef
461+
;
462+
%x = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> poison, <2 x i8> poison)
463+
ret <2 x i8> %x
464+
}
465+
466+
define <2 x i8> @test_uadd_vector_op2_poison_splat() {
467+
; CHECK-LABEL: @test_uadd_vector_op2_poison_splat(
468+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
469+
;
470+
%x = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> <i8 10, i8 20>, <2 x i8> poison)
471+
ret <2 x i8> %x
472+
}
473+
474+
define <2 x i8> @test_sadd_vector_op1_poison_splat() {
475+
; CHECK-LABEL: @test_sadd_vector_op1_poison_splat(
476+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
477+
;
478+
%x = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> poison, <2 x i8> <i8 10, i8 20>)
479+
ret <2 x i8> %x
480+
}
481+
482+
define <2 x i8> @test_usub_vector_op2_poison_splat() {
483+
; CHECK-LABEL: @test_usub_vector_op2_poison_splat(
484+
; CHECK-NEXT: ret <2 x i8> zeroinitializer
485+
;
486+
%x = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> <i8 10, i8 20>, <2 x i8> poison)
487+
ret <2 x i8> %x
488+
}
489+
490+
define <2 x i8> @test_ssub_vector_op1_poison_splat() {
491+
; CHECK-LABEL: @test_ssub_vector_op1_poison_splat(
492+
; CHECK-NEXT: ret <2 x i8> zeroinitializer
493+
;
494+
%x = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> poison, <2 x i8> <i8 10, i8 20>)
495+
ret <2 x i8> %x
496+
}
497+
498+
define <2 x i8> @test_uadd_vector_op2_poison_mix1() {
499+
; CHECK-LABEL: @test_uadd_vector_op2_poison_mix1(
500+
; CHECK-NEXT: ret <2 x i8> <i8 30, i8 undef>
501+
;
502+
%x = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> <i8 10, i8 poison>, <2 x i8> <i8 20, i8 poison>)
503+
ret <2 x i8> %x
504+
}
505+
506+
define <2 x i8> @test_uadd_vector_op2_poison_mix2() {
507+
; CHECK-LABEL: @test_uadd_vector_op2_poison_mix2(
508+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
509+
;
510+
%x = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> <i8 10, i8 poison>, <2 x i8> <i8 poison, i8 20>)
511+
ret <2 x i8> %x
512+
}
513+
514+
define <2 x i8> @test_sadd_vector_op1_poison_mix1() {
515+
; CHECK-LABEL: @test_sadd_vector_op1_poison_mix1(
516+
; CHECK-NEXT: ret <2 x i8> <i8 undef, i8 30>
517+
;
518+
%x = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> <i8 poison, i8 10>, <2 x i8> <i8 poison, i8 20>)
519+
ret <2 x i8> %x
520+
}
521+
522+
define <2 x i8> @test_sadd_vector_op1_poison_mix2() {
523+
; CHECK-LABEL: @test_sadd_vector_op1_poison_mix2(
524+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
525+
;
526+
%x = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> <i8 poison, i8 10>, <2 x i8> <i8 20, i8 poison>)
527+
ret <2 x i8> %x
528+
}
529+
530+
define <2 x i8> @test_usub_vector_op2_poison_mix1() {
531+
; CHECK-LABEL: @test_usub_vector_op2_poison_mix1(
532+
; CHECK-NEXT: ret <2 x i8> <i8 0, i8 undef>
533+
;
534+
%x = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> <i8 10, i8 poison>, <2 x i8> <i8 20, i8 poison>)
535+
ret <2 x i8> %x
536+
}
537+
538+
define <2 x i8> @test_usub_vector_op2_poison_mix2() {
539+
; CHECK-LABEL: @test_usub_vector_op2_poison_mix2(
540+
; CHECK-NEXT: ret <2 x i8> zeroinitializer
541+
;
542+
%x = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> <i8 10, i8 poison>, <2 x i8> <i8 poison, i8 20>)
543+
ret <2 x i8> %x
544+
}
545+
546+
define <2 x i8> @test_ssub_vector_op1_poison_mix1() {
547+
; CHECK-LABEL: @test_ssub_vector_op1_poison_mix1(
548+
; CHECK-NEXT: ret <2 x i8> <i8 undef, i8 -10>
549+
;
550+
%x = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> <i8 poison, i8 10>, <2 x i8> <i8 poison, i8 20>)
551+
ret <2 x i8> %x
552+
}
553+
554+
define <2 x i8> @test_ssub_vector_op1_poison_mix2() {
555+
; CHECK-LABEL: @test_ssub_vector_op1_poison_mix2(
556+
; CHECK-NEXT: ret <2 x i8> zeroinitializer
557+
;
558+
%x = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> <i8 poison, i8 10>, <2 x i8> <i8 20, i8 poison>)
559+
ret <2 x i8> %x
560+
}

0 commit comments

Comments
 (0)