Skip to content

Commit cdc294f

Browse files
committed
[X86][CodeGen] Add base trig intrinsic lowerings
This change adds constraint intrinsics and some lowering cases. The only x86 specific change was for f80. The x86 lowering is going to be done in three pr changes with this being the first. A second PR will be put up for Loop Vectorizing and then SLPVectorizer. The constraint intrinsics is also going to be in multiple parts, but just 2. This part covers just the llvm specific changes, part2 will cover clang specifc changes and legalization for backends than have special legalization requirements like aarch64 and wasm.
1 parent e1c03dd commit cdc294f

33 files changed

+3303
-3
lines changed

llvm/docs/LangRef.rst

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26476,6 +26476,219 @@ This function returns the tangent of the specified operand, returning the
2647626476
same values as the libm ``tan`` functions would, and handles error
2647726477
conditions in the same way.
2647826478

26479+
'``llvm.experimental.constrained.asin``' Intrinsic
26480+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26481+
26482+
Syntax:
26483+
"""""""
26484+
26485+
::
26486+
26487+
declare <type>
26488+
@llvm.experimental.constrained.asin(<type> <op1>,
26489+
metadata <rounding mode>,
26490+
metadata <exception behavior>)
26491+
26492+
Overview:
26493+
"""""""""
26494+
26495+
The '``llvm.experimental.constrained.asin``' intrinsic returns the arcsine of the
26496+
first operand.
26497+
26498+
Arguments:
26499+
""""""""""
26500+
26501+
The first argument and the return type are floating-point numbers of the same
26502+
type.
26503+
26504+
The second and third arguments specify the rounding mode and exception
26505+
behavior as described above.
26506+
26507+
Semantics:
26508+
""""""""""
26509+
26510+
This function returns the arcsine of the specified operand, returning the
26511+
same values as the libm ``asin`` functions would, and handles error
26512+
conditions in the same way.
26513+
26514+
26515+
'``llvm.experimental.constrained.acos``' Intrinsic
26516+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26517+
26518+
Syntax:
26519+
"""""""
26520+
26521+
::
26522+
26523+
declare <type>
26524+
@llvm.experimental.constrained.acos(<type> <op1>,
26525+
metadata <rounding mode>,
26526+
metadata <exception behavior>)
26527+
26528+
Overview:
26529+
"""""""""
26530+
26531+
The '``llvm.experimental.constrained.acos``' intrinsic returns the arccosine of the
26532+
first operand.
26533+
26534+
Arguments:
26535+
""""""""""
26536+
26537+
The first argument and the return type are floating-point numbers of the same
26538+
type.
26539+
26540+
The second and third arguments specify the rounding mode and exception
26541+
behavior as described above.
26542+
26543+
Semantics:
26544+
""""""""""
26545+
26546+
This function returns the arccosine of the specified operand, returning the
26547+
same values as the libm ``acos`` functions would, and handles error
26548+
conditions in the same way.
26549+
26550+
26551+
'``llvm.experimental.constrained.atan``' Intrinsic
26552+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26553+
26554+
Syntax:
26555+
"""""""
26556+
26557+
::
26558+
26559+
declare <type>
26560+
@llvm.experimental.constrained.atan(<type> <op1>,
26561+
metadata <rounding mode>,
26562+
metadata <exception behavior>)
26563+
26564+
Overview:
26565+
"""""""""
26566+
26567+
The '``llvm.experimental.constrained.atan``' intrinsic returns the arctangent of the
26568+
first operand.
26569+
26570+
Arguments:
26571+
""""""""""
26572+
26573+
The first argument and the return type are floating-point numbers of the same
26574+
type.
26575+
26576+
The second and third arguments specify the rounding mode and exception
26577+
behavior as described above.
26578+
26579+
Semantics:
26580+
""""""""""
26581+
26582+
This function returns the arctangent of the specified operand, returning the
26583+
same values as the libm ``atan`` functions would, and handles error
26584+
conditions in the same way.
26585+
26586+
'``llvm.experimental.constrained.sinh``' Intrinsic
26587+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26588+
26589+
Syntax:
26590+
"""""""
26591+
26592+
::
26593+
26594+
declare <type>
26595+
@llvm.experimental.constrained.sinh(<type> <op1>,
26596+
metadata <rounding mode>,
26597+
metadata <exception behavior>)
26598+
26599+
Overview:
26600+
"""""""""
26601+
26602+
The '``llvm.experimental.constrained.sinh``' intrinsic returns the hyperbolic sine of the
26603+
first operand.
26604+
26605+
Arguments:
26606+
""""""""""
26607+
26608+
The first argument and the return type are floating-point numbers of the same
26609+
type.
26610+
26611+
The second and third arguments specify the rounding mode and exception
26612+
behavior as described above.
26613+
26614+
Semantics:
26615+
""""""""""
26616+
26617+
This function returns the hyperbolic sine of the specified operand, returning the
26618+
same values as the libm ``sinh`` functions would, and handles error
26619+
conditions in the same way.
26620+
26621+
26622+
'``llvm.experimental.constrained.cosh``' Intrinsic
26623+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26624+
26625+
Syntax:
26626+
"""""""
26627+
26628+
::
26629+
26630+
declare <type>
26631+
@llvm.experimental.constrained.cosh(<type> <op1>,
26632+
metadata <rounding mode>,
26633+
metadata <exception behavior>)
26634+
26635+
Overview:
26636+
"""""""""
26637+
26638+
The '``llvm.experimental.constrained.cosh``' intrinsic returns the hyperbolic cosine of the
26639+
first operand.
26640+
26641+
Arguments:
26642+
""""""""""
26643+
26644+
The first argument and the return type are floating-point numbers of the same
26645+
type.
26646+
26647+
The second and third arguments specify the rounding mode and exception
26648+
behavior as described above.
26649+
26650+
Semantics:
26651+
""""""""""
26652+
26653+
This function returns the hyperbolic cosine of the specified operand, returning the
26654+
same values as the libm ``cosh`` functions would, and handles error
26655+
conditions in the same way.
26656+
26657+
26658+
'``llvm.experimental.constrained.tanh``' Intrinsic
26659+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26660+
26661+
Syntax:
26662+
"""""""
26663+
26664+
::
26665+
26666+
declare <type>
26667+
@llvm.experimental.constrained.tanh(<type> <op1>,
26668+
metadata <rounding mode>,
26669+
metadata <exception behavior>)
26670+
26671+
Overview:
26672+
"""""""""
26673+
26674+
The '``llvm.experimental.constrained.tanh``' intrinsic returns the hyperbolic tangent of the
26675+
first operand.
26676+
26677+
Arguments:
26678+
""""""""""
26679+
26680+
The first argument and the return type are floating-point numbers of the same
26681+
type.
26682+
26683+
The second and third arguments specify the rounding mode and exception
26684+
behavior as described above.
26685+
26686+
Semantics:
26687+
""""""""""
26688+
26689+
This function returns the hyperbolic tangent of the specified operand, returning the
26690+
same values as the libm ``tanh`` functions would, and handles error
26691+
conditions in the same way.
2647926692

