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

Jan Vesely jan.vesely at rutgers.edu
Thu Sep 25 18:53:53 PDT 2014


On Thu, 2014-09-25 at 18:17 -0400, Tom Stellard wrote:
> LGTM.

thanks, pushed

> 
> On Thu, Sep 25, 2014 at 03:51:04PM -0400, Jan Vesely wrote:
> > 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>
> 
> 


-- 
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/459ccd28/attachment.sig>


More information about the cfe-commits mailing list