Skip to content

[X86][CodeGen] Add base trig intrinsic lowerings #96222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26497,6 +26497,219 @@ This function returns the tangent of the specified operand, returning the
same values as the libm ``tan`` functions would, and handles error
conditions in the same way.

'``llvm.experimental.constrained.asin``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

::

declare <type>
@llvm.experimental.constrained.asin(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
"""""""""

The '``llvm.experimental.constrained.asin``' intrinsic returns the arcsine of the
first operand.

Arguments:
""""""""""

The first argument and the return type are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above.

Semantics:
""""""""""

This function returns the arcsine of the specified operand, returning the
same values as the libm ``asin`` functions would, and handles error
conditions in the same way.


'``llvm.experimental.constrained.acos``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

::

declare <type>
@llvm.experimental.constrained.acos(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
"""""""""

The '``llvm.experimental.constrained.acos``' intrinsic returns the arccosine of the
first operand.

Arguments:
""""""""""

The first argument and the return type are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above.

Semantics:
""""""""""

This function returns the arccosine of the specified operand, returning the
same values as the libm ``acos`` functions would, and handles error
conditions in the same way.


'``llvm.experimental.constrained.atan``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

::

declare <type>
@llvm.experimental.constrained.atan(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
"""""""""

The '``llvm.experimental.constrained.atan``' intrinsic returns the arctangent of the
first operand.

Arguments:
""""""""""

The first argument and the return type are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above.

Semantics:
""""""""""

This function returns the arctangent of the specified operand, returning the
same values as the libm ``atan`` functions would, and handles error
conditions in the same way.

'``llvm.experimental.constrained.sinh``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

::

declare <type>
@llvm.experimental.constrained.sinh(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
"""""""""

The '``llvm.experimental.constrained.sinh``' intrinsic returns the hyperbolic sine of the
first operand.

Arguments:
""""""""""

The first argument and the return type are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above.

Semantics:
""""""""""

This function returns the hyperbolic sine of the specified operand, returning the
same values as the libm ``sinh`` functions would, and handles error
conditions in the same way.


'``llvm.experimental.constrained.cosh``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

::

declare <type>
@llvm.experimental.constrained.cosh(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
"""""""""

The '``llvm.experimental.constrained.cosh``' intrinsic returns the hyperbolic cosine of the
first operand.

Arguments:
""""""""""

The first argument and the return type are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above.

Semantics:
""""""""""

This function returns the hyperbolic cosine of the specified operand, returning the
same values as the libm ``cosh`` functions would, and handles error
conditions in the same way.


'``llvm.experimental.constrained.tanh``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

::

declare <type>
@llvm.experimental.constrained.tanh(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
"""""""""

The '``llvm.experimental.constrained.tanh``' intrinsic returns the hyperbolic tangent of the
first operand.

Arguments:
""""""""""

The first argument and the return type are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above.

Semantics:
""""""""""

This function returns the hyperbolic tangent of the specified operand, returning the
same values as the libm ``tanh`` functions would, and handles error
conditions in the same way.

'``llvm.experimental.constrained.exp``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
18 changes: 18 additions & 0 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,24 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
case Intrinsic::tan:
ISD = ISD::FTAN;
break;
case Intrinsic::asin:
ISD = ISD::FASIN;
break;
case Intrinsic::acos:
ISD = ISD::FACOS;
break;
case Intrinsic::atan:
ISD = ISD::FATAN;
break;
case Intrinsic::sinh:
ISD = ISD::FSINH;
break;
case Intrinsic::cosh:
ISD = ISD::FCOSH;
break;
case Intrinsic::tanh:
ISD = ISD::FTANH;
break;
case Intrinsic::exp:
ISD = ISD::FEXP;
break;
Expand Down
12 changes: 12 additions & 0 deletions llvm/include/llvm/CodeGen/ISDOpcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ enum NodeType {
STRICT_FSIN,
STRICT_FCOS,
STRICT_FTAN,
STRICT_FASIN,
STRICT_FACOS,
STRICT_FATAN,
STRICT_FSINH,
STRICT_FCOSH,
STRICT_FTANH,
STRICT_FEXP,
STRICT_FEXP2,
STRICT_FLOG,
Expand Down Expand Up @@ -942,6 +948,12 @@ enum NodeType {
FSIN,
FCOS,
FTAN,
FASIN,
FACOS,
FATAN,
FSINH,
FCOSH,
FTANH,
FPOW,
FPOWI,
/// FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/IR/ConstrainedOps.def
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ CMP_INSTRUCTION(FCmp, 2, 0, experimental_constrained_fcmps, FSETCCS
// Theses are definitions for intrinsic functions, that are converted into
// constrained intrinsics.
//
DAG_FUNCTION(acos, 1, 1, experimental_constrained_acos, FACOS)
DAG_FUNCTION(asin, 1, 1, experimental_constrained_asin, FASIN)
DAG_FUNCTION(atan, 1, 1, experimental_constrained_atan, FATAN)
DAG_FUNCTION(ceil, 1, 0, experimental_constrained_ceil, FCEIL)
DAG_FUNCTION(cos, 1, 1, experimental_constrained_cos, FCOS)
DAG_FUNCTION(cosh, 1, 1, experimental_constrained_cosh, FCOSH)
DAG_FUNCTION(exp, 1, 1, experimental_constrained_exp, FEXP)
DAG_FUNCTION(exp2, 1, 1, experimental_constrained_exp2, FEXP2)
DAG_FUNCTION(floor, 1, 0, experimental_constrained_floor, FFLOOR)
Expand All @@ -94,8 +98,10 @@ DAG_FUNCTION(rint, 1, 1, experimental_constrained_rint, FRINT)
DAG_FUNCTION(round, 1, 0, experimental_constrained_round, FROUND)
DAG_FUNCTION(roundeven, 1, 0, experimental_constrained_roundeven, FROUNDEVEN)
DAG_FUNCTION(sin, 1, 1, experimental_constrained_sin, FSIN)
DAG_FUNCTION(sinh, 1, 1, experimental_constrained_sinh, FSINH)
DAG_FUNCTION(sqrt, 1, 1, experimental_constrained_sqrt, FSQRT)
DAG_FUNCTION(tan, 1, 1, experimental_constrained_tan, FTAN)
DAG_FUNCTION(tanh, 1, 1, experimental_constrained_tanh, FTANH)
DAG_FUNCTION(trunc, 1, 0, experimental_constrained_trunc, FTRUNC)

// This is definition for fmuladd intrinsic function, that is converted into
Expand Down
24 changes: 24 additions & 0 deletions llvm/include/llvm/IR/Intrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,18 @@ let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn, IntrStrictFP] in
llvm_anyint_ty,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_asin : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_acos : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_atan : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_sin : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
Expand All @@ -1223,6 +1235,18 @@ let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn, IntrStrictFP] in
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_sinh : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_cosh : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_tanh : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_pow : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
LLVMMatchType<0>,
Expand Down
30 changes: 30 additions & 0 deletions llvm/include/llvm/IR/RuntimeLibcalls.def
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,36 @@ HANDLE_LIBCALL(TAN_F64, "tan")
HANDLE_LIBCALL(TAN_F80, "tanl")
HANDLE_LIBCALL(TAN_F128,"tanl")
HANDLE_LIBCALL(TAN_PPCF128, "tanl")
HANDLE_LIBCALL(SINH_F32, "sinhf")
HANDLE_LIBCALL(SINH_F64, "sinh")
HANDLE_LIBCALL(SINH_F80, "sinhl")
HANDLE_LIBCALL(SINH_F128, "sinhl")
HANDLE_LIBCALL(SINH_PPCF128, "sinhl")
HANDLE_LIBCALL(COSH_F32, "coshf")
HANDLE_LIBCALL(COSH_F64, "cosh")
HANDLE_LIBCALL(COSH_F80, "coshl")
HANDLE_LIBCALL(COSH_F128, "coshl")
HANDLE_LIBCALL(COSH_PPCF128, "coshl")
HANDLE_LIBCALL(TANH_F32, "tanhf")
HANDLE_LIBCALL(TANH_F64, "tanh")
HANDLE_LIBCALL(TANH_F80, "tanhl")
HANDLE_LIBCALL(TANH_F128,"tanhl")
HANDLE_LIBCALL(TANH_PPCF128, "tanhl")
HANDLE_LIBCALL(ASIN_F32, "asinf")
HANDLE_LIBCALL(ASIN_F64, "asin")
HANDLE_LIBCALL(ASIN_F80, "asinl")
HANDLE_LIBCALL(ASIN_F128, "asinl")
HANDLE_LIBCALL(ASIN_PPCF128, "asinl")
HANDLE_LIBCALL(ACOS_F32, "acosf")
HANDLE_LIBCALL(ACOS_F64, "acos")
HANDLE_LIBCALL(ACOS_F80, "acosl")
HANDLE_LIBCALL(ACOS_F128, "acosl")
HANDLE_LIBCALL(ACOS_PPCF128, "acosl")
HANDLE_LIBCALL(ATAN_F32, "atanf")
HANDLE_LIBCALL(ATAN_F64, "atan")
HANDLE_LIBCALL(ATAN_F80, "atanl")
HANDLE_LIBCALL(ATAN_F128,"atanl")
HANDLE_LIBCALL(ATAN_PPCF128, "atanl")
HANDLE_LIBCALL(SINCOS_F32, nullptr)
HANDLE_LIBCALL(SINCOS_F64, nullptr)
HANDLE_LIBCALL(SINCOS_F80, nullptr)
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def : GINodeEquiv<G_FCEIL, fceil>;
def : GINodeEquiv<G_FCOS, fcos>;
def : GINodeEquiv<G_FSIN, fsin>;
def : GINodeEquiv<G_FTAN, ftan>;
def : GINodeEquiv<G_FACOS, facos>;
def : GINodeEquiv<G_FASIN, fasin>;
def : GINodeEquiv<G_FATAN, fatan>;
def : GINodeEquiv<G_FCOSH, fcosh>;
def : GINodeEquiv<G_FSINH, fsinh>;
def : GINodeEquiv<G_FTANH, ftanh>;
def : GINodeEquiv<G_FABS, fabs>;
def : GINodeEquiv<G_FSQRT, fsqrt>;
def : GINodeEquiv<G_FFLOOR, ffloor>;
Expand Down
Loading
Loading