Skip to content

Commit 1f6e3e5

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 3e82442 commit 1f6e3e5

21 files changed

+354
-10
lines changed

llvm/include/llvm/Analysis/VecFuncs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ TLI_DEFINE_VECFUNC("llvm.sin.f32", "vsinf", FIXED(4), "_ZGV_LLVM_N4v")
5454
TLI_DEFINE_VECFUNC("cosf", "vcosf", FIXED(4), "_ZGV_LLVM_N4v")
5555
TLI_DEFINE_VECFUNC("llvm.cos.f32", "vcosf", FIXED(4), "_ZGV_LLVM_N4v")
5656
TLI_DEFINE_VECFUNC("tanf", "vtanf", FIXED(4), "_ZGV_LLVM_N4v")
57+
TLI_DEFINE_VECFUNC("llvm.tan.f32", "vtanf", FIXED(4), "_ZGV_LLVM_N4v")
5758
TLI_DEFINE_VECFUNC("asinf", "vasinf", FIXED(4), "_ZGV_LLVM_N4v")
5859
TLI_DEFINE_VECFUNC("acosf", "vacosf", FIXED(4), "_ZGV_LLVM_N4v")
5960
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
@@ -1924,6 +1924,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
19241924
case Intrinsic::cos:
19251925
ISD = ISD::FCOS;
19261926
break;
1927+
case Intrinsic::tan:
1928+
ISD = ISD::FTAN;
1929+
break;
19271930
case Intrinsic::exp:
19281931
ISD = ISD::FEXP;
19291932
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",
@@ -1514,6 +1517,9 @@ def any_fsin : PatFrags<(ops node:$src),
15141517
def any_fcos : PatFrags<(ops node:$src),
15151518
[(strict_fcos node:$src),
15161519
(fcos node:$src)]>;
1520+
def any_ftan : PatFrags<(ops node:$src),
1521+
[(strict_ftan node:$src),
1522+
(ftan node:$src)]>;
15171523
def any_fexp2 : PatFrags<(ops node:$src),
15181524
[(strict_fexp2 node:$src),
15191525
(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
@@ -448,6 +448,8 @@ static RTLIB::Libcall getRTLibDesc(unsigned Opcode, unsigned Size) {
448448
RTLIBCASE(SIN_F);
449449
case TargetOpcode::G_FCOS:
450450
RTLIBCASE(COS_F);
451+
case TargetOpcode::G_FTAN:
452+
RTLIBCASE(TAN_F);
451453
case TargetOpcode::G_FLOG10:
452454
RTLIBCASE(LOG10_F);
453455
case TargetOpcode::G_FLOG:
@@ -1036,6 +1038,7 @@ LegalizerHelper::libcall(MachineInstr &MI, LostDebugLocObserver &LocObserver) {
10361038
case TargetOpcode::G_FREM:
10371039
case TargetOpcode::G_FCOS:
10381040
case TargetOpcode::G_FSIN:
1041+
case TargetOpcode::G_FTAN:
10391042
case TargetOpcode::G_FLOG10:
10401043
case TargetOpcode::G_FLOG:
10411044
case TargetOpcode::G_FLOG2:
@@ -2890,6 +2893,7 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
28902893
case TargetOpcode::G_FFLOOR:
28912894
case TargetOpcode::G_FCOS:
28922895
case TargetOpcode::G_FSIN:
2896+
case TargetOpcode::G_FTAN:
28932897
case TargetOpcode::G_FLOG10:
28942898
case TargetOpcode::G_FLOG:
28952899
case TargetOpcode::G_FLOG2:
@@ -4656,6 +4660,7 @@ LegalizerHelper::fewerElementsVector(MachineInstr &MI, unsigned TypeIdx,
46564660
case G_INTRINSIC_TRUNC:
46574661
case G_FCOS:
46584662
case G_FSIN:
4663+
case G_FTAN:
46594664
case G_FSQRT:
46604665
case G_BSWAP:
46614666
case G_BITREVERSE:

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ bool llvm::isKnownNeverNaN(Register Val, const MachineRegisterInfo &MRI,
821821
case TargetOpcode::G_FREM:
822822
case TargetOpcode::G_FSIN:
823823
case TargetOpcode::G_FCOS:
824+
case TargetOpcode::G_FTAN:
824825
case TargetOpcode::G_FMA:
825826
case TargetOpcode::G_FMAD:
826827
if (SNaN)
@@ -1701,6 +1702,7 @@ bool llvm::isPreISelGenericFloatingPointOpcode(unsigned Opc) {
17011702
case TargetOpcode::G_FREM:
17021703
case TargetOpcode::G_FRINT:
17031704
case TargetOpcode::G_FSIN:
1705+
case TargetOpcode::G_FTAN:
17041706
case TargetOpcode::G_FSQRT:
17051707
case TargetOpcode::G_FSUB:
17061708
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
@@ -4483,6 +4483,11 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
44834483
RTLIB::COS_F80, RTLIB::COS_F128,
44844484
RTLIB::COS_PPCF128, Results);
44854485
break;
4486+
case ISD::FTAN:
4487+
case ISD::STRICT_FTAN:
4488+
ExpandFPLibCall(Node, RTLIB::TAN_F32, RTLIB::TAN_F64, RTLIB::TAN_F80,
4489+
RTLIB::TAN_F128, RTLIB::TAN_PPCF128, Results);
4490+
break;
44864491
case ISD::FSINCOS:
44874492
// Expand into sincos libcall.
44884493
ExpandSinCosLibCall(Node, Results);
@@ -5433,6 +5438,7 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
54335438
case ISD::FSQRT:
54345439
case ISD::FSIN:
54355440
case ISD::FCOS:
5441+
case ISD::FTAN:
54365442
case ISD::FLOG:
54375443
case ISD::FLOG2:
54385444
case ISD::FLOG10:
@@ -5457,6 +5463,7 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
54575463
case ISD::STRICT_FSQRT:
54585464
case ISD::STRICT_FSIN:
54595465
case ISD::STRICT_FCOS:
5466+
case ISD::STRICT_FTAN:
54605467
case ISD::STRICT_FLOG:
54615468
case ISD::STRICT_FLOG2:
54625469
case ISD::STRICT_FLOG10:

0 commit comments

Comments
 (0)