PR6515: Implement __builtin_signbit and friends.

I'm reasonably sure my implementation is correct, but it would be nice if
someone could double-check.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97864 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eli Friedman 2010-03-06 02:17:52 +00:00
Родитель dbf217af72
Коммит ba68b08a05
3 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -240,6 +240,11 @@ BUILTIN(__builtin_isinf_sign, "i.", "nc")
BUILTIN(__builtin_isnan, "i.", "nc") BUILTIN(__builtin_isnan, "i.", "nc")
BUILTIN(__builtin_isnormal, "i.", "nc") BUILTIN(__builtin_isnormal, "i.", "nc")
// FP signbit builtins
BUILTIN(__builtin_signbit, "id", "nc")
BUILTIN(__builtin_signbitf, "if", "nc")
BUILTIN(__builtin_signbitl, "iLd", "nc")
// Builtins for arithmetic. // Builtins for arithmetic.
BUILTIN(__builtin_clz , "iUi" , "nc") BUILTIN(__builtin_clz , "iUi" , "nc")
BUILTIN(__builtin_clzl , "iULi" , "nc") BUILTIN(__builtin_clzl , "iULi" , "nc")

Просмотреть файл

@ -682,6 +682,23 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Value *F = CGM.getIntrinsic(Intrinsic::pow, &ArgType, 1); Value *F = CGM.getIntrinsic(Intrinsic::pow, &ArgType, 1);
return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp"));
} }
case Builtin::BI__builtin_signbit:
case Builtin::BI__builtin_signbitf:
case Builtin::BI__builtin_signbitl: {
LLVMContext &C = CGM.getLLVMContext();
Value *Arg = EmitScalarExpr(E->getArg(0));
const llvm::Type *ArgTy = Arg->getType();
if (ArgTy->isPPC_FP128Ty())
break; // FIXME: I'm not sure what the right implementation is here.
int ArgWidth = ArgTy->getPrimitiveSizeInBits();
const llvm::Type *ArgIntTy = llvm::IntegerType::get(C, ArgWidth);
Value *BCArg = Builder.CreateBitCast(Arg, ArgIntTy);
Value *ZeroCmp = llvm::Constant::getNullValue(ArgIntTy);
Value *Result = Builder.CreateICmpSLT(BCArg, ZeroCmp);
return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType())));
}
} }
// If this is an alias for a libm function (e.g. __builtin_sin) turn it into // If this is an alias for a libm function (e.g. __builtin_sin) turn it into

Просмотреть файл

@ -118,6 +118,7 @@ int main() {
// V(clear_cache, (&N, &N+1)); // V(clear_cache, (&N, &N+1));
V(trap, ()); V(trap, ());
R(extract_return_addr, (&N)); R(extract_return_addr, (&N));
P(signbit, (1.0));
return 0; return 0;
} }