r221206 - Lower __builtin_fabs* to @llvm.fabs.*
Reid Kleckner
reid at kleckner.net
Mon Nov 3 15:52:09 PST 2014
Author: rnk
Date: Mon Nov 3 17:52:09 2014
New Revision: 221206
URL: http://llvm.org/viewvc/llvm-project?rev=221206&view=rev
Log:
Lower __builtin_fabs* to @llvm.fabs.*
mingw64's headers implement fabs by calling __builtin_fabs, so using the
library call results in an infinite loop. If the backend legalizes
@llvm.fabs as a call to fabs later, things should work out, as the crt
provides a definition.
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=221206&r1=221205&r2=221206&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Nov 3 17:52:09 2014
@@ -245,6 +245,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(
return RValue::get(Result);
}
+ case Builtin::BI__builtin_fabs:
+ case Builtin::BI__builtin_fabsf:
+ case Builtin::BI__builtin_fabsl: {
+ Value *Arg1 = EmitScalarExpr(E->getArg(0));
+ Value *Result = EmitFAbs(*this, Arg1);
+ return RValue::get(Result);
+ }
case Builtin::BI__builtin_fmod:
case Builtin::BI__builtin_fmodf:
case Builtin::BI__builtin_fmodl: {
Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=221206&r1=221205&r2=221206&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Mon Nov 3 17:52:09 2014
@@ -211,6 +211,13 @@ void test_float_builtin_ops(float F, dou
resld = __builtin_fmodl(LD,LD);
// CHECK: frem x86_fp80
+
+ resf = __builtin_fabsf(F);
+ resd = __builtin_fabs(D);
+ resld = __builtin_fabsl(LD);
+ // CHECK: call float @llvm.fabs.f32(float
+ // CHECK: call double @llvm.fabs.f64(double
+ // CHECK: call x86_fp80 @llvm.fabs.f80(x86_fp80
}
// CHECK-LABEL: define void @test_builtin_longjmp
More information about the cfe-commits
mailing list