Skip to content

Commit

Permalink
[InstSimplify] allow partial undef constants for vector min/max folds
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Jul 29, 2020
1 parent 3c20ede commit 3e8534f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 2 additions & 3 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Expand Up @@ -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;
}
Expand Down
12 changes: 4 additions & 8 deletions llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
Expand Up @@ -218,35 +218,31 @@ 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
}

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
}

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
}

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
Expand Down

0 comments on commit 3e8534f

Please sign in to comment.