1 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3 ; TODO(#60133): Requires updates following opaque pointer migration.
6 ;; Check 'LLVM ==> SPIR-V' conversion of extractvalue/insertvalue.
8 %struct.arr = type { [7 x float] }
9 %struct.st = type { %struct.inner }
10 %struct.inner = type { float }
12 ; CHECK-SPIRV: %[[#float_ty:]] = OpTypeFloat 32
13 ; CHECK-SPIRV: %[[#int_ty:]] = OpTypeInt 32
14 ; CHECK-SPIRV: %[[#arr_size:]] = OpConstant %[[#int_ty]] 7
15 ; CHECK-SPIRV: %[[#array_ty:]] = OpTypeArray %[[#float_ty]] %[[#arr_size]]
16 ; CHECK-SPIRV: %[[#struct_ty:]] = OpTypeStruct %[[#array_ty]]
17 ; CHECK-SPIRV: %[[#struct_ptr_ty:]] = OpTypePointer CrossWorkgroup %[[#struct_ty]]
18 ; CHECK-SPIRV: %[[#array_ptr_ty:]] = OpTypePointer CrossWorkgroup %[[#array_ty]]
19 ; CHECK-SPIRV: %[[#struct1_in_ty:]] = OpTypeStruct %[[#float_ty]]
20 ; CHECK-SPIRV: %[[#struct1_ty:]] = OpTypeStruct %[[#struct1_in_ty]]
21 ; CHECK-SPIRV: %[[#struct1_ptr_ty:]] = OpTypePointer CrossWorkgroup %[[#struct1_ty]]
22 ; CHECK-SPIRV: %[[#struct1_in_ptr_ty:]] = OpTypePointer CrossWorkgroup %[[#struct1_in_ty]]
23 ; CHECK-SPIRV-NOT: OpConstant %{{.*}} 2
24 ; CHECK-SPIRV-NOT: OpConstant %{{.*}} 4
25 ; CHECK-SPIRV-NOT: OpConstant %{{.*}} 5
27 ; CHECK-SPIRV-LABEL: OpFunction
28 ; CHECK-SPIRV-NEXT: %[[#object:]] = OpFunctionParameter %[[#struct_ptr_ty]]
29 ; CHECK-SPIRV: %[[#store_ptr:]] = OpInBoundsPtrAccessChain %[[#array_ptr_ty]] %[[#object]] %[[#]] %[[#]]
30 ; CHECK-SPIRV: %[[#extracted_array:]] = OpLoad %[[#array_ty]] %[[#store_ptr]] Aligned 4
31 ; CHECK-SPIRV: %[[#elem_4:]] = OpCompositeExtract %[[#float_ty]] %[[#extracted_array]] 4
32 ; CHECK-SPIRV: %[[#elem_2:]] = OpCompositeExtract %[[#float_ty]] %[[#extracted_array]] 2
33 ; CHECK-SPIRV: %[[#add:]] = OpFAdd %[[#float_ty]] %[[#elem_4]] %[[#elem_2]]
34 ; CHECK-SPIRV: %[[#inserted_array:]] = OpCompositeInsert %[[#array_ty]] %[[#add]] %[[#extracted_array]] 5
35 ; CHECK-SPIRV: OpStore %[[#store_ptr]] %[[#inserted_array]]
36 ; CHECK-SPIRV-LABEL: OpFunctionEnd
38 define spir_func void @array_test(%struct.arr addrspace(1)* %object) {
40 %0 = getelementptr inbounds %struct.arr, %struct.arr addrspace(1)* %object, i32 0, i32 0
41 %1 = load [7 x float], [7 x float] addrspace(1)* %0, align 4
42 %2 = extractvalue [7 x float] %1, 4
43 %3 = extractvalue [7 x float] %1, 2
44 %4 = fadd float %2, %3
45 %5 = insertvalue [7 x float] %1, float %4, 5
46 store [7 x float] %5, [7 x float] addrspace(1)* %0
50 ; CHECK-SPIRV-LABEL: OpFunction
51 ; CHECK-SPIRV-NEXT: %[[#object:]] = OpFunctionParameter %[[#struct1_ptr_ty]]
52 ; CHECK-SPIRV: %[[#store1_ptr:]] = OpInBoundsPtrAccessChain %[[#struct1_in_ptr_ty]] %[[#object]] %[[#]] %[[#]]
53 ; CHECK-SPIRV: %[[#extracted_struct:]] = OpLoad %[[#struct1_in_ty]] %[[#store1_ptr]] Aligned 4
54 ; CHECK-SPIRV: %[[#elem:]] = OpCompositeExtract %[[#float_ty]] %[[#extracted_struct]] 0
55 ; CHECK-SPIRV: %[[#add:]] = OpFAdd %[[#float_ty]] %[[#elem]] %[[#]]
56 ; CHECK-SPIRV: %[[#inserted_struct:]] = OpCompositeInsert %[[#struct1_in_ty]] %[[#add]] %[[#extracted_struct]] 0
57 ; CHECK-SPIRV: OpStore %[[#store1_ptr]] %[[#inserted_struct]]
58 ; CHECK-SPIRV-LABEL: OpFunctionEnd
60 define spir_func void @struct_test(%struct.st addrspace(1)* %object) {
62 %0 = getelementptr inbounds %struct.st, %struct.st addrspace(1)* %object, i32 0, i32 0
63 %1 = load %struct.inner, %struct.inner addrspace(1)* %0, align 4
64 %2 = extractvalue %struct.inner %1, 0
65 %3 = fadd float %2, 1.000000e+00
66 %4 = insertvalue %struct.inner %1, float %3, 0
67 store %struct.inner %4, %struct.inner addrspace(1)* %0