xref: /llvm-project/llvm/test/CodeGen/SPIRV/struct.ll (revision 6c6f8b1acde862b176d38ede0a6d8ab649890a3c)
1; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2
3%struct.ST = type { i32, i32, i32 }
4
5; CHECK-DAG: OpName %[[#struct:]] "struct.ST"
6; CHECK-DAG: %[[#int:]] = OpTypeInt 32 0
7; CHECK-DAG: %[[#struct]] = OpTypeStruct %[[#int]] %[[#int]] %[[#int]]
8; CHECK-DAG: %[[#structP:]] = OpTypePointer Function %[[#struct]]
9; CHECK-DAG: %[[#intP:]] = OpTypePointer Function %[[#int]]
10; CHECK-DAG: %[[#zero:]] = OpConstant %[[#int]] 0
11; CHECK-DAG: %[[#one:]] = OpConstant %[[#int]] 1
12; CHECK-DAG: %[[#two:]] = OpConstant %[[#int]] 2
13; CHECK-DAG: %[[#three:]] = OpConstant %[[#int]] 3
14
15define dso_local spir_func i32 @func() {
16entry:
17; CHECK-SPIRV: %[[#st:]] = OpVariable %[[#structP]]
18  %st = alloca %struct.ST, align 4
19; CHECK-SPIRV: %[[#a:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#zero]]
20; CHECK-SPIRV: OpStore %[[#a]] %[[#one]]
21  %a = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 0
22  store i32 1, i32* %a, align 4
23; CHECK-SPIRV: %[[#b:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#one]]
24; CHECK-SPIRV: OpStore %[[#b]] %[[#two]]
25  %b = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 1
26  store i32 2, i32* %b, align 4
27; CHECK-SPIRV: %[[#c:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#two]]
28; CHECK-SPIRV: OpStore %[[#c]] %[[#three]]
29  %c = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 2
30  store i32 3, i32* %c, align 4
31; CHECK-SPIRV: %[[#a1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#zero]]
32; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#a1]]
33  %a1 = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 0
34  %0 = load i32, i32* %a1, align 4
35; CHECK-SPIRV: %[[#b1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#one]]
36; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#b1]]
37  %b2 = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 1
38  %1 = load i32, i32* %b2, align 4
39  %add = add nsw i32 %0, %1
40; CHECK-SPIRV: %[[#c1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#two]]
41; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#c1]]
42  %c3 = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 2
43  %2 = load i32, i32* %c3, align 4
44  %add4 = add nsw i32 %add, %2
45  ret i32 %add4
46}
47