Add __builtin_abs

llvm-svn: 44254
This commit is contained in:
Anders Carlsson 2007-11-20 19:05:17 +00:00
parent 5c3f1541a7
commit 4f8eb127e1
2 changed files with 13 additions and 0 deletions

View File

@ -85,6 +85,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
return RValue::get(llvm::ConstantInt::get(Result));
}
case Builtin::BI__builtin_abs: {
llvm::Value *ArgValue = EmitScalarExpr(E->getArg(0));
llvm::BinaryOperator *NegOp =
Builder.CreateNeg(ArgValue, (ArgValue->getName() + "neg").c_str());
llvm::Value *CmpResult =
Builder.CreateICmpSGE(ArgValue, NegOp->getOperand(0), "abscond");
llvm::Value *Result =
Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs");
return RValue::get(Result);
}
}
return RValue::get(0);

View File

@ -55,6 +55,7 @@
BUILTIN(__builtin_inf , "d" , "ncF")
BUILTIN(__builtin_inff , "f" , "ncF")
BUILTIN(__builtin_infl , "Ld" , "ncF")
BUILTIN(__builtin_abs , "ii" , "ncF")
BUILTIN(__builtin_fabs , "dd" , "ncF")
BUILTIN(__builtin_fabsf, "ff" , "ncF")
BUILTIN(__builtin_fabsl, "LdLd", "ncF")