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 /lib | |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGBuiltin.cpp | 24 |
1 files changed, 19 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)); |