Skip to content

Commit f7c6c7c

Browse files
authored
[DirectX] Overlapping binding detection - check register space first (llvm#152250)
The code that checks for overlapping binding did not compare register space when one of the bindings was for an unbounded resource array, leading to false errors. This change fixes it.
1 parent 2ff44d7 commit f7c6c7c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,11 @@ class ResourceInfo {
360360
std::tie(RHS.RecordID, RHS.Space, RHS.LowerBound, RHS.Size);
361361
}
362362
bool overlapsWith(const ResourceBinding &RHS) const {
363+
if (Space != RHS.Space)
364+
return false;
363365
if (Size == UINT32_MAX)
364366
return LowerBound < RHS.LowerBound;
365-
return Space == RHS.Space && LowerBound + Size - 1 >= RHS.LowerBound;
367+
return LowerBound + Size - 1 >= RHS.LowerBound;
366368
}
367369
};
368370

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; Use llc for this test so that we don't abort after the first error.
2+
; RUN: not llc %s -o /dev/null 2>&1 | FileCheck %s
3+
4+
; Check that there is no overlap with unbounded array in different space
5+
6+
; Buffer<double> A[2] : register(t2, space4);
7+
; Buffer<double> B : register(t20, space5); // does not overlap
8+
; Buffer<double> C[] : register(t2, space4); // overlaps with A
9+
10+
; CHECK: error: resource A at register 2 overlaps with resource C at register 2 in space 4
11+
; CHECK-NOT: error: resource C at register 2 overlaps with resource B at register 20 in space 5
12+
13+
target triple = "dxil-pc-shadermodel6.3-library"
14+
15+
@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1
16+
@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
17+
@C.str = private unnamed_addr constant [2 x i8] c"C\00", align 1
18+
19+
define void @test_not_overlapping_in_different_spaces() {
20+
entry:
21+
22+
; Buffer<double> A[2] : register(t2, space4);
23+
%h0 = call target("dx.TypedBuffer", double, 0, 0, 0)
24+
@llvm.dx.resource.handlefrombinding(i32 4, i32 2, i32 2, i32 10, i1 false, ptr @A.str)
25+
26+
; Buffer<double> B : register(t20, space5);
27+
%h1 = call target("dx.TypedBuffer", i64, 0, 0, 0)
28+
@llvm.dx.resource.handlefrombinding(i32 5, i32 20, i32 1, i32 0, i1 false, ptr @B.str)
29+
30+
; Buffer<double> C[] : register(t2, space4);
31+
%h2 = call target("dx.TypedBuffer", double, 0, 0, 0)
32+
@llvm.dx.resource.handlefrombinding(i32 4, i32 2, i32 -1, i32 10, i1 false, ptr @C.str)
33+
34+
ret void
35+
}

0 commit comments

Comments
 (0)