[PATCH 1/1] CGBuiltin: Use frem instruction rather than libcall to implement fmod
Jan Vesely
jan.vesely at rutgers.edu
Fri Sep 19 15:54:43 PDT 2014
AFAICT the semantics of frem match libm's fmod.
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
lib/CodeGen/CGBuiltin.cpp | 8 ++++++++
test/CodeGen/builtins.c | 16 ++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index 69ad762..9238aae 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -241,6 +241,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
return RValue::get(Result);
}
+ case Builtin::BI__builtin_fmod:
+ case Builtin::BI__builtin_fmodf:
+ case Builtin::BI__builtin_fmodl: {
+ Value *Arg1 = EmitScalarExpr(E->getArg(0));
+ Value *Arg2 = EmitScalarExpr(E->getArg(1));
+ Value *Result = Builder.CreateFRem(Arg1, Arg2, "fmod");
+ return RValue::get(Result);
+ }
case Builtin::BI__builtin_conj:
case Builtin::BI__builtin_conjf:
diff --git a/test/CodeGen/builtins.c b/test/CodeGen/builtins.c
index 451ed07..6dd749a 100644
--- a/test/CodeGen/builtins.c
+++ b/test/CodeGen/builtins.c
@@ -197,6 +197,22 @@ void test_float_builtins(float F, double D, long double LD) {
// CHECK: and i1
}
+// CHECK-LABEL: define void @test_float_builtin_ops
+void test_float_builtin_ops(float F, double D, long double LD) {
+ volatile float resf;
+ volatile double resd;
+ volatile long double resld;
+
+ resf = __builtin_fmodf(F,F);
+ // CHECK: frem float
+
+ resd = __builtin_fmod(D,D);
+ // CHECK: frem double
+
+ resld = __builtin_fmodl(LD,LD);
+ // CHECK: frem x86_fp80
+}
+
// CHECK-LABEL: define void @test_builtin_longjmp
void test_builtin_longjmp(void **buffer) {
// CHECK: [[BITCAST:%.*]] = bitcast
--
1.9.3
More information about the cfe-commits
mailing list