From 6192145ddc2d30258fa5b06942c419eda0291535 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Fri, 26 Sep 2014 01:19:41 +0000 Subject: [PATCH] CGBuiltin: Use frem instruction rather than libcall to implement fmod AFAICT the semantics of frem match libm's fmod. Signed-off-by: Jan Vesely Reviewed-by: Tom Stellard git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218488 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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 69ad762d18..9238aae88c 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 451ed07c73..6dd749a90b 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 -- 2.40.0