[llvm-commits] [llvm] r114893 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp test/Transforms/InstCombine/fold-calls.ll

Jakob Stoklund Olesen stoklund at 2pi.dk
Mon Sep 27 14:29:20 PDT 2010


Author: stoklund
Date: Mon Sep 27 16:29:20 2010
New Revision: 114893

URL: http://llvm.org/viewvc/llvm-project?rev=114893&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/test/Transforms/InstCombine/fold-calls.ll

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=114893&r1=114892&r2=114893&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Sep 27 16:29:20 2010
@@ -1094,6 +1094,13 @@
 
       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)) ==

Modified: llvm/trunk/test/Transforms/InstCombine/fold-calls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fold-calls.ll?rev=114893&r1=114892&r2=114893&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fold-calls.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fold-calls.ll Mon Sep 27 16:29:20 2010
@@ -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)





More information about the llvm-commits mailing list