Skip to content

Commit 5a36124

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 6621505 commit 5a36124

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
@@ -26497,6 +26497,219 @@ This function returns the tangent of the specified operand, returning the
2649726497
same values as the libm ``tan`` functions would, and handles error
2649826498
conditions in the same way.
2649926499

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

2650126714
'``llvm.experimental.constrained.exp``' Intrinsic
2650226715
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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)