diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-05-19 11:24:26 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-05-19 11:24:26 +0000 |
commit | 6349ce94d1b4fa560bf060c5ca5ad5728ce4fad9 (patch) | |
tree | dc449af225bb12ee86f20c93ee0be9dbf476abbd | |
parent | c3f984fa13364520f4a2c447d1d213db77db3309 (diff) |
Implement codegen for __builtin_isnormal.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104118 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGBuiltin.cpp | 24 | ||||
-rw-r--r-- | test/CodeGen/builtins.c | 8 |
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 4bd1b5d6ec..dd505c2ae8 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -364,11 +364,25 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, // TODO: BI__builtin_isinf_sign // isinf_sign(x) -> isinf(x) ? (signbit(x) ? -1 : 1) : 0 - // TODO: BI__builtin_isnormal - // isnormal(x) -> x != x && fabs(x) < infinity && fabsf(x) >= float_min - // where floatmin is the minimum value for the fp type. Not sure if this is - // APFloat::getSmallest or getSmallestNormalized. - + + case Builtin::BI__builtin_isnormal: { + // isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min + Value *V = EmitScalarExpr(E->getArg(0)); + Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); + + Value *Abs = EmitFAbs(*this, V, E->getArg(0)->getType()); + Value *IsLessThanInf = + Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); + APFloat Smallest = APFloat::getSmallestNormalized( + getContext().getFloatTypeSemantics(E->getArg(0)->getType())); + Value *IsNormal = + Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest), + "isnormal"); + V = Builder.CreateAnd(Eq, IsLessThanInf, "and"); + V = Builder.CreateAnd(V, IsNormal, "and"); + return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); + } + case Builtin::BI__builtin_isfinite: { // isfinite(x) --> x == x && fabs(x) != infinity; } Value *V = EmitScalarExpr(E->getArg(0)); diff --git a/test/CodeGen/builtins.c b/test/CodeGen/builtins.c index b6a4a68ea4..8b6125806e 100644 --- a/test/CodeGen/builtins.c +++ b/test/CodeGen/builtins.c @@ -185,5 +185,13 @@ void test_float_builtins(float F, double D, long double LD) { // CHECK: call float @fabsf // CHECK: fcmp une float {{.*}}, 0x7FF0000000000000 // CHECK: and i1 + + res = __builtin_isnormal(F); + // CHECK: fcmp oeq float + // CHECK: call float @fabsf + // CHECK: fcmp ult float {{.*}}, 0x7FF0000000000000 + // CHECK: fcmp uge float {{.*}}, 0x3810000000000000 + // CHECK: and i1 + // CHECK: and i1 } |