-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
e7487e4
commit 3e287b4
Showing
6 changed files
with
294 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,15 @@ | ||
| // 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 | ||
|
|
||
| // FIXME: If the builtin does not set errno, it should be converted to an LLVM intrinsic. | ||
|
|
||
| float foo(float X) { | ||
| // HAS_ERRNO: call float @sqrtf(float | ||
| // NO_ERRNO: call float @sqrtf(float | ||
| // NO_ERRNO: call float @llvm.sqrt.f32(float | ||
| return __builtin_sqrtf(X); | ||
| } | ||
|
|
||
| // HAS_ERRNO: declare float @sqrtf(float) [[ATTR:#[0-9]+]] | ||
| // HAS_ERRNO-NOT: attributes [[ATTR]] = {{{.*}} readnone | ||
|
|
||
| // NO_ERRNO: declare float @sqrtf(float) [[ATTR:#[0-9]+]] | ||
| // NO_ERRNO: declare float @llvm.sqrt.f32(float) [[ATTR:#[0-9]+]] | ||
| // NO_ERRNO: attributes [[ATTR]] = { nounwind readnone {{.*}}} | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.