[llvm] 3e8534f - [InstSimplify] allow partial undef constants for vector min/max folds
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 08:53:54 PDT 2020
Author: Sanjay Patel
Date: 2020-07-29T11:53:41-04:00
New Revision: 3e8534fbc62c87bd72c4145598a61eb805c82393
URL: https://github.com/llvm/llvm-project/commit/3e8534fbc62c87bd72c4145598a61eb805c82393
DIFF: https://github.com/llvm/llvm-project/commit/3e8534fbc62c87bd72c4145598a61eb805c82393.diff
LOG: [InstSimplify] allow partial undef constants for vector min/max folds
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 0f45182788e4..af487f99e8e2 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5266,16 +5266,15 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
if (isa<Constant>(Op0))
std::swap(Op0, Op1);
- // TODO: Allow partial undef vector constants.
const APInt *C;
- if (!match(Op1, m_APInt(C)))
+ if (!match(Op1, m_APIntAllowUndef(C)))
break;
if ((IID == Intrinsic::smax && C->isMaxSignedValue()) ||
(IID == Intrinsic::smin && C->isMinSignedValue()) ||
(IID == Intrinsic::umax && C->isMaxValue()) ||
(IID == Intrinsic::umin && C->isMinValue()))
- return Op1;
+ return ConstantInt::get(ReturnType, *C);
break;
}
diff --git a/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll b/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
index fee630f9f230..312056d745a9 100644
--- a/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
+++ b/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
@@ -218,8 +218,7 @@ define <2 x i8> @umin_maxval_commute(<2 x i8> %x) {
define <2 x i8> @smax_maxval_partial_undef(<2 x i8> %x) {
; CHECK-LABEL: @smax_maxval_partial_undef(
-; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> <i8 undef, i8 127>, <2 x i8> [[X:%.*]])
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: ret <2 x i8> <i8 127, i8 127>
;
%r = call <2 x i8> @llvm.smax.v2i8(<2 x i8> <i8 undef, i8 127>, <2 x i8> %x)
ret <2 x i8> %r
@@ -227,8 +226,7 @@ define <2 x i8> @smax_maxval_partial_undef(<2 x i8> %x) {
define <2 x i8> @smin_minval_partial_undef(<2 x i8> %x) {
; CHECK-LABEL: @smin_minval_partial_undef(
-; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.smin.v2i8(<2 x i8> [[X:%.*]], <2 x i8> <i8 -128, i8 undef>)
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: ret <2 x i8> <i8 -128, i8 -128>
;
%r = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %x, <2 x i8> <i8 -128, i8 undef>)
ret <2 x i8> %r
@@ -236,8 +234,7 @@ define <2 x i8> @smin_minval_partial_undef(<2 x i8> %x) {
define <2 x i8> @umax_maxval_partial_undef(<2 x i8> %x) {
; CHECK-LABEL: @umax_maxval_partial_undef(
-; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.umax.v2i8(<2 x i8> <i8 -1, i8 undef>, <2 x i8> [[X:%.*]])
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
;
%r = call <2 x i8> @llvm.umax.v2i8(<2 x i8> <i8 255, i8 undef>, <2 x i8> %x)
ret <2 x i8> %r
@@ -245,8 +242,7 @@ define <2 x i8> @umax_maxval_partial_undef(<2 x i8> %x) {
define <2 x i8> @umin_minval_partial_undef(<2 x i8> %x) {
; CHECK-LABEL: @umin_minval_partial_undef(
-; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.umin.v2i8(<2 x i8> [[X:%.*]], <2 x i8> <i8 undef, i8 0>)
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: ret <2 x i8> zeroinitializer
;
%r = call <2 x i8> @llvm.umin.v2i8(<2 x i8> %x, <2 x i8> <i8 undef, i8 0>)
ret <2 x i8> %r
More information about the llvm-commits
mailing list