2648026693
'``llvm.experimental.constrained.exp``' Intrinsic
2648126694
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,24 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
19801980
case Intrinsic::tan:
19811981
ISD = ISD::FTAN;
19821982
break;
1983+
case Intrinsic::asin:
1984+
ISD = ISD::FASIN;
1985+
break;
1986+
case Intrinsic::acos:
1987+
ISD = ISD::FACOS;
1988+
break;
1989+
case Intrinsic::atan:
1990+
ISD = ISD::FATAN;
1991+
break;
1992+
case Intrinsic::sinh:
1993+
ISD = ISD::FSINH;
1994+
break;
1995+
case Intrinsic::cosh:
1996+
ISD = ISD::FCOSH;
1997+
break;
1998+
case Intrinsic::tanh:
1999+
ISD = ISD::FTANH;
2000+
break;
19832001
case Intrinsic::exp:
19842002
ISD = ISD::FEXP;
19852003
break;

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ enum NodeType {
416416
STRICT_FSIN,
417417
STRICT_FCOS,
418418
STRICT_FTAN,
419+
STRICT_FASIN,
420+
STRICT_FACOS,
421+
STRICT_FATAN,
422+
STRICT_FSINH,
423+
STRICT_FCOSH,
424+
STRICT_FTANH,
419425
STRICT_FEXP,
420426
STRICT_FEXP2,
421427
STRICT_FLOG,
@@ -942,6 +948,12 @@ enum NodeType {
942948
FSIN,
943949
FCOS,
944950
FTAN,
951+
FASIN,
952+
FACOS,
953+
FATAN,
954+
FSINH,
955+
FCOSH,
956+
FTANH,
945957
FPOW,
946958
FPOWI,
947959
/// FLDEXP - ldexp, inspired by libm (op0 * 2**op1).

llvm/include/llvm/IR/ConstrainedOps.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ CMP_INSTRUCTION(FCmp, 2, 0, experimental_constrained_fcmps, FSETCCS
6969
// Theses are definitions for intrinsic functions, that are converted into
7070
// constrained intrinsics.
7171
//
72+
DAG_FUNCTION(acos, 1, 1, experimental_constrained_acos, FACOS)
73+
DAG_FUNCTION(asin, 1, 1, experimental_constrained_asin, FASIN)
74+
DAG_FUNCTION(atan, 1, 1, experimental_constrained_atan, FATAN)
7275
DAG_FUNCTION(ceil, 1, 0, experimental_constrained_ceil, FCEIL)
7376
DAG_FUNCTION(cos, 1, 1, experimental_constrained_cos, FCOS)
77+
DAG_FUNCTION(cosh, 1, 1, experimental_constrained_cosh, FCOSH)
7478
DAG_FUNCTION(exp, 1, 1, experimental_constrained_exp, FEXP)
7579
DAG_FUNCTION(exp2, 1, 1, experimental_constrained_exp2, FEXP2)
7680
DAG_FUNCTION(floor, 1, 0, experimental_constrained_floor, FFLOOR)
@@ -94,8 +98,10 @@ DAG_FUNCTION(rint, 1, 1, experimental_constrained_rint, FRINT)
9498
DAG_FUNCTION(round, 1, 0, experimental_constrained_round, FROUND)
9599
DAG_FUNCTION(roundeven, 1, 0, experimental_constrained_roundeven, FROUNDEVEN)
96100
DAG_FUNCTION(sin, 1, 1, experimental_constrained_sin, FSIN)
101+
DAG_FUNCTION(sinh, 1, 1, experimental_constrained_sinh, FSINH)
97102
DAG_FUNCTION(sqrt, 1, 1, experimental_constrained_sqrt, FSQRT)
98103
DAG_FUNCTION(tan, 1, 1, experimental_constrained_tan, FTAN)
104+
DAG_FUNCTION(tanh, 1, 1, experimental_constrained_tanh, FTANH)
99105
DAG_FUNCTION(trunc, 1, 0, experimental_constrained_trunc, FTRUNC)
100106

101107
// This is definition for fmuladd intrinsic function, that is converted into

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,18 @@ let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn, IntrStrictFP] in
12111211
llvm_anyint_ty,
12121212
llvm_metadata_ty,
12131213
llvm_metadata_ty ]>;
1214+
def int_experimental_constrained_asin : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1215+
[ LLVMMatchType<0>,
1216+
llvm_metadata_ty,
1217+
llvm_metadata_ty ]>;
1218+
def int_experimental_constrained_acos : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1219+
[ LLVMMatchType<0>,
1220+
llvm_metadata_ty,
1221+
llvm_metadata_ty ]>;
1222+
def int_experimental_constrained_atan : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1223+
[ LLVMMatchType<0>,
1224+
llvm_metadata_ty,
1225+
llvm_metadata_ty ]>;
12141226
def int_experimental_constrained_sin : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
12151227
[ LLVMMatchType<0>,
12161228
llvm_metadata_ty,
@@ -1223,6 +1235,18 @@ let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn, IntrStrictFP] in
12231235
[ LLVMMatchType<0>,
12241236
llvm_metadata_ty,
12251237
llvm_metadata_ty ]>;
1238+
def int_experimental_constrained_sinh : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1239+
[ LLVMMatchType<0>,
1240+
llvm_metadata_ty,
1241+
llvm_metadata_ty ]>;
1242+
def int_experimental_constrained_cosh : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1243+
[ LLVMMatchType<0>,
1244+
llvm_metadata_ty,
1245+
llvm_metadata_ty ]>;
1246+
def int_experimental_constrained_tanh : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1247+
[ LLVMMatchType<0>,
1248+
llvm_metadata_ty,
1249+
llvm_metadata_ty ]>;
12261250
def int_experimental_constrained_pow : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
12271251
[ LLVMMatchType<0>,
12281252
LLVMMatchType<0>,

llvm/include/llvm/IR/RuntimeLibcalls.def

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,36 @@ HANDLE_LIBCALL(TAN_F64, "tan")
202202
HANDLE_LIBCALL(TAN_F80, "tanl")
203203
HANDLE_LIBCALL(TAN_F128,"tanl")
204204
HANDLE_LIBCALL(TAN_PPCF128, "tanl")
205+
HANDLE_LIBCALL(SINH_F32, "sinhf")
206+
HANDLE_LIBCALL(SINH_F64, "sinh")
207+
HANDLE_LIBCALL(SINH_F80, "sinhl")
208+
HANDLE_LIBCALL(SINH_F128, "sinhl")
209+
HANDLE_LIBCALL(SINH_PPCF128, "sinhl")
210+
HANDLE_LIBCALL(COSH_F32, "coshf")
211+
HANDLE_LIBCALL(COSH_F64, "cosh")
212+
HANDLE_LIBCALL(COSH_F80, "coshl")
213+
HANDLE_LIBCALL(COSH_F128, "coshl")
214+
HANDLE_LIBCALL(COSH_PPCF128, "coshl")
215+
HANDLE_LIBCALL(TANH_F32, "tanhf")
216+
HANDLE_LIBCALL(TANH_F64, "tanh")
217+
HANDLE_LIBCALL(TANH_F80, "tanhl")
218+
HANDLE_LIBCALL(TANH_F128,"tanhl")
219+
HANDLE_LIBCALL(TANH_PPCF128, "tanhl")
220+
HANDLE_LIBCALL(ASIN_F32, "asinf")
221+
HANDLE_LIBCALL(ASIN_F64, "asin")
222+
HANDLE_LIBCALL(ASIN_F80, "asinl")
223+
HANDLE_LIBCALL(ASIN_F128, "asinl")
224+
HANDLE_LIBCALL(ASIN_PPCF128, "asinl")
225+
HANDLE_LIBCALL(ACOS_F32, "acosf")
226+
HANDLE_LIBCALL(ACOS_F64, "acos")
227+
HANDLE_LIBCALL(ACOS_F80, "acosl")
228+
HANDLE_LIBCALL(ACOS_F128, "acosl")
229+
HANDLE_LIBCALL(ACOS_PPCF128, "acosl")
230+
HANDLE_LIBCALL(ATAN_F32, "atanf")
231+
HANDLE_LIBCALL(ATAN_F64, "atan")
232+
HANDLE_LIBCALL(ATAN_F80, "atanl")
233+
HANDLE_LIBCALL(ATAN_F128,"atanl")
234+
HANDLE_LIBCALL(ATAN_PPCF128, "atanl")
205235
HANDLE_LIBCALL(SINCOS_F32, nullptr)
206236
HANDLE_LIBCALL(SINCOS_F64, nullptr)
207237
HANDLE_LIBCALL(SINCOS_F80, nullptr)

llvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def : GINodeEquiv<G_FCEIL, fceil>;
149149
def : GINodeEquiv<G_FCOS, fcos>;
150150
def : GINodeEquiv<G_FSIN, fsin>;
151151
def : GINodeEquiv<G_FTAN, ftan>;
152+
def : GINodeEquiv<G_FACOS, facos>;
153+
def : GINodeEquiv<G_FASIN, fasin>;
154+
def : GINodeEquiv<G_FATAN, fatan>;
155+
def : GINodeEquiv<G_FCOSH, fcosh>;
156+
def : GINodeEquiv<G_FSINH, fsinh>;
157+
def : GINodeEquiv<G_FTANH, ftanh>;
152158
def : GINodeEquiv<G_FABS, fabs>;
153159
def : GINodeEquiv<G_FSQRT, fsqrt>;
154160
def : GINodeEquiv<G_FFLOOR, ffloor>;

0 commit comments

Comments
 (0)