[PATCH 1/1] CGBuiltin: Use frem instruction rather than libcall to implement fmod

Jan Vesely jan.vesely at rutgers.edu
Thu Sep 25 12:51:04 PDT 2014


ping

On Fri, 2014-09-19 at 18:54 -0400, Jan Vesely wrote:
> 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


-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140925/05250c9a/attachment.sig>


More information about the cfe-commits mailing list