33target 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
78declare i32 @some_val ();
89
910define 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
0 commit comments