Skip to content

Commit e8c5dba

Browse files
committed
[DXIL] add WaveReadLaneAt intrinsic for scalars
- add WaveReadLaneAt intrinsic to IntrinsicsDirectX.td and mapping to DXIL.td - add test to show scalar functionality - note that this doesn't include support for the scalarizer to handle this function will be added in a future pr
1 parent 7008964 commit e8c5dba

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def int_dx_umad : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLV
8383
def int_dx_normalize : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
8484
def int_dx_rsqrt : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem]>;
8585
def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
86+
def int_dx_wave_read_lane_at : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent]>;
8687
def int_dx_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
8788
def int_dx_step : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>], [IntrNoMem]>;
8889
}

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,3 +801,13 @@ def WaveIsFirstLane : DXILOp<110, waveIsFirstLane> {
801801
let stages = [Stages<DXIL1_0, [all_stages]>];
802802
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
803803
}
804+
805+
def WaveReadLaneAt: DXILOp<117, waveIsFirstLane> {
806+
let Doc = "returns the value from the specified lane";
807+
let LLVMIntrinsic = int_dx_wave_read_lane_at;
808+
let arguments = [OverloadTy, Int32Ty];
809+
let result = OverloadTy;
810+
let overloads = [Overloads<DXIL1_0, [HalfTy, FloatTy, DoubleTy, Int1Ty, Int16Ty, Int32Ty]>];
811+
let stages = [Stages<DXIL1_0, [all_stages]>];
812+
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
813+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s | FileCheck %s
2+
3+
; Test that for scalar values, WaveReadLaneAt maps down to the DirectX op
4+
5+
define noundef half @wave_rla_half(half noundef %expr, i32 noundef %idx) #0 {
6+
entry:
7+
; CHECK: call half @dx.op.waveReadLaneAt.f16(i32 117, half %expr, i32 %idx)
8+
%ret = call half @llvm.dx.wave.read.lane.at.f16(half %expr, i32 %idx)
9+
ret half %ret
10+
}
11+
12+
define noundef float @wave_rla_float(float noundef %expr, i32 noundef %idx) #0 {
13+
entry:
14+
; CHECK: call float @dx.op.waveReadLaneAt.f32(i32 117, float %expr, i32 %idx)
15+
%ret = call float @llvm.dx.wave.read.lane.at(float %expr, i32 %idx)
16+
ret float %ret
17+
}
18+
19+
define noundef double @wave_rla_double(double noundef %expr, i32 noundef %idx) #0 {
20+
entry:
21+
; CHECK: call double @dx.op.waveReadLaneAt.f64(i32 117, double %expr, i32 %idx)
22+
%ret = call double @llvm.dx.wave.read.lane.at(double %expr, i32 %idx)
23+
ret double %ret
24+
}
25+
26+
define noundef i1 @wave_rla_i1(i1 noundef %expr, i32 noundef %idx) #0 {
27+
entry:
28+
; CHECK: call i1 @dx.op.waveReadLaneAt.i1(i32 117, i1 %expr, i32 %idx)
29+
%ret = call i1 @llvm.dx.wave.read.lane.at.i1(i1 %expr, i32 %idx)
30+
ret i1 %ret
31+
}
32+
33+
define noundef i16 @wave_rla_i16(i16 noundef %expr, i32 noundef %idx) #0 {
34+
entry:
35+
; CHECK: call i16 @dx.op.waveReadLaneAt.i16(i32 117, i16 %expr, i32 %idx)
36+
%ret = call i16 @llvm.dx.wave.read.lane.at.i16(i16 %expr, i32 %idx)
37+
ret i16 %ret
38+
}
39+
40+
define noundef i32 @wave_rla_i32(i32 noundef %expr, i32 noundef %idx) #0 {
41+
entry:
42+
; CHECK: call i32 @dx.op.waveReadLaneAt.i32(i32 117, i32 %expr, i32 %idx)
43+
%ret = call i32 @llvm.dx.wave.read.lane.at.i32(i32 %expr, i32 %idx)
44+
ret i32 %ret
45+
}
46+
47+
declare half @llvm.dx.wave.read.lane.at.f16(half, i32) #1
48+
declare float @llvm.dx.wave.read.lane.at.f32(float, i32) #1
49+
declare double @llvm.dx.wave.read.lane.at.f64(double, i32) #1
50+
51+
declare i1 @llvm.dx.wave.read.lane.at.i1(i1, i32) #1
52+
declare i16 @llvm.dx.wave.read.lane.at.i16(i16, i32) #1
53+
declare i32 @llvm.dx.wave.read.lane.at.i32(i32, i32) #1
54+
55+
attributes #0 = { norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
56+
attributes #1 = { nocallback nofree nosync nounwind willreturn }

0 commit comments

Comments
 (0)