Skip to content

Commit 4d4d087

Browse files
committed
start of tan intrinsic
copy over X86ISelLowering and x86 test cases from @junaire's https://reviews.llvm.org/D146905 fix test case run clang format fix unit test and documentation
1 parent b963931 commit 4d4d087

21 files changed

+352
-10
lines changed

llvm/include/llvm/Analysis/VecFuncs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ TLI_DEFINE_VECFUNC("llvm.sin.f32", "vsinf", FIXED(4), "_ZGV_LLVM_N4v")
4949
TLI_DEFINE_VECFUNC("cosf", "vcosf", FIXED(4), "_ZGV_LLVM_N4v")
5050
TLI_DEFINE_VECFUNC("llvm.cos.f32", "vcosf", FIXED(4), "_ZGV_LLVM_N4v")
5151
TLI_DEFINE_VECFUNC("tanf", "vtanf", FIXED(4), "_ZGV_LLVM_N4v")
52+
TLI_DEFINE_VECFUNC("llvm.tan.f32", "vtanf", FIXED(4), "_ZGV_LLVM_N4v")
5253
TLI_DEFINE_VECFUNC("asinf", "vasinf", FIXED(4), "_ZGV_LLVM_N4v")
5354
TLI_DEFINE_VECFUNC("acosf", "vacosf", FIXED(4), "_ZGV_LLVM_N4v")
5455
TLI_DEFINE_VECFUNC("atanf", "vatanf", FIXED(4), "_ZGV_LLVM_N4v")

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
19731973
case Intrinsic::cos:
19741974
ISD = ISD::FCOS;
19751975
break;
1976+
case Intrinsic::tan:
1977+
ISD = ISD::FTAN;
1978+
break;
19761979
case Intrinsic::exp:
19771980
ISD = ISD::FEXP;
19781981
break;

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ enum NodeType {
415415
STRICT_FLDEXP,
416416
STRICT_FSIN,
417417
STRICT_FCOS,
418+
STRICT_FTAN,
418419
STRICT_FEXP,
419420
STRICT_FEXP2,
420421
STRICT_FLOG,
@@ -934,6 +935,7 @@ enum NodeType {
934935
FCBRT,
935936
FSIN,
936937
FCOS,
938+
FTAN,
937939
FPOW,
938940
FPOWI,
939941
/// FLDEXP - ldexp, inspired by libm (op0 * 2**op1).

llvm/include/llvm/IR/RuntimeLibcalls.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ HANDLE_LIBCALL(COS_F64, "cos")
197197
HANDLE_LIBCALL(COS_F80, "cosl")
198198
HANDLE_LIBCALL(COS_F128, "cosl")
199199
HANDLE_LIBCALL(COS_PPCF128, "cosl")
200+
HANDLE_LIBCALL(TAN_F32, "tanf")
201+
HANDLE_LIBCALL(TAN_F64, "tan")
202+
HANDLE_LIBCALL(TAN_F80, "tanl")
203+
HANDLE_LIBCALL(TAN_F128,"tanl")
204+
HANDLE_LIBCALL(TAN_PPCF128, "tanl")
200205
HANDLE_LIBCALL(SINCOS_F32, nullptr)
201206
HANDLE_LIBCALL(SINCOS_F64, nullptr)
202207
HANDLE_LIBCALL(SINCOS_F80, nullptr)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def : GINodeEquiv<G_BUILD_VECTOR, build_vector>;
148148
def : GINodeEquiv<G_FCEIL, fceil>;
149149
def : GINodeEquiv<G_FCOS, fcos>;
150150
def : GINodeEquiv<G_FSIN, fsin>;
151+
def : GINodeEquiv<G_FTAN, ftan>;
151152
def : GINodeEquiv<G_FABS, fabs>;
152153
def : GINodeEquiv<G_FSQRT, fsqrt>;
153154
def : GINodeEquiv<G_FFLOOR, ffloor>;

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
509509
def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
510510
def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
511511
def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
512+
def ftan : SDNode<"ISD::FTAN" , SDTFPUnaryOp>;
512513
def fexp2 : SDNode<"ISD::FEXP2" , SDTFPUnaryOp>;
513514
def fexp10 : SDNode<"ISD::FEXP10" , SDTFPUnaryOp>;
514515
def fpow : SDNode<"ISD::FPOW" , SDTFPBinOp>;
@@ -562,6 +563,8 @@ def strict_fsin : SDNode<"ISD::STRICT_FSIN",
562563
SDTFPUnaryOp, [SDNPHasChain]>;
563564
def strict_fcos : SDNode<"ISD::STRICT_FCOS",
564565
SDTFPUnaryOp, [SDNPHasChain]>;
566+
def strict_ftan : SDNode<"ISD::STRICT_FTAN",
567+
SDTFPUnaryOp, [SDNPHasChain]>;
565568
def strict_fexp2 : SDNode<"ISD::STRICT_FEXP2",
566569
SDTFPUnaryOp, [SDNPHasChain]>;
567570
def strict_fpow : SDNode<"ISD::STRICT_FPOW",
@@ -1517,6 +1520,9 @@ def any_fsin : PatFrags<(ops node:$src),
15171520
def any_fcos : PatFrags<(ops node:$src),
15181521
[(strict_fcos node:$src),
15191522
(fcos node:$src)]>;
1523+
def any_ftan : PatFrags<(ops node:$src),
1524+
[(strict_ftan node:$src),
1525+
(ftan node:$src)]>;
15201526
def any_fexp2 : PatFrags<(ops node:$src),
15211527
[(strict_fexp2 node:$src),
15221528
(fexp2 node:$src)]>;

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) {
6868
case Intrinsic::sqrt: // Begin floating-point.
6969
case Intrinsic::sin:
7070
case Intrinsic::cos:
71+
case Intrinsic::tan:
7172
case Intrinsic::exp:
7273
case Intrinsic::exp2:
7374
case Intrinsic::log:

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ static RTLIB::Libcall getRTLibDesc(unsigned Opcode, unsigned Size) {
449449
RTLIBCASE(SIN_F);
450450
case TargetOpcode::G_FCOS:
451451
RTLIBCASE(COS_F);
452+
case TargetOpcode::G_FTAN:
453+
RTLIBCASE(TAN_F);
452454
case TargetOpcode::G_FLOG10:
453455
RTLIBCASE(LOG10_F);
454456
case TargetOpcode::G_FLOG:
@@ -1037,6 +1039,7 @@ LegalizerHelper::libcall(MachineInstr &MI, LostDebugLocObserver &LocObserver) {
10371039
case TargetOpcode::G_FREM:
10381040
case TargetOpcode::G_FCOS:
10391041
case TargetOpcode::G_FSIN:
1042+
case TargetOpcode::G_FTAN:
10401043
case TargetOpcode::G_FLOG10:
10411044
case TargetOpcode::G_FLOG:
10421045
case TargetOpcode::G_FLOG2:
@@ -2893,6 +2896,7 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
28932896
case TargetOpcode::G_FFLOOR:
28942897
case TargetOpcode::G_FCOS:
28952898
case TargetOpcode::G_FSIN:
2899+
case TargetOpcode::G_FTAN:
28962900
case TargetOpcode::G_FLOG10:
28972901
case TargetOpcode::G_FLOG:
28982902
case TargetOpcode::G_FLOG2:
@@ -4659,6 +4663,7 @@ LegalizerHelper::fewerElementsVector(MachineInstr &MI, unsigned TypeIdx,
46594663
case G_INTRINSIC_TRUNC:
46604664
case G_FCOS:
46614665
case G_FSIN:
4666+
case G_FTAN:
46624667
case G_FSQRT:
46634668
case G_BSWAP:
46644669
case G_BITREVERSE:

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ bool llvm::isKnownNeverNaN(Register Val, const MachineRegisterInfo &MRI,
833833
case TargetOpcode::G_FREM:
834834
case TargetOpcode::G_FSIN:
835835
case TargetOpcode::G_FCOS:
836+
case TargetOpcode::G_FTAN:
836837
case TargetOpcode::G_FMA:
837838
case TargetOpcode::G_FMAD:
838839
if (SNaN)
@@ -1713,6 +1714,7 @@ bool llvm::isPreISelGenericFloatingPointOpcode(unsigned Opc) {
17131714
case TargetOpcode::G_FREM:
17141715
case TargetOpcode::G_FRINT:
17151716
case TargetOpcode::G_FSIN:
1717+
case TargetOpcode::G_FTAN:
17161718
case TargetOpcode::G_FSQRT:
17171719
case TargetOpcode::G_FSUB:
17181720
case TargetOpcode::G_INTRINSIC_ROUND:

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,6 +4492,11 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
44924492
RTLIB::COS_F80, RTLIB::COS_F128,
44934493
RTLIB::COS_PPCF128, Results);
44944494
break;
4495+
case ISD::FTAN:
4496+
case ISD::STRICT_FTAN:
4497+
ExpandFPLibCall(Node, RTLIB::TAN_F32, RTLIB::TAN_F64, RTLIB::TAN_F80,
4498+
RTLIB::TAN_F128, RTLIB::TAN_PPCF128, Results);
4499+
break;
44954500
case ISD::FSINCOS:
44964501
// Expand into sincos libcall.
44974502
ExpandSinCosLibCall(Node, Results);
@@ -5446,6 +5451,7 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
54465451
case ISD::FSQRT:
54475452
case ISD::FSIN:
54485453
case ISD::FCOS:
5454+
case ISD::FTAN:
54495455
case ISD::FLOG:
54505456
case ISD::FLOG2:
54515457
case ISD::FLOG10:
@@ -5470,6 +5476,7 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
54705476
case ISD::STRICT_FSQRT:
54715477
case ISD::STRICT_FSIN:
54725478
case ISD::STRICT_FCOS:
5479+
case ISD::STRICT_FTAN:
54735480
case ISD::STRICT_FLOG:
54745481
case ISD::STRICT_FLOG2:
54755482
case ISD::STRICT_FLOG10:

0 commit comments

Comments
 (0)