From 1083573796d2f988537e18cfc71e35f11b02725b Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Mon, 27 Sep 2010 21:29:20 +0000 Subject: Don't try to constant fold libm functions with non-finite arguments. Usually we wouldn't do this anyway because llvm_fenv_testexcept would return an exception, but we have seen some cases where neither errno nor fenv detect an exception on arm-linux. llvm-svn: 114893 --- 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 96656a3c73f..d3596d1c86d 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1094,6 +1094,13 @@ llvm::ConstantFoldCall(Function *F, if (!Ty->isFloatTy() && !Ty->isDoubleTy()) return 0; + + /// 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. + if (Op->getValueAPF().isNaN() || Op->getValueAPF().isInfinity()) + return 0; + /// Currently APFloat versions of these functions do not exist, so we use /// the host native double versions. Float versions are not called /// directly but for all these it is true (float)(f((double)arg)) == -- cgit v1.2.3