[clang][hlsl][dxil][spirv][x86] Add tan intrinsic #90088
Closed
+354
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change is an implementation of #87367's investigation on supporting IEEE math operations as intrinsics.
Which was discussed in this RFC:
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294
All the X86ISelLowering portions of this pr and tests should be credited to
https://github.com/junaire
https://reviews.llvm.org/D146905
Changes:
clang/docs/LanguageExtensions.rst
- Document the new elementwise tan builtin.clang/include/clang/Basic/Builtins.td
- Implement the tan builtin.clang/lib/CodeGen/CGBuiltin.cpp
- invoke the tan intrinsic on uses of the builtinclang/lib/Headers/hlsl/hlsl_intrinsics.h
- Associate the tan builtin with the equivalent hlsl apisclang/lib/Sema/SemaChecking.cpp
- Add generic sema checks as well as HLSL specifc sema checks to the tan builtinllvm/docs/GlobalISel/GenericOpcode.rst
- Document theG_FTAN
opcodellvm/docs/LangRef.rst
- Document the tan intrinsicllvm/include/llvm/Analysis/VecFuncs.def
- Associate the tan intrinsic as a vector function similar to the tanf libcall.llvm/include/llvm/CodeGen/BasicTTIImpl.h
- Map the tan intrinsic toISD::FTAN
llvm/include/llvm/CodeGen/ISDOpcodes.h
- Define ISD opcodes forFTAN
andSTRICT_FTAN
llvm/include/llvm/IR/Intrinsics.td
- Create the tan intrinsicllvm/include/llvm/IR/RuntimeLibcalls.def
- Define tan libcall mappingsllvm/include/llvm/Target/GenericOpcodes.td
- Define theG_FTAN
Opcodellvm/include/llvm/Support/TargetOpcodes.def
- Create aG_FTAN
Opcode handlerllvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td
- MapG_FTAN
toftan
llvm/include/llvm/Target/TargetSelectionDAG.td
- Defineftan
,strict_ftan
, andany_ftan
and map them to the ISD opcodes forFTAN
andSTRICT_FTAN
llvm/lib/Analysis/VectorUtils.cpp
- Associate the tan intrinsic as a vector intrinsicllvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Map the tan intrinsic toG_FTAN
Opcodellvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
- AddG_FTAN
to the list of floating point math operations also associateG_FTAN
with theTAN_F
runtime lib.llvm/lib/CodeGen/GlobalISel/Utils.cpp
- More floating point math operation common behaviors.FTAN
andSTRICT_FTAN
. Also define both opcodes inPromoteNode
.llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
- MoreFTAN
andSTRICT_FTAN
handling in the legalizerllvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
- DefineSoftenFloatRes_FTAN
andExpandFloatRes_FTAN
.llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
- DefineFTAN
as a legal vector operation.llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
- DefineFTAN
as a legal vector operation.llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
- define tan as an intrinsic that doesn't return NaN.llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
MapLibFunc_tan
,LibFunc_tanf
, andLibFunc_tanl
toISD::FTAN
. MapIntrinsic::tan
toISD::FTAN
and add selection dag handling forIntrinsic::tan
.llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
- Defineftan
andstrict_ftan
names for the equivalent ISD opcodes.llvm/lib/CodeGen/TargetLoweringBase.cpp
-Define a Tan128 libcall and ISD::FTAN as a target lowering action.llvm/lib/Target/DirectX/DXIL.td
- Mapint_tan
(the tan intrinsic) to the equivalent DXIL Op.llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
- Map theG_FTAN
opcode to the GLSL 4.5 and openCL tan instructions.llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
- DefineG_FTAN
as a legal spirv target opcode.llvm/lib/Target/X86/X86ISelLowering.cpp
- Add x86_64 lowering for tan intrinsiccloses #70082
This change might also resolve #34950