2017-11-01 04:19:39 +08:00
|
|
|
// RUN: %clang_cc1 -fmath-errno -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=HAS_ERRNO
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=NO_ERRNO
|
|
|
|
|
|
|
|
float foo(float X) {
|
|
|
|
// HAS_ERRNO: call float @sqrtf(float
|
[CodeGen] convert math libcalls/builtins to equivalent LLVM intrinsics
There are 20 LLVM math intrinsics that correspond to mathlib calls according to the LangRef:
http://llvm.org/docs/LangRef.html#standard-c-library-intrinsics
We were only converting 3 mathlib calls (sqrt, fma, pow) and 12 builtin calls (ceil, copysign,
fabs, floor, fma, fmax, fmin, nearbyint, pow, rint, round, trunc) to their intrinsic-equivalents.
This patch pulls the transforms together and handles all 20 cases. The switch is guarded by a
check for const-ness to make sure we're not doing the transform if errno could possibly be set by
the libcall or builtin.
Differential Revision: https://reviews.llvm.org/D40044
llvm-svn: 319593
2017-12-02 07:15:52 +08:00
|
|
|
// NO_ERRNO: call float @llvm.sqrt.f32(float
|
2017-11-01 04:19:39 +08:00
|
|
|
return __builtin_sqrtf(X);
|
|
|
|
}
|
|
|
|
|
|
|
|
// HAS_ERRNO: declare float @sqrtf(float) [[ATTR:#[0-9]+]]
|
2017-11-03 04:39:26 +08:00
|
|
|
// HAS_ERRNO-NOT: attributes [[ATTR]] = {{{.*}} readnone
|
2017-11-01 04:19:39 +08:00
|
|
|
|
[CodeGen] convert math libcalls/builtins to equivalent LLVM intrinsics
There are 20 LLVM math intrinsics that correspond to mathlib calls according to the LangRef:
http://llvm.org/docs/LangRef.html#standard-c-library-intrinsics
We were only converting 3 mathlib calls (sqrt, fma, pow) and 12 builtin calls (ceil, copysign,
fabs, floor, fma, fmax, fmin, nearbyint, pow, rint, round, trunc) to their intrinsic-equivalents.
This patch pulls the transforms together and handles all 20 cases. The switch is guarded by a
check for const-ness to make sure we're not doing the transform if errno could possibly be set by
the libcall or builtin.
Differential Revision: https://reviews.llvm.org/D40044
llvm-svn: 319593
2017-12-02 07:15:52 +08:00
|
|
|
// NO_ERRNO: declare float @llvm.sqrt.f32(float) [[ATTR:#[0-9]+]]
|
2017-11-01 04:19:39 +08:00
|
|
|
// NO_ERRNO: attributes [[ATTR]] = { nounwind readnone {{.*}}}
|
|
|
|
|