1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[InstSimplify] fold max (max X, Y), X --> max X, Y

https://alive2.llvm.org/ce/z/VGgG3M
This commit is contained in:
Sanjay Patel 2020-08-02 11:11:05 -04:00
parent 33336c7314
commit a4319ccb7e
2 changed files with 27 additions and 32 deletions

View File

@ -5239,6 +5239,17 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
return ConstantInt::get(ReturnType, APInt::getMinValue(BitWidth));
}
// For 4 commuted variants of each intrinsic:
// max (max X, Y), X --> max X, Y
if (auto *MinMax0 = dyn_cast<IntrinsicInst>(Op0))
if (MinMax0->getIntrinsicID() == IID &&
(MinMax0->getOperand(0) == Op1 || MinMax0->getOperand(1) == Op1))
return MinMax0;
if (auto *MinMax1 = dyn_cast<IntrinsicInst>(Op1))
if (MinMax1->getIntrinsicID() == IID &&
(MinMax1->getOperand(0) == Op0 || MinMax1->getOperand(1) == Op0))
return MinMax1;
const APInt *C;
if (!match(Op1, m_APIntAllowUndef(C)))
break;

View File

@ -271,8 +271,7 @@ define <2 x i8> @umin_maxval_partial_undef(<2 x i8> %x) {
define i8 @umax_umax(i8 %x, i8 %y) {
; CHECK-LABEL: @umax_umax(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[M]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.umax.i8(i8 %x, i8 %y)
%m2 = call i8 @llvm.umax.i8(i8 %x, i8 %m)
@ -282,8 +281,7 @@ define i8 @umax_umax(i8 %x, i8 %y) {
define i8 @umax_umax_commute1(i8 %x, i8 %y) {
; CHECK-LABEL: @umax_umax_commute1(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[M]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.umax.i8(i8 %y, i8 %x)
%m2 = call i8 @llvm.umax.i8(i8 %x, i8 %m)
@ -293,8 +291,7 @@ define i8 @umax_umax_commute1(i8 %x, i8 %y) {
define i8 @umax_umax_commute2(i8 %x, i8 %y) {
; CHECK-LABEL: @umax_umax_commute2(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[M]], i8 [[X]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.umax.i8(i8 %x, i8 %y)
%m2 = call i8 @llvm.umax.i8(i8 %m, i8 %x)
@ -304,8 +301,7 @@ define i8 @umax_umax_commute2(i8 %x, i8 %y) {
define <2 x i8> @umax_umax_commute3(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @umax_umax_commute3(
; CHECK-NEXT: [[M:%.*]] = call <2 x i8> @llvm.umax.v2i8(<2 x i8> [[Y:%.*]], <2 x i8> [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call <2 x i8> @llvm.umax.v2i8(<2 x i8> [[M]], <2 x i8> [[X]])
; CHECK-NEXT: ret <2 x i8> [[M2]]
; CHECK-NEXT: ret <2 x i8> [[M]]
;
%m = call <2 x i8> @llvm.umax.v2i8(<2 x i8> %y, <2 x i8> %x)
%m2 = call <2 x i8> @llvm.umax.v2i8(<2 x i8> %m, <2 x i8> %x)
@ -315,8 +311,7 @@ define <2 x i8> @umax_umax_commute3(<2 x i8> %x, <2 x i8> %y) {
define i8 @umin_umin(i8 %x, i8 %y) {
; CHECK-LABEL: @umin_umin(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 [[M]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.umin.i8(i8 %x, i8 %y)
%m2 = call i8 @llvm.umin.i8(i8 %x, i8 %m)
@ -326,8 +321,7 @@ define i8 @umin_umin(i8 %x, i8 %y) {
define i8 @umin_umin_commute1(i8 %x, i8 %y) {
; CHECK-LABEL: @umin_umin_commute1(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 [[M]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.umin.i8(i8 %y, i8 %x)
%m2 = call i8 @llvm.umin.i8(i8 %x, i8 %m)
@ -337,8 +331,7 @@ define i8 @umin_umin_commute1(i8 %x, i8 %y) {
define <2 x i8> @umin_umin_commute2(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @umin_umin_commute2(
; CHECK-NEXT: [[M:%.*]] = call <2 x i8> @llvm.umin.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call <2 x i8> @llvm.umin.v2i8(<2 x i8> [[M]], <2 x i8> [[X]])
; CHECK-NEXT: ret <2 x i8> [[M2]]
; CHECK-NEXT: ret <2 x i8> [[M]]
;
%m = call <2 x i8> @llvm.umin.v2i8(<2 x i8> %x, <2 x i8> %y)
%m2 = call <2 x i8> @llvm.umin.v2i8(<2 x i8> %m, <2 x i8> %x)
@ -348,8 +341,7 @@ define <2 x i8> @umin_umin_commute2(<2 x i8> %x, <2 x i8> %y) {
define i8 @umin_umin_commute3(i8 %x, i8 %y) {
; CHECK-LABEL: @umin_umin_commute3(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umin.i8(i8 [[M]], i8 [[X]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.umin.i8(i8 %y, i8 %x)
%m2 = call i8 @llvm.umin.i8(i8 %m, i8 %x)
@ -359,8 +351,7 @@ define i8 @umin_umin_commute3(i8 %x, i8 %y) {
define i8 @smax_smax(i8 %x, i8 %y) {
; CHECK-LABEL: @smax_smax(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 [[M]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.smax.i8(i8 %x, i8 %y)
%m2 = call i8 @llvm.smax.i8(i8 %x, i8 %m)
@ -370,8 +361,7 @@ define i8 @smax_smax(i8 %x, i8 %y) {
define <2 x i8> @smax_smax_commute1(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @smax_smax_commute1(
; CHECK-NEXT: [[M:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[Y:%.*]], <2 x i8> [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[X]], <2 x i8> [[M]])
; CHECK-NEXT: ret <2 x i8> [[M2]]
; CHECK-NEXT: ret <2 x i8> [[M]]
;
%m = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %y, <2 x i8> %x)
%m2 = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %x, <2 x i8> %m)
@ -381,8 +371,7 @@ define <2 x i8> @smax_smax_commute1(<2 x i8> %x, <2 x i8> %y) {
define i8 @smax_smax_commute2(i8 %x, i8 %y) {
; CHECK-LABEL: @smax_smax_commute2(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[M]], i8 [[X]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.smax.i8(i8 %x, i8 %y)
%m2 = call i8 @llvm.smax.i8(i8 %m, i8 %x)
@ -392,8 +381,7 @@ define i8 @smax_smax_commute2(i8 %x, i8 %y) {
define i8 @smax_smax_commute3(i8 %x, i8 %y) {
; CHECK-LABEL: @smax_smax_commute3(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[M]], i8 [[X]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.smax.i8(i8 %y, i8 %x)
%m2 = call i8 @llvm.smax.i8(i8 %m, i8 %x)
@ -403,8 +391,7 @@ define i8 @smax_smax_commute3(i8 %x, i8 %y) {
define <2 x i8> @smin_smin(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @smin_smin(
; CHECK-NEXT: [[M:%.*]] = call <2 x i8> @llvm.smin.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call <2 x i8> @llvm.smin.v2i8(<2 x i8> [[X]], <2 x i8> [[M]])
; CHECK-NEXT: ret <2 x i8> [[M2]]
; CHECK-NEXT: ret <2 x i8> [[M]]
;
%m = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %x, <2 x i8> %y)
%m2 = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %x, <2 x i8> %m)
@ -414,8 +401,7 @@ define <2 x i8> @smin_smin(<2 x i8> %x, <2 x i8> %y) {
define i8 @smin_smin_commute1(i8 %x, i8 %y) {
; CHECK-LABEL: @smin_smin_commute1(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 [[M]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.smin.i8(i8 %y, i8 %x)
%m2 = call i8 @llvm.smin.i8(i8 %x, i8 %m)
@ -425,8 +411,7 @@ define i8 @smin_smin_commute1(i8 %x, i8 %y) {
define i8 @smin_smin_commute2(i8 %x, i8 %y) {
; CHECK-LABEL: @smin_smin_commute2(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smin.i8(i8 [[M]], i8 [[X]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.smin.i8(i8 %x, i8 %y)
%m2 = call i8 @llvm.smin.i8(i8 %m, i8 %x)
@ -436,8 +421,7 @@ define i8 @smin_smin_commute2(i8 %x, i8 %y) {
define i8 @smin_smin_commute3(i8 %x, i8 %y) {
; CHECK-LABEL: @smin_smin_commute3(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smin.i8(i8 [[M]], i8 [[X]])
; CHECK-NEXT: ret i8 [[M2]]
; CHECK-NEXT: ret i8 [[M]]
;
%m = call i8 @llvm.smin.i8(i8 %y, i8 %x)
%m2 = call i8 @llvm.smin.i8(i8 %m, i8 %x)