[cfe-commits] r103168 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtins.c
Chris Lattner
sabre at nondot.org
Wed May 5 23:04:13 PDT 2010
Author: lattner
Date: Thu May 6 01:04:13 2010
New Revision: 103168
URL: http://llvm.org/viewvc/llvm-project?rev=103168&view=rev
Log:
implement codegen support for __builtin_isfinite, part of PR6083
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins.c
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=103168&r1=103167&r2=103168&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu May 6 01:04:13 2010
@@ -362,6 +362,19 @@
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!
Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=103168&r1=103167&r2=103168&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Thu May 6 01:04:13 2010
@@ -165,8 +165,8 @@
// 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 @@
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
}
More information about the cfe-commits
mailing list