From b67688a87cfc31f9da2d34b33a0c07632c789bfe Mon Sep 17 00:00:00 2001 From: Karthik Bhat Date: Fri, 7 Mar 2014 04:36:21 +0000 Subject: Allow constant folding of round function whenever feasible llvm-svn: 203198 --- llvm/lib/Analysis/ConstantFolding.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'llvm/lib/Analysis/ConstantFolding.cpp') diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index ff1124a..8ff79d6 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1196,6 +1196,7 @@ bool llvm::canConstantFoldCallTo(const Function *F) { case Intrinsic::fma: case Intrinsic::fmuladd: case Intrinsic::copysign: + case Intrinsic::round: case Intrinsic::sadd_with_overflow: case Intrinsic::uadd_with_overflow: case Intrinsic::ssub_with_overflow: @@ -1345,6 +1346,12 @@ static Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy()) return 0; + if (IntrinsicID == Intrinsic::round) { + APFloat V = Op->getValueAPF(); + V.roundToIntegral(APFloat::rmNearestTiesToAway); + return ConstantFP::get(Ty->getContext(), V); + } + /// We only fold functions with finite arguments. Folding NaN and inf is /// likely to be aborted with an exception anyway, and some host libms /// have known errors raising exceptions. -- cgit v1.1