Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/lib/Target/DirectX/DXIL.td
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ class DXILOpMapping<int opCode, DXILOpClass opClass,
def IsInf : DXILOpMapping<9, isSpecialFloat, int_dx_isinf,
"Determines if the specified value is infinite.",
[llvm_i1_ty, llvm_halforfloat_ty]>;
def Cos : DXILOpMapping<12, unary, int_cos,
"Returns cosine(theta) for theta in radians.",
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
def Sin : DXILOpMapping<13, unary, int_sin,
"Returns sine(theta) for theta in radians.",
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
Expand All @@ -277,6 +280,9 @@ def Round : DXILOpMapping<26, unary, int_round,
"Returns the input rounded to the nearest integer"
"within a floating-point type.",
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
def Floor : DXILOpMapping<27, unary, int_floor,
"Returns the largest integer that is less than or equal to the input.",
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
def FMax : DXILOpMapping<35, binary, int_maxnum,
"Float maximum. FMax(a,b) = a > b ? a : b">;
def FMin : DXILOpMapping<36, binary, int_minnum,
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/DirectX/cos.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: opt -S -dxil-op-lower < %s | FileCheck %s

; Make sure dxil operation function calls for cos are generated for float and half.

define noundef float @cos_float(float noundef %a) #0 {
entry:
; CHECK:call float @dx.op.unary.f32(i32 12, float %{{.*}})
%elt.cos = call float @llvm.cos.f32(float %a)
ret float %elt.cos
}

define noundef half @cos_half(half noundef %a) #0 {
entry:
; CHECK:call half @dx.op.unary.f16(i32 12, half %{{.*}})
%elt.cos = call half @llvm.cos.f16(half %a)
ret half %elt.cos
}

declare half @llvm.cos.f16(half)
declare float @llvm.cos.f32(float)
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/DirectX/cos_error.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; RUN: not opt -S -dxil-op-lower %s 2>&1 | FileCheck %s

; DXIL operation cos does not support double overload type
; CHECK: LLVM ERROR: Invalid Overload Type

define noundef double @cos_double(double noundef %a) {
entry:
%elt.cos = call double @llvm.cos.f64(double %a)
ret double %elt.cos
}
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/DirectX/floor.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: opt -S -dxil-op-lower < %s | FileCheck %s

; Make sure dxil operation function calls for floor are generated for float and half.

define noundef float @floor_float(float noundef %a) #0 {
entry:
; CHECK:call float @dx.op.unary.f32(i32 27, float %{{.*}})
%elt.floor = call float @llvm.floor.f32(float %a)
ret float %elt.floor
}

define noundef half @floor_half(half noundef %a) #0 {
entry:
; CHECK:call half @dx.op.unary.f16(i32 27, half %{{.*}})
%elt.floor = call half @llvm.floor.f16(half %a)
ret half %elt.floor
}

declare half @llvm.floor.f16(half)
declare float @llvm.floor.f32(float)
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/DirectX/floor_error.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; RUN: not opt -S -dxil-op-lower %s 2>&1 | FileCheck %s

; DXIL operation floor does not support double overload type
; CHECK: LLVM ERROR: Invalid Overload Type

define noundef double @floor_double(double noundef %a) {
entry:
%elt.floor = call double @llvm.floor.f64(double %a)
ret double %elt.floor
}