implement codegen support for __builtin_isfinite, part of PR6083

llvm-svn: 103168
This commit is contained in:
Chris Lattner 2010-05-06 06:04:13 +00:00
parent 68784efaf6
commit dbff4bf5f4
2 changed files with 21 additions and 2 deletions

View 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!

View 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
}