r218488 - CGBuiltin: Use frem instruction rather than libcall to implement fmod
Jan Vesely
jan.vesely at rutgers.edu
Thu Sep 25 18:19:41 PDT 2014
Author: jvesely
Date: Thu Sep 25 20:19:41 2014
New Revision: 218488
URL: http://llvm.org/viewvc/llvm-project?rev=218488&view=rev
Log:
CGBuiltin: Use frem instruction rather than libcall to implement fmod
AFAICT the semantics of frem match libm's fmod.
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
Reviewed-by: Tom Stellard <tom at stellard.net>
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins.c
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=218488&r1=218487&r2=218488&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Sep 25 20:19:41 2014
@@ -241,6 +241,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(
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:
Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=218488&r1=218487&r2=218488&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Thu Sep 25 20:19:41 2014
@@ -197,6 +197,22 @@ void test_float_builtins(float F, double
// 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
More information about the cfe-commits
mailing list