Skip to content

Commit 85ef6b7

Browse files
authored
[DXIL] Add tan intrinsic part 2 (#90277)
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.
1 parent 2c20995 commit 85ef6b7

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ def Cos : DXILOpMapping<12, unary, int_cos,
266266
def Sin : DXILOpMapping<13, unary, int_sin,
267267
"Returns sine(theta) for theta in radians.",
268268
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
269+
def Tan : DXILOpMapping<14, unary, int_tan,
270+
"Returns tangent(theta) for theta in radians.",
271+
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
269272
def Exp2 : DXILOpMapping<21, unary, int_exp2,
270273
"Returns the base 2 exponential, or 2**x, of the specified value."
271274
"exp2(x) = 2**x.",

llvm/test/CodeGen/DirectX/tan.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
2+
3+
; Make sure dxil operation function calls for tan are generated for float and half.
4+
5+
define noundef float @tan_float(float noundef %a) #0 {
6+
entry:
7+
; CHECK:call float @dx.op.unary.f32(i32 14, float %{{.*}})
8+
%elt.tan = call float @llvm.tan.f32(float %a)
9+
ret float %elt.tan
10+
}
11+
12+
define noundef half @tan_half(half noundef %a) #0 {
13+
entry:
14+
; CHECK:call half @dx.op.unary.f16(i32 14, half %{{.*}})
15+
%elt.tan = call half @llvm.tan.f16(half %a)
16+
ret half %elt.tan
17+
}
18+
19+
declare half @llvm.tan.f16(half)
20+
declare float @llvm.tan.f32(float)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not opt -S -dxil-op-lower %s 2>&1 | FileCheck %s
2+
3+
; DXIL operation tan does not support double overload type
4+
; CHECK: LLVM ERROR: Invalid Overload
5+
6+
define noundef double @tan_double(double noundef %a) #0 {
7+
entry:
8+
%1 = call double @llvm.tan.f64(double %a)
9+
ret double %1
10+
}

0 commit comments

Comments
 (0)