Author: azanella Date: Tue May 28 14:16:04 2019 New Revision: 361878 URL: http://llvm.org/viewvc/llvm-project?rev=361878&view=rev Log: [clang] Handle lrint/llrint builtins
As for other floating-point rounding builtins that can be optimized when build with -fno-math-errno, this patch adds support for lrint and llrint. It currently only optimize for AArch64 backend. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D62019 Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp cfe/trunk/test/CodeGen/builtins.c cfe/trunk/test/CodeGen/math-builtins.c cfe/trunk/test/CodeGen/math-libcalls.c Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=361878&r1=361877&r2=361878&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original) +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue May 28 14:16:04 2019 @@ -1741,6 +1741,22 @@ RValue CodeGenFunction::EmitBuiltinExpr( case Builtin::BI__builtin_llroundl: return RValue::get(emitFPToIntRoundBuiltin(*this, E, Intrinsic::llround)); + case Builtin::BIlrint: + case Builtin::BIlrintf: + case Builtin::BIlrintl: + case Builtin::BI__builtin_lrint: + case Builtin::BI__builtin_lrintf: + case Builtin::BI__builtin_lrintl: + return RValue::get(emitFPToIntRoundBuiltin(*this, E, Intrinsic::lrint)); + + case Builtin::BIllrint: + case Builtin::BIllrintf: + case Builtin::BIllrintl: + case Builtin::BI__builtin_llrint: + case Builtin::BI__builtin_llrintf: + case Builtin::BI__builtin_llrintl: + return RValue::get(emitFPToIntRoundBuiltin(*this, E, Intrinsic::llrint)); + default: break; } Modified: cfe/trunk/test/CodeGen/builtins.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=361878&r1=361877&r2=361878&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/builtins.c (original) +++ cfe/trunk/test/CodeGen/builtins.c Tue May 28 14:16:04 2019 @@ -390,6 +390,15 @@ void test_float_builtin_ops(float F, dou resli = __builtin_lroundl (LD); // CHECK: call i64 @llvm.lround.i64.f80 + + resli = __builtin_lrintf (F); + // CHECK: call i64 @llvm.lrint.i64.f32 + + resli = __builtin_lrint (D); + // CHECK: call i64 @llvm.lrint.i64.f64 + + resli = __builtin_lrintl (LD); + // CHECK: call i64 @llvm.lrint.i64.f80 } // __builtin_longjmp isn't supported on all platforms, so only test it on X86. Modified: cfe/trunk/test/CodeGen/math-builtins.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/math-builtins.c?rev=361878&r1=361877&r2=361878&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/math-builtins.c (original) +++ cfe/trunk/test/CodeGen/math-builtins.c Tue May 28 14:16:04 2019 @@ -353,9 +353,9 @@ void foo(double *d, float f, float *fp, __builtin_llrint(f); __builtin_llrintf(f); __builtin_llrintl(f); -// NO__ERRNO: declare i64 @llrint(double) [[READNONE]] -// NO__ERRNO: declare i64 @llrintf(float) [[READNONE]] -// NO__ERRNO: declare i64 @llrintl(x86_fp80) [[READNONE]] +// NO__ERRNO: declare i64 @llvm.llrint.i64.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.llrint.i64.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.llrint.i64.f80(x86_fp80) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare i64 @llrint(double) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @llrintf(float) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @llrintl(x86_fp80) [[NOT_READNONE]] @@ -416,9 +416,9 @@ void foo(double *d, float f, float *fp, __builtin_lrint(f); __builtin_lrintf(f); __builtin_lrintl(f); -// NO__ERRNO: declare i64 @lrint(double) [[READNONE]] -// NO__ERRNO: declare i64 @lrintf(float) [[READNONE]] -// NO__ERRNO: declare i64 @lrintl(x86_fp80) [[READNONE]] +// NO__ERRNO: declare i64 @llvm.lrint.i64.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.lrint.i64.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.lrint.i64.f80(x86_fp80) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare i64 @lrint(double) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @lrintf(float) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @lrintl(x86_fp80) [[NOT_READNONE]] Modified: cfe/trunk/test/CodeGen/math-libcalls.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/math-libcalls.c?rev=361878&r1=361877&r2=361878&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/math-libcalls.c (original) +++ cfe/trunk/test/CodeGen/math-libcalls.c Tue May 28 14:16:04 2019 @@ -308,9 +308,9 @@ void foo(double *d, float f, float *fp, llrint(f); llrintf(f); llrintl(f); -// NO__ERRNO: declare i64 @llrint(double) [[READNONE]] -// NO__ERRNO: declare i64 @llrintf(float) [[READNONE]] -// NO__ERRNO: declare i64 @llrintl(x86_fp80) [[READNONE]] +// NO__ERRNO: declare i64 @llvm.llrint.i64.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.llrint.i64.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.llrint.i64.f80(x86_fp80) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare i64 @llrint(double) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @llrintf(float) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @llrintl(x86_fp80) [[NOT_READNONE]] @@ -371,9 +371,9 @@ void foo(double *d, float f, float *fp, lrint(f); lrintf(f); lrintl(f); -// NO__ERRNO: declare i64 @lrint(double) [[READNONE]] -// NO__ERRNO: declare i64 @lrintf(float) [[READNONE]] -// NO__ERRNO: declare i64 @lrintl(x86_fp80) [[READNONE]] +// NO__ERRNO: declare i64 @llvm.lrint.i64.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.lrint.i64.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare i64 @llvm.lrint.i64.f80(x86_fp80) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare i64 @lrint(double) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @lrintf(float) [[NOT_READNONE]] // HAS_ERRNO: declare i64 @lrintl(x86_fp80) [[NOT_READNONE]] _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits