[clang][hlsl][dxil][spirv][x86] Add tan intrinsic #90088
Closed
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_FTANopcodellvm/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::FTANllvm/include/llvm/CodeGen/ISDOpcodes.h- Define ISD opcodes forFTANandSTRICT_FTANllvm/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_FTANOpcodellvm/include/llvm/Support/TargetOpcodes.def- Create aG_FTANOpcode handlerllvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td- MapG_FTANtoftanllvm/include/llvm/Target/TargetSelectionDAG.td- Defineftan,strict_ftan, andany_ftanand map them to the ISD opcodes forFTANandSTRICT_FTANllvm/lib/Analysis/VectorUtils.cpp- Associate the tan intrinsic as a vector intrinsicllvm/lib/CodeGen/GlobalISel/IRTranslator.cppMap the tan intrinsic toG_FTANOpcodellvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp- AddG_FTANto the list of floating point math operations also associateG_FTANwith theTAN_Fruntime lib.llvm/lib/CodeGen/GlobalISel/Utils.cpp- More floating point math operation common behaviors.FTANandSTRICT_FTAN. Also define both opcodes inPromoteNode.llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp- MoreFTANandSTRICT_FTANhandling in the legalizerllvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h- DefineSoftenFloatRes_FTANandExpandFloatRes_FTAN.llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp- DefineFTANas a legal vector operation.llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp- DefineFTANas 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.cppMapLibFunc_tan,LibFunc_tanf, andLibFunc_tanltoISD::FTAN. MapIntrinsic::tantoISD::FTANand add selection dag handling forIntrinsic::tan.llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp- Defineftanandstrict_ftannames 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_FTANopcode to the GLSL 4.5 and openCL tan instructions.llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp- DefineG_FTANas 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