Skip to content

Commit 79c32eb

Browse files
authored
[DXIL] Add lowerings for cosine and floor (#86173)
Completes #86170 Completes #86172 - `DXIL.td` - Add changes to lower the cosine and floor intrinsics to dxilOps.
1 parent d8e5c0b commit 79c32eb

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ def Abs : DXILOpMapping<6, unary, int_fabs,
260260
def IsInf : DXILOpMapping<9, isSpecialFloat, int_dx_isinf,
261261
"Determines if the specified value is infinite.",
262262
[llvm_i1_ty, llvm_halforfloat_ty]>;
263+
def Cos : DXILOpMapping<12, unary, int_cos,
264+
"Returns cosine(theta) for theta in radians.",
265+
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
263266
def Sin : DXILOpMapping<13, unary, int_sin,
264267
"Returns sine(theta) for theta in radians.",
265268
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
@@ -279,6 +282,9 @@ def Round : DXILOpMapping<26, unary, int_round,
279282
"Returns the input rounded to the nearest integer"
280283
"within a floating-point type.",
281284
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
285+
def Floor : DXILOpMapping<27, unary, int_floor,
286+
"Returns the largest integer that is less than or equal to the input.",
287+
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
282288
def FMax : DXILOpMapping<35, binary, int_maxnum,
283289
"Float maximum. FMax(a,b) = a > b ? a : b">;
284290
def FMin : DXILOpMapping<36, binary, int_minnum,

llvm/test/CodeGen/DirectX/cos.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 cos are generated for float and half.
4+
5+
define noundef float @cos_float(float noundef %a) #0 {
6+
entry:
7+
; CHECK:call float @dx.op.unary.f32(i32 12, float %{{.*}})
8+
%elt.cos = call float @llvm.cos.f32(float %a)
9+
ret float %elt.cos
10+
}
11+
12+
define noundef half @cos_half(half noundef %a) #0 {
13+
entry:
14+
; CHECK:call half @dx.op.unary.f16(i32 12, half %{{.*}})
15+
%elt.cos = call half @llvm.cos.f16(half %a)
16+
ret half %elt.cos
17+
}
18+
19+
declare half @llvm.cos.f16(half)
20+
declare float @llvm.cos.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 cos does not support double overload type
4+
; CHECK: LLVM ERROR: Invalid Overload Type
5+
6+
define noundef double @cos_double(double noundef %a) {
7+
entry:
8+
%elt.cos = call double @llvm.cos.f64(double %a)
9+
ret double %elt.cos
10+
}

llvm/test/CodeGen/DirectX/floor.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 floor are generated for float and half.
4+
5+
define noundef float @floor_float(float noundef %a) #0 {
6+
entry:
7+
; CHECK:call float @dx.op.unary.f32(i32 27, float %{{.*}})
8+
%elt.floor = call float @llvm.floor.f32(float %a)
9+
ret float %elt.floor
10+
}
11+
12+
define noundef half @floor_half(half noundef %a) #0 {
13+
entry:
14+
; CHECK:call half @dx.op.unary.f16(i32 27, half %{{.*}})
15+
%elt.floor = call half @llvm.floor.f16(half %a)
16+
ret half %elt.floor
17+
}
18+
19+
declare half @llvm.floor.f16(half)
20+
declare float @llvm.floor.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 floor does not support double overload type
4+
; CHECK: LLVM ERROR: Invalid Overload Type
5+
6+
define noundef double @floor_double(double noundef %a) {
7+
entry:
8+
%elt.floor = call double @llvm.floor.f64(double %a)
9+
ret double %elt.floor
10+
}

0 commit comments

Comments
 (0)