blob: 54b807e1e0d11e564621e7d7a62b2bd94cce21bf [file] [edit]
; RUN: not opt -S -dxil-resource-type -dxil-resource-access -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s
; Ensure that a cyclic loop of resource ptrs reports a fatal error and exits
; compilation, rather than hanging or crashing later on the illegal access.
;
; This might be generated by something like:
;
; RWBuffer<float> bufA : register(u0);
; RWBuffer<float> bufB : register(u1);
; ...
; for (int i = 0; i < N; ++i) {
; dst[tid] = src[tid] * 0.5f;
; RWBuffer<float> tmp = src; src = dst; dst = tmp;
; }
; CHECK: LLVM ERROR: Resource access is not guaranteed to map to a unique global resource
@.str = private unnamed_addr constant [5 x i8] c"bufA\00", align 1
@.str.2 = private unnamed_addr constant [5 x i8] c"bufB\00", align 1
define void @main(i32 %tid, i32 %n) {
entry:
%0 = tail call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0_0t(i32 0, i32 0, i32 1, i32 0, ptr nonnull @.str)
%1 = tail call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0_0t(i32 0, i32 1, i32 1, i32 0, ptr nonnull @.str.2)
br label %for.cond
for.cond:
%dst = phi target("dx.TypedBuffer", float, 1, 0, 0) [ %1, %entry ], [ %src, %for.body ]
%src = phi target("dx.TypedBuffer", float, 1, 0, 0) [ %0, %entry ], [ %dst, %for.body ]
%i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%exit = icmp eq i32 %i, %n
br i1 %exit, label %end, label %for.body
for.body:
%srcptr = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.TypedBuffer_f32_1_0_0t(target("dx.TypedBuffer", float, 1, 0, 0) %src, i32 %tid)
%v = load float, ptr %srcptr, align 4
%mul = fmul float %v, 5.000000e-01
%dstptr = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.TypedBuffer_f32_1_0_0t(target("dx.TypedBuffer", float, 1, 0, 0) %dst, i32 %tid)
store float %mul, ptr %dstptr, align 4
%inc = add nuw i32 %i, 1
br label %for.cond
end:
ret void
}