Skip to content
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

[clang][hlsl][dxil][spirv][x86] Add tan intrinsic #90088

Closed
wants to merge 5 commits into from

Conversation

farzonl
Copy link
Member

@farzonl farzonl commented Apr 25, 2024

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 builtin
  • clang/lib/Headers/hlsl/hlsl_intrinsics.h - Associate the tan builtin with the equivalent hlsl apis
  • clang/lib/Sema/SemaChecking.cpp - Add generic sema checks as well as HLSL specifc sema checks to the tan builtin
  • llvm/docs/GlobalISel/GenericOpcode.rst - Document the G_FTAN opcode
  • llvm/docs/LangRef.rst - Document the tan intrinsic
  • llvm/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 to ISD::FTAN
  • llvm/include/llvm/CodeGen/ISDOpcodes.h - Define ISD opcodes for FTAN and STRICT_FTAN
  • llvm/include/llvm/IR/Intrinsics.td - Create the tan intrinsic
  • llvm/include/llvm/IR/RuntimeLibcalls.def - Define tan libcall mappings
  • llvm/include/llvm/Target/GenericOpcodes.td - Define the G_FTAN Opcode
  • llvm/include/llvm/Support/TargetOpcodes.def - Create a G_FTAN Opcode handler
  • llvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td - Map G_FTAN to ftan
  • llvm/include/llvm/Target/TargetSelectionDAG.td - Define ftan, strict_ftan, and any_ftan and map them to the ISD opcodes for FTAN and STRICT_FTAN
  • llvm/lib/Analysis/VectorUtils.cpp - Associate the tan intrinsic as a vector intrinsic
  • llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp Map the tan intrinsic to G_FTAN Opcode
  • llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp - Add G_FTAN to the list of floating point math operations also associate G_FTAN with the TAN_F runtime lib.
  • llvm/lib/CodeGen/GlobalISel/Utils.cpp - More floating point math operation common behaviors.
  • llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp - List the function expansion operations for FTAN and STRICT_FTAN. Also define both opcodes in PromoteNode.
  • llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp - More FTAN and STRICT_FTAN handling in the legalizer
  • llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h - Define SoftenFloatRes_FTAN and ExpandFloatRes_FTAN.
  • llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp - Define FTAN as a legal vector operation.
  • llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp - Define FTAN 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 Map LibFunc_tan, LibFunc_tanf, and LibFunc_tanl to ISD::FTAN. Map Intrinsic::tan to ISD::FTAN and add selection dag handling for Intrinsic::tan.
  • llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp - Define ftan and strict_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 - Map int_tan (the tan intrinsic) to the equivalent DXIL Op.
  • llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp - Map the G_FTAN opcode to the GLSL 4.5 and openCL tan instructions.
  • llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp - Define G_FTAN as a legal spirv target opcode.
  • llvm/lib/Target/X86/X86ISelLowering.cpp - Add x86_64 lowering for tan intrinsic

closes #70082

This change might also resolve #34950

farzonl added a commit that referenced this pull request May 8, 2024
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

If you want an overarching view of how this will all connect see:
#90088

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 builtin
- `clang/lib/Headers/hlsl/hlsl_intrinsics.h` - Associate the tan builtin
with the equivalent hlsl apis
- `clang/lib/Sema/SemaChecking.cpp` - Add generic sema checks as well as
HLSL specifc sema checks to the tan builtin
-  `llvm/include/llvm/IR/Intrinsics.td` - Create the tan intrinsic
-  `llvm/docs/LangRef.rst` - Document the tan intrinsic
farzonl added a commit that referenced this pull request May 8, 2024
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

If you want an overarching view of how this will all connect see:
#90088

Changes:
-  `llvm/include/llvm/IR/Intrinsics.td` - Create the tan intrinsic
- `llvm/lib/Target/DirectX/DXIL.td` - Map `int_tan` (the tan intrinsic)
to the equivalent DXIL Op.
farzonl added a commit that referenced this pull request May 8, 2024
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

If you want an overarching view of how this will all connect see:
#90088
Changes:
- `llvm/docs/GlobalISel/GenericOpcode.rst` - Document the `G_FTAN`
opcode
-  `llvm/include/llvm/IR/Intrinsics.td` - Create the tan intrinsic
- `llvm/include/llvm/Support/TargetOpcodes.def` - Create a `G_FTAN`
Opcode handler
- `llvm/include/llvm/Target/GenericOpcodes.td` - Define the `G_FTAN`
Opcode
- `llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp` Map the tan intrinsic
to `G_FTAN` Opcode
- `llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp` - Map the
`G_FTAN` opcode to the GLSL 4.5 and openCL tan instructions.
- `llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp` - Define `G_FTAN` as a
legal spirv target opcode.
@farzonl farzonl closed this May 9, 2024
@farzonl farzonl deleted the add-tan-intrinsic branch July 14, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missed optimization in math expression: tan(a) * cos(a) == sin(a) [HLSL] implement tan intrinsic
1 participant