diff options
author | Craig Topper <craig.topper@intel.com> | 2019-05-20 16:27:09 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2019-05-20 16:27:09 +0000 |
commit | af7a188453b0412de2149d9cc273fb3455774a2e (patch) | |
tree | 178b305dfe9a6eb800047f0e6752fdc102039846 /clang/lib/CodeGen | |
parent | 203bfdd0f0d7fce8dd448140dbf6938c1ff068d5 (diff) | |
download | bcm5719-llvm-af7a188453b0412de2149d9cc273fb3455774a2e.tar.gz bcm5719-llvm-af7a188453b0412de2149d9cc273fb3455774a2e.zip |
[Intrinsics] Merge lround.i32 and lround.i64 into a single intrinsic with overloaded result type. Make result type for llvm.llround overloaded instead of fixing to i64
We shouldn't really make assumptions about possible sizes for long and long long. And longer term we should probably support vectorizing these intrinsics. By making the result types not fixed we can support vectors as well.
Differential Revision: https://reviews.llvm.org/D62026
llvm-svn: 361169
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 43963576dac..6a183129073 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -391,6 +391,18 @@ static Value *emitFPIntBuiltin(CodeGenFunction &CGF, return CGF.Builder.CreateCall(F, {Src0, Src1}); } +// Emit an intrinsic that has overloaded integer result and fp operand. +static Value *emitFPToIntRoundBuiltin(CodeGenFunction &CGF, + const CallExpr *E, + unsigned IntrinsicID) { + llvm::Type *ResultType = CGF.ConvertType(E->getType()); + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + + Function *F = CGF.CGM.getIntrinsic(IntrinsicID, + {ResultType, Src0->getType()}); + return CGF.Builder.CreateCall(F, Src0); +} + /// EmitFAbs - Emit a call to @llvm.fabs(). static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) { Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType()); @@ -1726,13 +1738,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BIlroundl: case Builtin::BI__builtin_lround: case Builtin::BI__builtin_lroundf: - case Builtin::BI__builtin_lroundl: { - llvm::Type *ResultType = ConvertType(E->getType()); - int Width = ResultType->getPrimitiveSizeInBits(); - return RValue::get(emitUnaryBuiltin(*this, E, - Width == 32 ? Intrinsic::lround_i32 - : Intrinsic::lround_i64)); - } + case Builtin::BI__builtin_lroundl: + return RValue::get(emitFPToIntRoundBuiltin(*this, E, Intrinsic::lround)); case Builtin::BIllround: case Builtin::BIllroundf: @@ -1740,7 +1747,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_llround: case Builtin::BI__builtin_llroundf: case Builtin::BI__builtin_llroundl: - return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::llround)); + return RValue::get(emitFPToIntRoundBuiltin(*this, E, Intrinsic::llround)); default: break; |