diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index a9b51065a1d99..dd4a3abf8c89d 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -3241,6 +3241,16 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty, if (TLI->has(Func)) return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty); break; + case LibFunc_fdim: + case LibFunc_fdimf: + case LibFunc_fdiml: + APFloat Difference = Op1V; + Difference.subtract(Op2V, RoundingMode::NearestTiesToEven); + + APFloat MaxVal = + maximum(Difference, APFloat::getZero(Ty->getFltSemantics())); + return ConstantFP::get(Ty->getContext(), MaxVal); + break; } return nullptr; diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index c3537f544c432..55cd08b3de855 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -3201,18 +3201,8 @@ Value *LibCallSimplifier::optimizeFdim(CallInst *CI, IRBuilderBase &B) { if (isa(CI->getArgOperand(1))) return CI->getArgOperand(1); - const APFloat *X, *Y; - // Check if both values are constants - if (!match(CI->getArgOperand(0), m_APFloat(X)) || - !match(CI->getArgOperand(1), m_APFloat(Y))) - return nullptr; - - APFloat Difference = *X; - Difference.subtract(*Y, RoundingMode::NearestTiesToEven); - - APFloat MaxVal = - maximum(Difference, APFloat::getZero(CI->getType()->getFltSemantics())); - return ConstantFP::get(CI->getType(), MaxVal); + // Constant folding will be handled by ConstantFoldLibCall2 + return nullptr; } //===----------------------------------------------------------------------===//