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 Much of this change was following how G_FSIN and G_FCOS were used. Changes: - `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/X86/X86ISelLowering.cpp` - Add x86_64 lowering for tan intrinsic resolves https://github.com/llvm/llvm-project/issues/70082
71 lines
2.0 KiB
LLVM
71 lines
2.0 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
|
|
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
|
|
|
|
define half @use_tanf16(half %a) nounwind {
|
|
; CHECK-LABEL: use_tanf16:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: pushq %rax
|
|
; CHECK-NEXT: callq __extendhfsf2@PLT
|
|
; CHECK-NEXT: callq tanf@PLT
|
|
; CHECK-NEXT: callq __truncsfhf2@PLT
|
|
; CHECK-NEXT: popq %rax
|
|
; CHECK-NEXT: retq
|
|
%x = call half @llvm.tan.f16(half %a)
|
|
ret half %x
|
|
}
|
|
|
|
define float @use_tanf32(float %a) nounwind {
|
|
; CHECK-LABEL: use_tanf32:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: jmp tanf@PLT # TAILCALL
|
|
%x = call float @llvm.tan.f32(float %a)
|
|
ret float %x
|
|
}
|
|
|
|
define double @use_tanf64(double %a) nounwind {
|
|
; CHECK-LABEL: use_tanf64:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: jmp tan@PLT # TAILCALL
|
|
%x = call double @llvm.tan.f64(double %a)
|
|
ret double %x
|
|
}
|
|
|
|
define x86_fp80 @use_tanf80(x86_fp80 %a) nounwind {
|
|
; CHECK-LABEL: use_tanf80:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: subq $24, %rsp
|
|
; CHECK-NEXT: fldt 32(%rsp)
|
|
; CHECK-NEXT: fstpt (%rsp)
|
|
; CHECK-NEXT: callq tanl@PLT
|
|
; CHECK-NEXT: addq $24, %rsp
|
|
; CHECK-NEXT: retq
|
|
%x = call x86_fp80 @llvm.tan.f80(x86_fp80 %a)
|
|
ret x86_fp80 %x
|
|
}
|
|
|
|
define fp128 @use_tanfp128(fp128 %a) nounwind {
|
|
; CHECK-LABEL: use_tanfp128:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: jmp tanf128@PLT # TAILCALL
|
|
%x = call fp128 @llvm.tan.f128(fp128 %a)
|
|
ret fp128 %x
|
|
}
|
|
|
|
define ppc_fp128 @use_tanppc_fp128(ppc_fp128 %a) nounwind {
|
|
; CHECK-LABEL: use_tanppc_fp128:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: pushq %rax
|
|
; CHECK-NEXT: callq tanl@PLT
|
|
; CHECK-NEXT: popq %rax
|
|
; CHECK-NEXT: retq
|
|
%x = call ppc_fp128 @llvm.tan.ppcf128(ppc_fp128 %a)
|
|
ret ppc_fp128 %x
|
|
}
|
|
|
|
declare half @llvm.tan.f16(half)
|
|
declare float @llvm.tan.f32(float)
|
|
declare double @llvm.tan.f64(double)
|
|
declare x86_fp80 @llvm.tan.f80(x86_fp80)
|
|
declare fp128 @llvm.tan.f128(fp128)
|
|
declare ppc_fp128 @llvm.tan.ppcf128(ppc_fp128)
|