Skip to content

Commit 93a9a8a

Browse files
committed
[VecLib] Add support for vector fns from Darwin's libsystem.
This patch adds support for Darwin's libsystem math vector functions to TLI. Darwin's libsystem provides a range of vector functions for libm functions. This initial patch only adds the 2 x double and 4 x float versions, which are available on both X86 and ARM64. On X86, wider vector versions are supported as well. Reviewed By: jroelofs Differential Revision: https://reviews.llvm.org/D101856
1 parent 5000a1b commit 93a9a8a

File tree

5 files changed

+858
-5
lines changed

5 files changed

+858
-5
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ class TargetLibraryInfoImpl {
8686
/// addVectorizableFunctionsFromVecLib for filling up the tables of
8787
/// vectorizable functions.
8888
enum VectorLibrary {
89-
NoLibrary, // Don't use any vector library.
90-
Accelerate, // Use Accelerate framework.
91-
LIBMVEC_X86,// GLIBC Vector Math library.
92-
MASSV, // IBM MASS vector library.
93-
SVML // Intel short vector math library.
89+
NoLibrary, // Don't use any vector library.
90+
Accelerate, // Use Accelerate framework.
91+
DarwinLibSystemM, // Use Darwin's libsystem_m.
92+
LIBMVEC_X86, // GLIBC Vector Math library.
93+
MASSV, // IBM MASS vector library.
94+
SVML // Intel short vector math library.
9495
};
9596

9697
TargetLibraryInfoImpl();

llvm/include/llvm/Analysis/VecFuncs.def

+54
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,59 @@ TLI_DEFINE_VECFUNC("asinhf", "vasinhf", FIXED(4))
6464
TLI_DEFINE_VECFUNC("acoshf", "vacoshf", FIXED(4))
6565
TLI_DEFINE_VECFUNC("atanhf", "vatanhf", FIXED(4))
6666

67+
#elif defined(TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS)
68+
// Darwin libsystem_m vector functions.
69+
70+
// Exponential and Logarithmic Functions
71+
TLI_DEFINE_VECFUNC("exp", "_simd_exp_d2", FIXED(2))
72+
TLI_DEFINE_VECFUNC("llvm.exp.f64", "_simd_exp_d2", FIXED(2))
73+
TLI_DEFINE_VECFUNC("expf", "_simd_exp_f4", FIXED(4))
74+
TLI_DEFINE_VECFUNC("llvm.exp.f32", "_simd_exp_f4", FIXED(4))
75+
76+
// Trigonometric Functions
77+
TLI_DEFINE_VECFUNC("acos", "_simd_acos_d2", FIXED(2))
78+
TLI_DEFINE_VECFUNC("acosf", "_simd_acos_f4", FIXED(4))
79+
TLI_DEFINE_VECFUNC("asin", "_simd_asin_d2", FIXED(2))
80+
TLI_DEFINE_VECFUNC("asinf", "_simd_asin_f4", FIXED(4))
81+
82+
TLI_DEFINE_VECFUNC("atan", "_simd_atan_d2", FIXED(2))
83+
TLI_DEFINE_VECFUNC("atanf", "_simd_atan_f4", FIXED(4))
84+
TLI_DEFINE_VECFUNC("atan2", "_simd_atan2_d2", FIXED(2))
85+
TLI_DEFINE_VECFUNC("atan2f", "_simd_atan2_f4", FIXED(4))
86+
87+
TLI_DEFINE_VECFUNC("cos", "_simd_cos_d2", FIXED(2))
88+
TLI_DEFINE_VECFUNC("llvm.cos.f64", "_simd_cos_d2", FIXED(2))
89+
TLI_DEFINE_VECFUNC("cosf", "_simd_cos_f4", FIXED(4))
90+
TLI_DEFINE_VECFUNC("llvm.cos.f32", "_simd_cos_f4", FIXED(4))
91+
92+
TLI_DEFINE_VECFUNC("sin", "_simd_sin_d2", FIXED(2))
93+
TLI_DEFINE_VECFUNC("llvm.sin.f64", "_simd_sin_d2", FIXED(2))
94+
TLI_DEFINE_VECFUNC("sinf", "_simd_sin_f4", FIXED(4))
95+
TLI_DEFINE_VECFUNC("llvm.sin.f32", "_simd_sin_f4", FIXED(4))
96+
97+
// Floating-Point Arithmetic and Auxiliary Functions
98+
TLI_DEFINE_VECFUNC("cbrt", "_simd_cbrt_d2", FIXED(2))
99+
TLI_DEFINE_VECFUNC("cbrtf", "_simd_cbrt_f4", FIXED(4))
100+
TLI_DEFINE_VECFUNC("erf", "_simd_erf_d2", FIXED(2))
101+
TLI_DEFINE_VECFUNC("erff", "_simd_erf_f4", FIXED(4))
102+
TLI_DEFINE_VECFUNC("pow", "_simd_pow_d2", FIXED(2))
103+
TLI_DEFINE_VECFUNC("llvm.pow.f64", "_simd_pow_d2", FIXED(2))
104+
TLI_DEFINE_VECFUNC("powf", "_simd_pow_f4", FIXED(4))
105+
TLI_DEFINE_VECFUNC("llvm.pow.f32", "_simd_pow_f4", FIXED(4))
106+
107+
// Hyperbolic Functions
108+
TLI_DEFINE_VECFUNC("sinh", "_simd_sinh_d2", FIXED(2))
109+
TLI_DEFINE_VECFUNC("sinhf", "_simd_sinh_f4", FIXED(4))
110+
TLI_DEFINE_VECFUNC("cosh", "_simd_cosh_d2", FIXED(2))
111+
TLI_DEFINE_VECFUNC("coshf", "_simd_cosh_f4", FIXED(4))
112+
TLI_DEFINE_VECFUNC("tanh", "_simd_tanh_d2", FIXED(2))
113+
TLI_DEFINE_VECFUNC("tanhf", "_simd_tanh_f4", FIXED(4))
114+
TLI_DEFINE_VECFUNC("asinh", "_simd_asinh_d2", FIXED(2))
115+
TLI_DEFINE_VECFUNC("asinhf", "_simd_asinh_f4", FIXED(4))
116+
TLI_DEFINE_VECFUNC("acosh", "_simd_acosh_d2", FIXED(2))
117+
TLI_DEFINE_VECFUNC("acoshf", "_simd_acosh_f4", FIXED(4))
118+
TLI_DEFINE_VECFUNC("atanh", "_simd_atanh_d2", FIXED(2))
119+
TLI_DEFINE_VECFUNC("atanhf", "_simd_atanh_f4", FIXED(4))
67120

68121
#elif defined(TLI_DEFINE_LIBMVEC_X86_VECFUNCS)
69122
// GLIBC Vector math Functions
@@ -419,6 +472,7 @@ TLI_DEFINE_VECFUNC("__exp2f_finite", "__svml_exp2f16", FIXED(16))
419472

420473
#undef TLI_DEFINE_VECFUNC
421474
#undef TLI_DEFINE_ACCELERATE_VECFUNCS
475+
#undef TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
422476
#undef TLI_DEFINE_LIBMVEC_X86_VECFUNCS
423477
#undef TLI_DEFINE_MASSV_VECFUNCS
424478
#undef TLI_DEFINE_SVML_VECFUNCS

llvm/lib/Analysis/TargetLibraryInfo.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
2424
"No vector functions library"),
2525
clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
2626
"Accelerate framework"),
27+
clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM,
28+
"Darwin_libsystem_m", "Darwin libsystem_m"),
2729
clEnumValN(TargetLibraryInfoImpl::LIBMVEC_X86, "LIBMVEC-X86",
2830
"GLIBC Vector Math library"),
2931
clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV",
@@ -1622,6 +1624,14 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
16221624
addVectorizableFunctions(VecFuncs);
16231625
break;
16241626
}
1627+
case DarwinLibSystemM: {
1628+
const VecDesc VecFuncs[] = {
1629+
#define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1630+
#include "llvm/Analysis/VecFuncs.def"
1631+
};
1632+
addVectorizableFunctions(VecFuncs);
1633+
break;
1634+
}
16251635
case LIBMVEC_X86: {
16261636
const VecDesc VecFuncs[] = {
16271637
#define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes
2+
; RUN: opt -vector-library=Darwin_libsystem_m -replace-with-veclib -S < %s | FileCheck %s
3+
4+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-unknown-linux-gnu"
6+
7+
define <4 x float> @sin_v4f32(<4 x float> %in) {
8+
; CHECK-LABEL: define {{[^@]+}}@sin_v4f32
9+
; CHECK-SAME: (<4 x float> [[IN:%.*]]) {
10+
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x float> @_simd_sin_f4(<4 x float> [[IN]])
11+
; CHECK-NEXT: ret <4 x float> [[TMP1]]
12+
;
13+
%call = call <4 x float> @llvm.sin.v4f32(<4 x float> %in)
14+
ret <4 x float> %call
15+
}
16+
declare <4 x float> @llvm.sin.v4f32(<4 x float>) #0
17+
18+
define <2 x double> @sin_v2f64(<2 x double> %in) {
19+
; CHECK-LABEL: define {{[^@]+}}@sin_v2f64
20+
; CHECK-SAME: (<2 x double> [[IN:%.*]]) {
21+
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x double> @_simd_sin_d2(<2 x double> [[IN]])
22+
; CHECK-NEXT: ret <2 x double> [[TMP1]]
23+
;
24+
%call = call <2 x double> @llvm.sin.v2f64(<2 x double> %in)
25+
ret <2 x double> %call
26+
}
27+
declare <2 x double> @llvm.sin.v2f64(<2 x double>)
28+
29+
30+
define <2 x double> @exp_v2(<2 x double> %in) {
31+
; CHECK-LABEL: define {{[^@]+}}@exp_v2
32+
; CHECK-SAME: (<2 x double> [[IN:%.*]]) {
33+
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x double> @_simd_exp_d2(<2 x double> [[IN]])
34+
; CHECK-NEXT: ret <2 x double> [[TMP1]]
35+
;
36+
%call = call <2 x double> @llvm.exp.v2f64(<2 x double> %in)
37+
ret <2 x double> %call
38+
}
39+
40+
declare <2 x double> @llvm.exp.v2f64(<2 x double>) #0
41+
42+
define <4 x float> @exp_f32(<4 x float> %in) {
43+
; CHECK-LABEL: define {{[^@]+}}@exp_f32
44+
; CHECK-SAME: (<4 x float> [[IN:%.*]]) {
45+
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x float> @_simd_exp_f4(<4 x float> [[IN]])
46+
; CHECK-NEXT: ret <4 x float> [[TMP1]]
47+
;
48+
%call = call <4 x float> @llvm.exp.v4f32(<4 x float> %in)
49+
ret <4 x float> %call
50+
}
51+
52+
declare <4 x float> @llvm.exp.v4f32(<4 x float>) #0
53+
54+
define <3 x double> @exp_v3(<3 x double> %in) {
55+
; CHECK-LABEL: define {{[^@]+}}@exp_v3
56+
; CHECK-SAME: (<3 x double> [[IN:%.*]]) {
57+
; CHECK-NEXT: [[CALL:%.*]] = call <3 x double> @llvm.exp.v3f64(<3 x double> [[IN]])
58+
; CHECK-NEXT: ret <3 x double> [[CALL]]
59+
;
60+
%call = call <3 x double> @llvm.exp.v3f64(<3 x double> %in)
61+
ret <3 x double> %call
62+
}
63+
64+
declare <3 x double> @llvm.exp.v3f64(<3 x double>) #0

0 commit comments

Comments
 (0)