Re: [PATCH] D5896: Emit more intrinsics for builtin functions
arsenm closed this revision. arsenm added a comment. r274370 http://reviews.llvm.org/D5896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D5896: Emit more intrinsics for builtin functions
arsenm added a comment. ping http://reviews.llvm.org/D5896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D5896: Emit more intrinsics for builtin functions
arsenm added a comment. ping http://reviews.llvm.org/D5896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D5896: Emit more intrinsics for builtin functions
arsenm updated this revision to Diff 61472. arsenm added a comment. Attach right diff http://reviews.llvm.org/D5896 Files: lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtins.c Index: test/CodeGen/builtins.c === --- test/CodeGen/builtins.c +++ test/CodeGen/builtins.c @@ -257,6 +257,98 @@ // CHECK: call float @llvm.canonicalize.f32(float // CHECK: call double @llvm.canonicalize.f64(double // CHECK: call x86_fp80 @llvm.canonicalize.f80(x86_fp80 + + resf = __builtin_fminf(F, F); + // CHECK: call float @llvm.minnum.f32 + + resd = __builtin_fmin(D, D); + // CHECK: call double @llvm.minnum.f64 + + resld = __builtin_fminl(LD, LD); + // CHECK: call x86_fp80 @llvm.minnum.f80 + + resf = __builtin_fmaxf(F, F); + // CHECK: call float @llvm.maxnum.f32 + + resd = __builtin_fmax(D, D); + // CHECK: call double @llvm.maxnum.f64 + + resld = __builtin_fmaxl(LD, LD); + // CHECK: call x86_fp80 @llvm.maxnum.f80 + + resf = __builtin_fabsf(F); + // CHECK: call float @llvm.fabs.f32 + + resd = __builtin_fabs(D); + // CHECK: call double @llvm.fabs.f64 + + resld = __builtin_fabsl(LD); + // CHECK: call x86_fp80 @llvm.fabs.f80 + + resf = __builtin_copysignf(F, F); + // CHECK: call float @llvm.copysign.f32 + + resd = __builtin_copysign(D, D); + // CHECK: call double @llvm.copysign.f64 + + resld = __builtin_copysignl(LD, LD); + // CHECK: call x86_fp80 @llvm.copysign.f80 + + + resf = __builtin_ceilf(F); + // CHECK: call float @llvm.ceil.f32 + + resd = __builtin_ceil(D); + // CHECK: call double @llvm.ceil.f64 + + resld = __builtin_ceill(LD); + // CHECK: call x86_fp80 @llvm.ceil.f80 + + resf = __builtin_floorf(F); + // CHECK: call float @llvm.floor.f32 + + resd = __builtin_floor(D); + // CHECK: call double @llvm.floor.f64 + + resld = __builtin_floorl(LD); + // CHECK: call x86_fp80 @llvm.floor.f80 + + resf = __builtin_truncf(F); + // CHECK: call float @llvm.trunc.f32 + + resd = __builtin_trunc(D); + // CHECK: call double @llvm.trunc.f64 + + resld = __builtin_truncl(LD); + // CHECK: call x86_fp80 @llvm.trunc.f80 + + resf = __builtin_rintf(F); + // CHECK: call float @llvm.rint.f32 + + resd = __builtin_rint(D); + // CHECK: call double @llvm.rint.f64 + + resld = __builtin_rintl(LD); + // CHECK: call x86_fp80 @llvm.rint.f80 + + resf = __builtin_nearbyintf(F); + // CHECK: call float @llvm.nearbyint.f32 + + resd = __builtin_nearbyint(D); + // CHECK: call double @llvm.nearbyint.f64 + + resld = __builtin_nearbyintl(LD); + // CHECK: call x86_fp80 @llvm.nearbyint.f80 + + resf = __builtin_roundf(F); + // CHECK: call float @llvm.round.f32 + + resd = __builtin_round(D); + // CHECK: call double @llvm.round.f64 + + resld = __builtin_roundl(LD); + // CHECK: call x86_fp80 @llvm.round.f80 + } // __builtin_longjmp isn't supported on all platforms, so only test it on X86. Index: lib/CodeGen/CGBuiltin.cpp === --- lib/CodeGen/CGBuiltin.cpp +++ lib/CodeGen/CGBuiltin.cpp @@ -217,6 +217,51 @@ ValueType); } +// Emit a simple mangled intrinsic that has 1 argument and a return type +// matching the argument type. +static Value *emitUnaryBuiltin(CodeGenFunction , + const CallExpr *E, + unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + + Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); + return CGF.Builder.CreateCall(F, Src0); +} + +// Emit an intrinsic that has 2 operands of the same type as its result. +static Value *emitBinaryBuiltin(CodeGenFunction , +const CallExpr *E, +unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); + + Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); + return CGF.Builder.CreateCall(F, { Src0, Src1 }); +} + +// Emit an intrinsic that has 3 operands of the same type as its result. +static Value *emitTernaryBuiltin(CodeGenFunction , + const CallExpr *E, + unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); + llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); + + Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); + return CGF.Builder.CreateCall(F, { Src0, Src1, Src2 }); +} + +// Emit an intrinsic that has 1 float or double operand, and 1 integer. +static Value *emitFPIntBuiltin(CodeGenFunction , + const CallExpr *E, + unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); + + Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); +
Re: [PATCH] D5896: Emit more intrinsics for builtin functions
arsenm added a comment. In http://reviews.llvm.org/D5896#463883, @hfinkel wrote: > Why are you removing 'F' from all of the builtin definitions? And if you need > to, why are you not removing them from copysign? That marks them as emitting a libcall. It should also be removed from copysign http://reviews.llvm.org/D5896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D5896: Emit more intrinsics for builtin functions
hfinkel added a comment. Why are you removing 'F' from all of the builtin definitions? And if you need to, why are you not removing them from copysign? http://reviews.llvm.org/D5896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D5896: Emit more intrinsics for builtin functions
arsenm updated this revision to Diff 61432. arsenm added a comment. Update for trunk http://reviews.llvm.org/D5896 Files: include/clang/Basic/Builtins.def lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtins.c Index: test/CodeGen/builtins.c === --- test/CodeGen/builtins.c +++ test/CodeGen/builtins.c @@ -257,6 +257,98 @@ // CHECK: call float @llvm.canonicalize.f32(float // CHECK: call double @llvm.canonicalize.f64(double // CHECK: call x86_fp80 @llvm.canonicalize.f80(x86_fp80 + + resf = __builtin_fminf(F, F); + // CHECK: call float @llvm.minnum.f32 + + resd = __builtin_fmin(D, D); + // CHECK: call double @llvm.minnum.f64 + + resld = __builtin_fminl(LD, LD); + // CHECK: call x86_fp80 @llvm.minnum.f80 + + resf = __builtin_fmaxf(F, F); + // CHECK: call float @llvm.maxnum.f32 + + resd = __builtin_fmax(D, D); + // CHECK: call double @llvm.maxnum.f64 + + resld = __builtin_fmaxl(LD, LD); + // CHECK: call x86_fp80 @llvm.maxnum.f80 + + resf = __builtin_fabsf(F); + // CHECK: call float @llvm.fabs.f32 + + resd = __builtin_fabs(D); + // CHECK: call double @llvm.fabs.f64 + + resld = __builtin_fabsl(LD); + // CHECK: call x86_fp80 @llvm.fabs.f80 + + resf = __builtin_copysignf(F, F); + // CHECK: call float @llvm.copysign.f32 + + resd = __builtin_copysign(D, D); + // CHECK: call double @llvm.copysign.f64 + + resld = __builtin_copysignl(LD, LD); + // CHECK: call x86_fp80 @llvm.copysign.f80 + + + resf = __builtin_ceilf(F); + // CHECK: call float @llvm.ceil.f32 + + resd = __builtin_ceil(D); + // CHECK: call double @llvm.ceil.f64 + + resld = __builtin_ceill(LD); + // CHECK: call x86_fp80 @llvm.ceil.f80 + + resf = __builtin_floorf(F); + // CHECK: call float @llvm.floor.f32 + + resd = __builtin_floor(D); + // CHECK: call double @llvm.floor.f64 + + resld = __builtin_floorl(LD); + // CHECK: call x86_fp80 @llvm.floor.f80 + + resf = __builtin_truncf(F); + // CHECK: call float @llvm.trunc.f32 + + resd = __builtin_trunc(D); + // CHECK: call double @llvm.trunc.f64 + + resld = __builtin_truncl(LD); + // CHECK: call x86_fp80 @llvm.trunc.f80 + + resf = __builtin_rintf(F); + // CHECK: call float @llvm.rint.f32 + + resd = __builtin_rint(D); + // CHECK: call double @llvm.rint.f64 + + resld = __builtin_rintl(LD); + // CHECK: call x86_fp80 @llvm.rint.f80 + + resf = __builtin_nearbyintf(F); + // CHECK: call float @llvm.nearbyint.f32 + + resd = __builtin_nearbyint(D); + // CHECK: call double @llvm.nearbyint.f64 + + resld = __builtin_nearbyintl(LD); + // CHECK: call x86_fp80 @llvm.nearbyint.f80 + + resf = __builtin_roundf(F); + // CHECK: call float @llvm.round.f32 + + resd = __builtin_round(D); + // CHECK: call double @llvm.round.f64 + + resld = __builtin_roundl(LD); + // CHECK: call x86_fp80 @llvm.round.f80 + } // __builtin_longjmp isn't supported on all platforms, so only test it on X86. Index: lib/CodeGen/CGBuiltin.cpp === --- lib/CodeGen/CGBuiltin.cpp +++ lib/CodeGen/CGBuiltin.cpp @@ -217,6 +217,51 @@ ValueType); } +// Emit a simple mangled intrinsic that has 1 argument and a return type +// matching the argument type. +static Value *emitUnaryBuiltin(CodeGenFunction , + const CallExpr *E, + unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + + Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); + return CGF.Builder.CreateCall(F, Src0); +} + +// Emit an intrinsic that has 2 operands of the same type as its result. +static Value *emitBinaryBuiltin(CodeGenFunction , +const CallExpr *E, +unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); + + Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); + return CGF.Builder.CreateCall(F, { Src0, Src1 }); +} + +// Emit an intrinsic that has 3 operands of the same type as its result. +static Value *emitTernaryBuiltin(CodeGenFunction , + const CallExpr *E, + unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); + llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); + + Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); + return CGF.Builder.CreateCall(F, { Src0, Src1, Src2 }); +} + +// Emit an intrinsic that has 1 float or double operand, and 1 integer. +static Value *emitFPIntBuiltin(CodeGenFunction , + const CallExpr *E, + unsigned IntrinsicID) { + llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); + llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); + + Value *F =