[clang] a7d6593 - Add missing roundtointegral builtin functions for some FP instructions to be generated from C-written codes
Jun Sha via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 6 22:17:36 PST 2023
Author: Jun Sha (Joshua)
Date: 2023-03-07T14:17:35+08:00
New Revision: a7d6593a0a17a1e7f46a3c9cd5c4aeeb7dfc6e0a
URL: https://github.com/llvm/llvm-project/commit/a7d6593a0a17a1e7f46a3c9cd5c4aeeb7dfc6e0a
DIFF: https://github.com/llvm/llvm-project/commit/a7d6593a0a17a1e7f46a3c9cd5c4aeeb7dfc6e0a.diff
LOG: Add missing roundtointegral builtin functions for some FP instructions to be generated from C-written codes
To generate FROUND instructions in https://reviews.llvm.org/D143982, we need to use llvm intrinsics in IR files. Now I add some corresponding builtin functions to make sure these roundtointegral instructions can be generated from C codes.
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D144935
Added:
Modified:
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def
index 6db599a3de116..478eb59bb7712 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -350,6 +350,11 @@ BUILTIN(__builtin_roundf, "ff" , "Fnc")
BUILTIN(__builtin_roundf16, "hh" , "Fnc")
BUILTIN(__builtin_roundl, "LdLd" , "Fnc")
BUILTIN(__builtin_roundf128, "LLdLLd" , "Fnc")
+BUILTIN(__builtin_roundeven, "dd" , "Fnc")
+BUILTIN(__builtin_roundevenf, "ff" , "Fnc")
+BUILTIN(__builtin_roundevenf16, "hh" , "Fnc")
+BUILTIN(__builtin_roundevenl, "LdLd" , "Fnc")
+BUILTIN(__builtin_roundevenf128, "LLdLLd" , "Fnc")
BUILTIN(__builtin_scalbln , "ddLi", "Fne")
BUILTIN(__builtin_scalblnf, "ffLi", "Fne")
BUILTIN(__builtin_scalblnl, "LdLdLi", "Fne")
@@ -1420,6 +1425,10 @@ LIBBUILTIN(round, "dd", "fnc", MATH_H, ALL_LANGUAGES)
LIBBUILTIN(roundf, "ff", "fnc", MATH_H, ALL_LANGUAGES)
LIBBUILTIN(roundl, "LdLd", "fnc", MATH_H, ALL_LANGUAGES)
+LIBBUILTIN(roundeven, "dd", "fnc", MATH_H, ALL_LANGUAGES)
+LIBBUILTIN(roundevenf, "ff", "fnc", MATH_H, ALL_LANGUAGES)
+LIBBUILTIN(roundevenl, "LdLd", "fnc", MATH_H, ALL_LANGUAGES)
+
LIBBUILTIN(scalbln, "ddLi", "fne", MATH_H, ALL_LANGUAGES)
LIBBUILTIN(scalblnf, "ffLi", "fne", MATH_H, ALL_LANGUAGES)
LIBBUILTIN(scalblnl, "LdLdLi", "fne", MATH_H, ALL_LANGUAGES)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 07a39bca9d7a2..cea4727422c0b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2444,6 +2444,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Intrinsic::round,
Intrinsic::experimental_constrained_round));
+ case Builtin::BIroundeven:
+ case Builtin::BIroundevenf:
+ case Builtin::BIroundevenl:
+ case Builtin::BI__builtin_roundeven:
+ case Builtin::BI__builtin_roundevenf:
+ case Builtin::BI__builtin_roundevenf16:
+ case Builtin::BI__builtin_roundevenl:
+ case Builtin::BI__builtin_roundevenf128:
+ return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E,
+ Intrinsic::roundeven,
+ Intrinsic::experimental_constrained_roundeven));
+
case Builtin::BIsin:
case Builtin::BIsinf:
case Builtin::BIsinl:
diff --git a/clang/test/CodeGen/builtins.c b/clang/test/CodeGen/builtins.c
index 21e14cc9c08c0..1281c5e13ae3e 100644
--- a/clang/test/CodeGen/builtins.c
+++ b/clang/test/CodeGen/builtins.c
@@ -411,6 +411,15 @@ void test_float_builtin_ops(float F, double D, long double LD) {
resld = __builtin_roundl(LD);
// CHECK: call x86_fp80 @llvm.round.f80
+ resf = __builtin_roundevenf(F);
+ // CHECK: call float @llvm.roundeven.f32
+
+ resd = __builtin_roundeven(D);
+ // CHECK: call double @llvm.roundeven.f64
+
+ resld = __builtin_roundevenl(LD);
+ // CHECK: call x86_fp80 @llvm.roundeven.f80
+
resli = __builtin_lroundf (F);
// CHECK: call i64 @llvm.lround.i64.f32
More information about the cfe-commits
mailing list