]> granicus.if.org Git - clang/commitdiff
implement codegen support for __builtin_isfinite, part of PR6083
authorChris Lattner <sabre@nondot.org>
Thu, 6 May 2010 06:04:13 +0000 (06:04 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 6 May 2010 06:04:13 +0000 (06:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103168 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtins.c

index 651539f0196ea3260e465361c7ee04d004573c6b..90fcb698285e960dc4a1e94443defbf6193fc243 100644 (file)
@@ -362,6 +362,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
     return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()), "tmp"));
   }
    
+  case Builtin::BI__builtin_isfinite: {
+    // isfinite(x) --> x == x && fabs(x) != infinity; }
+    Value *V = EmitScalarExpr(E->getArg(0));
+    Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq");
+    
+    Value *Abs = EmitFAbs(*this, V, E->getArg(0)->getType());
+    Value *IsNotInf =
+      Builder.CreateFCmpUNE(Abs, ConstantFP::getInfinity(V->getType()),"isinf");
+    
+    V = Builder.CreateAnd(Eq, IsNotInf, "and");
+    return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType())));
+  }
+      
   case Builtin::BIalloca:
   case Builtin::BI__builtin_alloca: {
     // FIXME: LLVM IR Should allow alloca with an i64 size!
index e604fbe318933d22990ea24dc9d8c6b1135cf37d..b6a4a68ea4fc9a8671993f7823e59371ed645eb4 100644 (file)
@@ -165,8 +165,8 @@ void bar() {
 // CHECK: }
 
 
-// CHECK: define void @test_inff
-void test_inff(float F, double D, long double LD) {
+// CHECK: define void @test_float_builtins
+void test_float_builtins(float F, double D, long double LD) {
   volatile int res;
   res = __builtin_isinf(F);
   // CHECK:  call float @fabsf(float
@@ -179,5 +179,11 @@ void test_inff(float F, double D, long double LD) {
   res = __builtin_isinf(LD);
   // CHECK:  call x86_fp80 @fabsl(x86_fp80
   // CHECK:  fcmp oeq x86_fp80 {{.*}}, 0xK7FFF8000000000000000
+  
+  res = __builtin_isfinite(F);
+  // CHECK: fcmp oeq float 
+  // CHECK: call float @fabsf
+  // CHECK: fcmp une float {{.*}}, 0x7FF0000000000000
+  // CHECK: and i1 
 }