Skip to content

Commit d8329ec

Browse files
committed
Add more test
Add tests for NonUniformResourceIndex on: - value that goes through store & load - handle initialization of a single resource - value not related to resources
1 parent 987b9e1 commit d8329ec

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

llvm/test/CodeGen/DirectX/CreateHandle-NURI.ll

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
target triple = "dxil-pc-shadermodel6.0-compute"
44

55
@A.str = internal unnamed_addr constant [2 x i8] c"A\00", align 1
6+
@B.str = internal unnamed_addr constant [2 x i8] c"A\00", align 1
67

78
declare i32 @some_val();
89

910
define void @test_buffers_with_nuri() {
1011

1112
%val = call i32 @some_val()
13+
%foo = alloca i32, align 4
1214

1315
; RWBuffer<float> A[10];
1416
;
1517
; A[NonUniformResourceIndex(val)];
1618

1719
%nuri1 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
18-
%res1 = call target("dx.TypedBuffer", float, 1, 0, 0)
20+
%res1 = call target("dx.TypedBuffer", float, 1, 0, 0)
1921
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 %nuri1, ptr @A.str)
2022
; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 %val, i1 true) #[[ATTR:.*]]
2123
; CHECK-NOT: @llvm.dx.cast.handle
@@ -25,7 +27,7 @@ define void @test_buffers_with_nuri() {
2527
%add1 = add i32 %val, 1
2628
%nuri2 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %add1)
2729
%rem1 = urem i32 %nuri2, 10
28-
%res2 = call target("dx.TypedBuffer", float, 1, 0, 0)
30+
%res2 = call target("dx.TypedBuffer", float, 1, 0, 0)
2931
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 %rem1, ptr @A.str)
3032
; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 %rem1, i1 true) #[[ATTR]]
3133

@@ -36,6 +38,30 @@ define void @test_buffers_with_nuri() {
3638
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 %add2, ptr @A.str)
3739
; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 %add2, i1 true) #[[ATTR]]
3840

41+
; NonUniformResourceIndex value going through store & load - the flag is not going to get picked up:
42+
%a = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
43+
store i32 %a, ptr %foo
44+
%b = load i32, ptr %foo
45+
%res4 = call target("dx.TypedBuffer", float, 1, 0, 0)
46+
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 %b, ptr @A.str)
47+
; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 %b, i1 false) #[[ATTR]]
48+
49+
; NonUniformResourceIndex index value on a single resouce (not an array) - the flag is not going to get picked up:
50+
;
51+
; RWBuffer<float> B : register(u20);
52+
; B[NonUniformResourceIndex(val)];
53+
%nuri3 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
54+
%res5 = call target("dx.TypedBuffer", float, 1, 0, 0)
55+
@llvm.dx.resource.handlefrombinding(i32 20, i32 0, i32 1, i32 %nuri1, ptr @B.str)
56+
; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 1, i32 %val, i1 false) #[[ATTR]]
57+
58+
; NonUniformResourceIndex on unrelated value - the call is removed:
59+
; foo = NonUniformResourceIndex(val);
60+
%nuri4 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
61+
store i32 %nuri4, ptr %foo
62+
; CHECK: store i32 %val, ptr %foo
63+
; CHECK-NOT: @llvm.dx.resource.nonuniformindex
64+
3965
ret void
4066
}
4167

llvm/test/CodeGen/DirectX/CreateHandleFromBinding-NURI.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
target triple = "dxil-pc-shadermodel6.6-compute"
44

55
@A.str = internal unnamed_addr constant [2 x i8] c"A\00", align 1
6+
@B.str = internal unnamed_addr constant [2 x i8] c"A\00", align 1
67

78
declare i32 @some_val();
89

910
define void @test_buffers_with_nuri() {
1011

1112
%val = call i32 @some_val()
13+
%foo = alloca i32, align 4
1214

1315
; RWBuffer<float> A[10];
1416
;
@@ -39,6 +41,35 @@ define void @test_buffers_with_nuri() {
3941
; CHECK: %[[RES3:.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 9, i32 0, i8 1 }, i32 %add2, i1 true) #[[ATTR]]
4042
; CHECK: %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %[[RES3]], %dx.types.ResourceProperties { i32 4106, i32 265 }) #[[ATTR]]
4143
ret void
44+
45+
; NonUniformResourceIndex value going through store & load: the flag is not going to get picked up
46+
%a = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
47+
store i32 %a, ptr %foo
48+
%b = load i32, ptr %foo
49+
%res4 = call target("dx.TypedBuffer", float, 1, 0, 0)
50+
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 %b, ptr @A.str)
51+
; CHECK: %[[RES4:.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 9, i32 0, i8 1 }, i32 %b, i1 false) #[[ATTR]]
52+
; CHECK: %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %[[RES4]], %dx.types.ResourceProperties { i32 4106, i32 265 }) #[[ATTR]]
53+
54+
; NonUniformResourceIndex index value on a single resouce (not an array): the flag is not going to get picked up
55+
; RWBuffer<float> B : register(u20);
56+
;
57+
; B[NonUniformResourceIndex(val)];
58+
59+
%nuri3 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
60+
%res5 = call target("dx.TypedBuffer", float, 1, 0, 0)
61+
@llvm.dx.resource.handlefrombinding(i32 20, i32 0, i32 1, i32 %nuri1, ptr @B.str)
62+
; CHECK: %[[RES4:.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 20, i8 1 }, i32 %val, i1 false) #[[ATTR]]
63+
; CHECK: %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %[[RES4]], %dx.types.ResourceProperties { i32 4106, i32 265 }) #[[ATTR]]
64+
65+
; NonUniformResourceIndex on unrelated value - the call is removed:
66+
; foo = NonUniformResourceIndex(val);
67+
%nuri4 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
68+
store i32 %nuri4, ptr %foo
69+
; CHECK: store i32 %val, ptr %foo
70+
; CHECK-NOT: @llvm.dx.resource.nonuniformindex
71+
72+
ret void
4273
}
4374

4475
; CHECK: attributes #[[ATTR]] = {{{.*}} memory(none) {{.*}}}

0 commit comments

Comments
 (0)