Don't try to constant fold libm functions with non-finite arguments.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Mon, 27 Sep 2010 21:29:20 +0000 (21:29 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Mon, 27 Sep 2010 21:29:20 +0000 (21:29 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114893 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantFolding.cpp
test/Transforms/InstCombine/fold-calls.ll

index 96656a3c73f7175bfe3d8e7d994ab4467b20878d..d3596d1c86d2f126c5dce9d615ae0632d270a428 100644 (file)
@@ -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)) ==
index fbd09affcb562b248803964dab21403124453757..504f874beaebf134e414bba2f5f8821350c9b1d6 100644 (file)
@@ -1,10 +1,5 @@
 ; RUN: opt -instcombine -S < %s | FileCheck %s
 
-; This test is inexplicably still failing, which suggests a bug in the host
-; libm. It appears that sin(inf) returns NaN without setting a floating point
-; exception.
-; XFAIL: arm-pc-linux-gnu
-
 ; This shouldn't fold, because sin(inf) is invalid.
 ; CHECK: @foo
 ; CHECK:   %t = call double @sin(double 0x7FF0000000000000)