diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index aaab600bfc6..0ddca5a0983 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -2305,6 +2305,25 @@ static Constant *ConstantFoldScalarCall2(StringRef Name, const CallBase *Call) { assert(Operands.size() == 2 && "Wrong number of operands."); + if (Ty->isFloatingPointTy()) { + // TODO: We should have undef handling for all of the FP intrinsics that + // are attempted to be folded in this function. + bool IsOp0Undef = isa(Operands[0]); + bool IsOp1Undef = isa(Operands[1]); + switch (IntrinsicID) { + case Intrinsic::maxnum: + case Intrinsic::minnum: + case Intrinsic::maximum: + case Intrinsic::minimum: + // If one argument is undef, return the other argument. + if (IsOp0Undef) + return Operands[1]; + if (IsOp1Undef) + return Operands[0]; + break; + } + } + if (auto *Op1 = dyn_cast(Operands[0])) { if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy()) return nullptr; diff --git a/test/Transforms/InstSimplify/ConstProp/fp-undef.ll b/test/Transforms/InstSimplify/ConstProp/fp-undef.ll index b77337a63a3..fd139f0b880 100644 --- a/test/Transforms/InstSimplify/ConstProp/fp-undef.ll +++ b/test/Transforms/InstSimplify/ConstProp/fp-undef.ll @@ -540,7 +540,7 @@ define <2 x double> @frem_undef_op0_constant_vec(<2 x double> %x) { 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> +; CHECK-NEXT: ret <2 x double> ; %r = call <2 x double> @llvm.maximum.v2f64(<2 x double> , <2 x double> undef) ret <2 x double> %r @@ -556,7 +556,7 @@ define <2 x double> @maximum_nan_op1_vec_partial_undef_op0_undef(<2 x double> %x define <2 x double> @minimum_nan_op0_vec_partial_undef_op1_undef(<2 x double> %x) { ; CHECK-LABEL: @minimum_nan_op0_vec_partial_undef_op1_undef( -; CHECK-NEXT: ret <2 x double> +; CHECK-NEXT: ret <2 x double> ; %r = call <2 x double> @llvm.minimum.v2f64(<2 x double> , <2 x double> undef) ret <2 x double> %r @@ -572,7 +572,7 @@ define <2 x double> @minimum_nan_op1_vec_partial_undef_op0_undef(<2 x double> %x define <2 x double> @maxnum_nan_op0_vec_partial_undef_op1_undef(<2 x double> %x) { ; CHECK-LABEL: @maxnum_nan_op0_vec_partial_undef_op1_undef( -; CHECK-NEXT: ret <2 x double> undef +; CHECK-NEXT: ret <2 x double> ; %r = call <2 x double> @llvm.maxnum.v2f64(<2 x double> , <2 x double> undef) ret <2 x double> %r @@ -588,7 +588,7 @@ define <2 x double> @maxnum_nan_op1_vec_partial_undef_op0_undef(<2 x double> %x) define <2 x double> @minnum_nan_op0_vec_partial_undef_op1_undef(<2 x double> %x) { ; CHECK-LABEL: @minnum_nan_op0_vec_partial_undef_op1_undef( -; CHECK-NEXT: ret <2 x double> undef +; CHECK-NEXT: ret <2 x double> ; %r = call <2 x double> @llvm.minnum.v2f64(<2 x double> , <2 x double> undef) ret <2 x double> %r