Skip to content

Commit c173edf

Browse files
committed
[DXIL] Add frac unary lowering
1 parent c9b1f1c commit c173edf

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ class DXILOpMapping<int opCode, DXILOpClass opClass, Intrinsic intrinsic, string
218218
// Concrete definition of DXIL Operation mapping to corresponding LLVM intrinsic
219219
def Sin : DXILOpMapping<13, unary, int_sin,
220220
"Returns sine(theta) for theta in radians.">;
221+
def Frac : DXILOpMapping<22, unary, int_dx_frac,
222+
"Returns a fraction from 0 to 1 that represents the "
223+
"decimal part of the input.">;
221224
def UMax : DXILOpMapping<39, binary, int_umax,
222225
"Unsigned integer maximum. UMax(a,b) = a > b ? a : b">;
223226
def ThreadId : DXILOpMapping<93, threadId, int_dx_thread_id,

llvm/test/CodeGen/DirectX/frac.ll

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
2+
3+
; Make sure dxil operation function calls for frac are generated for float and half.
4+
; CHECK:call float @dx.op.unary.f32(i32 22, float %{{.*}})
5+
; CHECK:call half @dx.op.unary.f16(i32 22, half %{{.*}})
6+
7+
target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
8+
target triple = "dxil-pc-shadermodel6.7-library"
9+
10+
; Function Attrs: noinline nounwind optnone
11+
define noundef float @_Z3foof(float noundef %a) #0 {
12+
entry:
13+
%a.addr = alloca float, align 4
14+
store float %a, ptr %a.addr, align 4
15+
%0 = load float, ptr %a.addr, align 4
16+
%dx.frac = call float @llvm.dx.frac.f32(float %0)
17+
ret float %dx.frac
18+
}
19+
20+
; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
21+
declare float @llvm.dx.frac.f32(float) #1
22+
23+
; Function Attrs: noinline nounwind optnone
24+
define noundef half @_Z3barDh(half noundef %a) #0 {
25+
entry:
26+
%a.addr = alloca half, align 2
27+
store half %a, ptr %a.addr, align 2
28+
%0 = load half, ptr %a.addr, align 2
29+
%dx.frac = call half @llvm.dx.frac.f16(half %0)
30+
ret half %dx.frac
31+
}
32+
33+
; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
34+
declare half @llvm.dx.frac.f16(half) #1
35+
36+
attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
37+
attributes #1 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
38+
39+
!llvm.module.flags = !{!0}
40+
!llvm.ident = !{!1}
41+
42+
!0 = !{i32 1, !"wchar_size", i32 4}
43+
!1 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git 73417c517644db5c419c85c0b3cb6750172fcab5)"}

0 commit comments

Comments
 (0)