Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,8 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case Intrinsic::maxnum:
case Intrinsic::minimum:
case Intrinsic::maximum:
case Intrinsic::minimumnum:
case Intrinsic::maximumnum:
case Intrinsic::log:
case Intrinsic::log2:
case Intrinsic::log10:
Expand Down Expand Up @@ -2930,6 +2932,8 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
case Intrinsic::minnum:
case Intrinsic::maximum:
case Intrinsic::minimum:
case Intrinsic::maximumnum:
case Intrinsic::minimumnum:
case Intrinsic::nvvm_fmax_d:
case Intrinsic::nvvm_fmin_d:
// If one argument is undef, return the other argument.
Expand Down Expand Up @@ -3030,6 +3034,10 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
return ConstantFP::get(Ty->getContext(), minimum(Op1V, Op2V));
case Intrinsic::maximum:
return ConstantFP::get(Ty->getContext(), maximum(Op1V, Op2V));
case Intrinsic::minimumnum:
return ConstantFP::get(Ty->getContext(), minimumnum(Op1V, Op2V));
case Intrinsic::maximumnum:
return ConstantFP::get(Ty->getContext(), maximumnum(Op1V, Op2V));

case Intrinsic::nvvm_fmax_d:
case Intrinsic::nvvm_fmax_f:
Expand Down
34 changes: 34 additions & 0 deletions llvm/test/Transforms/InstSimplify/ConstProp/fp-undef.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ declare <2 x double> @llvm.minnum.v2f64(<2 x double>, <2 x double>)
declare <2 x double> @llvm.maxnum.v2f64(<2 x double>, <2 x double>)
declare <2 x double> @llvm.minimum.v2f64(<2 x double>, <2 x double>)
declare <2 x double> @llvm.maximum.v2f64(<2 x double>, <2 x double>)
declare <2 x double> @llvm.minimumnum.v2f64(<2 x double>, <2 x double>)
declare <2 x double> @llvm.maximumnum.v2f64(<2 x double>, <2 x double>)

; Constant folding - undef undef.

Expand Down Expand Up @@ -538,6 +540,38 @@ define <2 x double> @frem_undef_op0_constant_vec(<2 x double> %x) {
ret <2 x double> %r
}

define <2 x double> @maximumnum_nan_op0_vec_partial_undef_op1_undef(<2 x double> %x) {
; CHECK-LABEL: @maximumnum_nan_op0_vec_partial_undef_op1_undef(
; CHECK-NEXT: ret <2 x double> <double 0x7FF8000000000000, double undef>
;
%r = call <2 x double> @llvm.maximumnum.v2f64(<2 x double> <double 0x7ff8000000000000, double undef>, <2 x double> undef)
ret <2 x double> %r
}

define <2 x double> @maximumnum_nan_op1_vec_partial_undef_op0_undef(<2 x double> %x) {
; CHECK-LABEL: @maximumnum_nan_op1_vec_partial_undef_op0_undef(
; CHECK-NEXT: ret <2 x double> <double 0x7FF8000000000000, double undef>
;
%r = call <2 x double> @llvm.maximumnum.v2f64(<2 x double> undef, <2 x double> <double 0x7ff8000000000000, double undef>)
ret <2 x double> %r
}

define <2 x double> @minimumnum_nan_op0_vec_partial_undef_op1_undef(<2 x double> %x) {
; CHECK-LABEL: @minimumnum_nan_op0_vec_partial_undef_op1_undef(
; CHECK-NEXT: ret <2 x double> <double 0x7FF8000000000000, double undef>
;
%r = call <2 x double> @llvm.minimumnum.v2f64(<2 x double> <double 0x7ff8000000000000, double undef>, <2 x double> undef)
ret <2 x double> %r
}

define <2 x double> @minimumnum_nan_op1_vec_partial_undef_op0_undef(<2 x double> %x) {
; CHECK-LABEL: @minimumnum_nan_op1_vec_partial_undef_op0_undef(
; CHECK-NEXT: ret <2 x double> <double 0x7FF8000000000000, double undef>
;
%r = call <2 x double> @llvm.minimumnum.v2f64(<2 x double> undef, <2 x double> <double 0x7ff8000000000000, double undef>)
ret <2 x double> %r
}

define <2 x double> @maximum_nan_op0_vec_partial_undef_op1_undef(<2 x double> %x) {
; CHECK-LABEL: @maximum_nan_op0_vec_partial_undef_op1_undef(
; CHECK-NEXT: ret <2 x double> <double 0x7FF8000000000000, double undef>
Expand Down
Loading
Loading