xref: /llvm-project/llvm/test/CodeGen/SPIRV/hlsl-resources/BufferLoadStore.ll (revision 4b692a95d103f3ad30d6be1ce6d5dda0bd90bc1f)
1; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-library %s -o - | FileCheck %s
2; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-library %s -o - -filetype=obj | spirv-val %}
3
4; CHECK-DAG: [[float:%[0-9]+]] = OpTypeFloat 32
5; CHECK-DAG: [[v4float:%[0-9]+]] = OpTypeVector [[float]] 4
6; CHECK-DAG: [[int:%[0-9]+]] = OpTypeInt 32 0
7; CHECK-DAG: [[zero:%[0-9]+]] = OpConstant [[int]] 0
8; CHECK-DAG: [[one:%[0-9]+]] = OpConstant [[int]] 1
9; CHECK-DAG: [[twenty:%[0-9]+]] = OpConstant [[int]] 20
10; CHECK-DAG: [[twenty_three:%[0-9]+]] = OpConstant [[int]] 23
11; CHECK-DAG: [[ImageType:%[0-9]+]] = OpTypeImage [[float]] Buffer 2 0 0 2 Rgba32f
12; CHECK-DAG: [[ImagePtr:%[0-9]+]] = OpTypePointer UniformConstant [[ImageType]]
13; CHECK: [[Var:%[0-9]+]] = OpVariable [[ImagePtr]] UniformConstant
14
15; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none)
16define void @main() local_unnamed_addr #0 {
17entry:
18; CHECK: [[H:%[0-9]+]] = OpLoad [[ImageType]] [[Var]]
19  %s_h.i = tail call target("spirv.Image", float, 5, 2, 0, 0, 2, 1) @llvm.spv.resource.handlefrombinding.tspirv.Image_f32_5_2_0_0_2_0t(i32 3, i32 5, i32 1, i32 0, i1 false)
20
21; CHECK: [[R:%[0-9]+]] = OpImageRead [[v4float]] [[H]] [[one]]
22; CHECK: [[V:%[0-9]+]] = OpCompositeExtract [[float]] [[R]] 0
23  %0 = tail call noundef nonnull align 4 dereferenceable(4) ptr @llvm.spv.resource.getpointer.p0.tspirv.Image_f32_5_2_0_0_2_0t(target("spirv.Image", float, 5, 2, 0, 0, 2, 1) %s_h.i, i32 1)
24  %1 = load float, ptr %0, align 4
25; CHECK: OpBranch [[bb_store:%[0-9]+]]
26  br label %bb_store
27
28; CHECK: [[bb_store]] = OpLabel
29bb_store:
30
31; CHECK: [[H:%[0-9]+]] = OpLoad [[ImageType]] [[Var]]
32; CHECK: OpImageWrite [[H]] [[zero]] [[V]]
33  %2 = tail call noundef nonnull align 4 dereferenceable(4) ptr @llvm.spv.resource.getpointer.p0.tspirv.Image_f32_5_2_0_0_2_0t(target("spirv.Image", float, 5, 2, 0, 0, 2, 1) %s_h.i, i32 0)
34  store float %1, ptr %2, align 4
35; CHECK: OpBranch [[bb_both:%[0-9]+]]
36  br label %bb_both
37
38; CHECK: [[bb_both]] = OpLabel
39bb_both:
40; CHECK: [[H:%[0-9]+]] = OpLoad [[ImageType]] [[Var]]
41; CHECK: [[R:%[0-9]+]] = OpImageRead [[v4float]] [[H]] [[twenty_three]]
42; CHECK: [[V:%[0-9]+]] = OpCompositeExtract [[float]] [[R]] 0
43  %3 = tail call noundef nonnull align 4 dereferenceable(4) ptr @llvm.spv.resource.getpointer.p0.tspirv.Image_f32_5_2_0_0_2_0t(target("spirv.Image", float, 5, 2, 0, 0, 2, 1) %s_h.i, i32 23)
44  %4 = load float, ptr %3, align 4
45
46; CHECK: [[H:%[0-9]+]] = OpLoad [[ImageType]] [[Var]]
47; CHECK: OpImageWrite [[H]] [[twenty]] [[V]]
48  %5 = tail call noundef nonnull align 4 dereferenceable(4) ptr @llvm.spv.resource.getpointer.p0.tspirv.Image_f32_5_2_0_0_2_0t(target("spirv.Image", float, 5, 2, 0, 0, 2, 1) %s_h.i, i32 20)
49  store float %4, ptr %5, align 4
50  ret void
51}
52
53; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none)
54declare ptr @llvm.spv.resource.getpointer.p0.tspirv.Image_f32_5_2_0_0_2_0t(target("spirv.Image", float, 5, 2, 0, 0, 2, 1), i32) #1
55
56; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none)
57declare target("spirv.Image", float, 5, 2, 0, 0, 2, 1) @llvm.spv.resource.handlefrombinding.tspirv.Image_f32_5_2_0_0_2_0t(i32, i32, i32, i32, i1) #1
58
59attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
60attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(none) }
61