Skip to content

Commit e741d88

Browse files
authored
[DXIL] Add frac unary lowering (#83465)
This change adds lowering for HLSL's frac intrinsic to DXIL. This change should complete #70099
1 parent df0fd3a commit e741d88

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-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 Round : DXILOpMapping<26, unary, int_round,
222225
"Returns the input rounded to the nearest integer"
223226
"within a floating-point type.">;

llvm/test/CodeGen/DirectX/frac.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 @frac_float(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 @frac_half(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

0 commit comments

Comments
 (0)