Skip to content

Commit c52dbdb

Browse files
committed
[InstCombine] add tests for min/max with negated operand; NFC
1 parent 02ef996 commit c52dbdb

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

llvm/test/Transforms/InstCombine/minmax-intrinsics.ll

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare i8 @llvm.smax.i8(i8, i8)
88
declare <3 x i8> @llvm.umin.v3i8(<3 x i8>, <3 x i8>)
99
declare <3 x i8> @llvm.umax.v3i8(<3 x i8>, <3 x i8>)
1010
declare <3 x i8> @llvm.smin.v3i8(<3 x i8>, <3 x i8>)
11+
declare <3 x i8> @llvm.smax.v3i8(<3 x i8>, <3 x i8>)
1112
declare void @use(i8)
1213

1314
define i8 @umin_known_bits(i8 %x, i8 %y) {
@@ -606,3 +607,90 @@ define i8 @not_umin_of_not_constant_op(i8 %x) {
606607
%notm = xor i8 %m, -1
607608
ret i8 %notm
608609
}
610+
611+
define i8 @smax_negation(i8 %x, i8 %y) {
612+
; CHECK-LABEL: @smax_negation(
613+
; CHECK-NEXT: [[S1:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
614+
; CHECK-NEXT: [[S2:%.*]] = sub i8 [[Y]], [[X]]
615+
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[S1]], i8 [[S2]])
616+
; CHECK-NEXT: ret i8 [[R]]
617+
;
618+
%s1 = sub i8 %x, %y
619+
%s2 = sub i8 %y, %x
620+
%r = call i8 @llvm.smax.i8(i8 %s1, i8 %s2)
621+
ret i8 %r
622+
}
623+
624+
define i8 @smax_negation_nsw(i8 %x, i8 %y) {
625+
; CHECK-LABEL: @smax_negation_nsw(
626+
; CHECK-NEXT: [[S1:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]
627+
; CHECK-NEXT: [[S2:%.*]] = sub nsw i8 [[Y]], [[X]]
628+
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[S1]], i8 [[S2]])
629+
; CHECK-NEXT: ret i8 [[R]]
630+
;
631+
%s1 = sub nsw i8 %x, %y
632+
%s2 = sub nsw i8 %y, %x
633+
%r = call i8 @llvm.smax.i8(i8 %s1, i8 %s2)
634+
ret i8 %r
635+
}
636+
637+
define i8 @smax_negation_not_nsw(i8 %x, i8 %y) {
638+
; CHECK-LABEL: @smax_negation_not_nsw(
639+
; CHECK-NEXT: [[S1:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]
640+
; CHECK-NEXT: [[S2:%.*]] = sub nuw i8 [[Y]], [[X]]
641+
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[S1]], i8 [[S2]])
642+
; CHECK-NEXT: ret i8 [[R]]
643+
;
644+
%s1 = sub nsw i8 %x, %y
645+
%s2 = sub nuw i8 %y, %x
646+
%r = call i8 @llvm.smax.i8(i8 %s1, i8 %s2)
647+
ret i8 %r
648+
}
649+
650+
define <3 x i8> @smax_negation_vec(<3 x i8> %x) {
651+
; CHECK-LABEL: @smax_negation_vec(
652+
; CHECK-NEXT: [[S:%.*]] = sub <3 x i8> <i8 0, i8 undef, i8 0>, [[X:%.*]]
653+
; CHECK-NEXT: [[R:%.*]] = call <3 x i8> @llvm.smax.v3i8(<3 x i8> [[X]], <3 x i8> [[S]])
654+
; CHECK-NEXT: ret <3 x i8> [[R]]
655+
;
656+
%s = sub <3 x i8> <i8 0, i8 undef, i8 0>, %x
657+
%r = call <3 x i8> @llvm.smax.v3i8(<3 x i8> %x, <3 x i8> %s)
658+
ret <3 x i8> %r
659+
}
660+
661+
define i8 @smin_negation(i8 %x, i8 %y) {
662+
; CHECK-LABEL: @smin_negation(
663+
; CHECK-NEXT: [[S1:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
664+
; CHECK-NEXT: [[S2:%.*]] = sub i8 [[Y]], [[X]]
665+
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smin.i8(i8 [[S1]], i8 [[S2]])
666+
; CHECK-NEXT: ret i8 [[R]]
667+
;
668+
%s1 = sub i8 %x, %y
669+
%s2 = sub i8 %y, %x
670+
%r = call i8 @llvm.smin.i8(i8 %s1, i8 %s2)
671+
ret i8 %r
672+
}
673+
674+
define i8 @umax_negation(i8 %x, i8 %y) {
675+
; CHECK-LABEL: @umax_negation(
676+
; CHECK-NEXT: [[S1:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]
677+
; CHECK-NEXT: [[S2:%.*]] = sub nsw i8 [[Y]], [[X]]
678+
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umax.i8(i8 [[S1]], i8 [[S2]])
679+
; CHECK-NEXT: ret i8 [[R]]
680+
;
681+
%s1 = sub nsw i8 %x, %y
682+
%s2 = sub nsw i8 %y, %x
683+
%r = call i8 @llvm.umax.i8(i8 %s1, i8 %s2)
684+
ret i8 %r
685+
}
686+
687+
define i8 @umin_negation(i8 %x) {
688+
; CHECK-LABEL: @umin_negation(
689+
; CHECK-NEXT: [[S:%.*]] = sub nsw i8 0, [[X:%.*]]
690+
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umin.i8(i8 [[S]], i8 [[X]])
691+
; CHECK-NEXT: ret i8 [[R]]
692+
;
693+
%s = sub nsw i8 0, %x
694+
%r = call i8 @llvm.umin.i8(i8 %s, i8 %x)
695+
ret i8 %r
696+
}

0 commit comments

Comments
 (0)