Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 2 additions & 12 deletions llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3201,18 +3201,8 @@ Value *LibCallSimplifier::optimizeFdim(CallInst *CI, IRBuilderBase &B) {
if (isa<PoisonValue>(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;
}

//===----------------------------------------------------------------------===//
Expand Down