forked from OSchip/llvm-project
implement codegen support for __builtin_isfinite, part of PR6083
llvm-svn: 103168
This commit is contained in:
parent
68784efaf6
commit
dbff4bf5f4
|
@ -362,6 +362,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
||||||
return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()), "tmp"));
|
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::BIalloca:
|
||||||
case Builtin::BI__builtin_alloca: {
|
case Builtin::BI__builtin_alloca: {
|
||||||
// FIXME: LLVM IR Should allow alloca with an i64 size!
|
// FIXME: LLVM IR Should allow alloca with an i64 size!
|
||||||
|
|
|
@ -165,8 +165,8 @@ void bar() {
|
||||||
// CHECK: }
|
// CHECK: }
|
||||||
|
|
||||||
|
|
||||||
// CHECK: define void @test_inff
|
// CHECK: define void @test_float_builtins
|
||||||
void test_inff(float F, double D, long double LD) {
|
void test_float_builtins(float F, double D, long double LD) {
|
||||||
volatile int res;
|
volatile int res;
|
||||||
res = __builtin_isinf(F);
|
res = __builtin_isinf(F);
|
||||||
// CHECK: call float @fabsf(float
|
// CHECK: call float @fabsf(float
|
||||||
|
@ -179,5 +179,11 @@ void test_inff(float F, double D, long double LD) {
|
||||||
res = __builtin_isinf(LD);
|
res = __builtin_isinf(LD);
|
||||||
// CHECK: call x86_fp80 @fabsl(x86_fp80
|
// CHECK: call x86_fp80 @fabsl(x86_fp80
|
||||||
// CHECK: fcmp oeq x86_fp80 {{.*}}, 0xK7FFF8000000000000000
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue