| 1 |
; REQUIRES: spirv-as |
| 2 |
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s |
| 3 |
|
| 4 |
; RUN: llvm-spirv -spec-const-info %t.spv | FileCheck %s --check-prefix=CHECK-INFO |
| 5 |
; CHECK-INFO: Number of scalar specialization constants in the module = 11 |
| 6 |
; CHECK-INFO: Spec const id = 101, size in bytes = 1, type = i8 |
| 7 |
; CHECK-INFO: Spec const id = 102, size in bytes = 2, type = i16 |
| 8 |
; CHECK-INFO: Spec const id = 103, size in bytes = 4, type = i32 |
| 9 |
; CHECK-INFO: Spec const id = 104, size in bytes = 8, type = i64 |
| 10 |
; CHECK-INFO: Spec const id = 105, size in bytes = 1, type = i8 |
| 11 |
; CHECK-INFO: Spec const id = 106, size in bytes = 1, type = i1 |
| 12 |
; CHECK-INFO: Spec const id = 107, size in bytes = 1, type = i1 |
| 13 |
; CHECK-INFO: Spec const id = 108, size in bytes = 2, type = f16 |
| 14 |
; CHECK-INFO: Spec const id = 109, size in bytes = 4, type = f32 |
| 15 |
; CHECK-INFO: Spec const id = 110, size in bytes = 8, type = f64 |
| 16 |
; CHECK-INFO: Spec const id = 111, size in bytes = 8, type = f64 |
| 17 |
|
| 18 |
; Negative tests for the command line option. |
| 19 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "1234" 2>&1 | FileCheck %s --check-prefix=CHECK-FORMAT |
| 20 |
; CHECK-FORMAT: Invalid format of -spec-const option: "1234". Expected format: -spec-const "<id1:type1:value1 id2:type2:value2 ...>" |
| 21 |
|
| 22 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "q:i32:4" 2>&1 | FileCheck %s --check-prefix=CHECK-ID |
| 23 |
; CHECK-ID: Invalid id for '-spec-const' option! In "q:i32:4": "q" must be a 32-bit unsigned integer |
| 24 |
|
| 25 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "10:i32:1024" 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-ID |
| 26 |
; CHECK-INVALID-ID: CL_INVALID_SPEC_ID. "10:i32:1024": There is no specialization constant with id = 10 in the SPIR-V module. |
| 27 |
|
| 28 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "101:32:99" 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE |
| 29 |
; CHECK-TYPE: Invalid type for '-spec-const' option! In "101:32:99": "32" - is not allowed type. Allowed types are: i1, i8, i16, i32, i64, f16, f32, f64 |
| 30 |
|
| 31 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "101:i9:99" 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE-INT |
| 32 |
; CHECK-TYPE-INT: Invalid type for '-spec-const' option! In "101:i9:99": "i9" - is not allowed type. Allowed types are: i1, i8, i16, i32, i64, f16, f32, f64 |
| 33 |
|
| 34 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "101:f8:99" 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE-FP |
| 35 |
; CHECK-TYPE-FP: Invalid type for '-spec-const' option! In "101:f8:99": "f8" - is not allowed type. Allowed types are: i1, i8, i16, i32, i64, f16, f32, f64 |
| 36 |
|
| 37 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "101:i8:257" 2>&1 | FileCheck %s --check-prefix=CHECK-VALUE-INT |
| 38 |
; CHECK-VALUE-INT: Invalid value for '-spec-const' option! In "101:i8:257": can't convert "257" to 8-bit integer number |
| 39 |
|
| 40 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "101:f32:4.40282347E+38" 2>&1 | FileCheck %s --check-prefix=CHECK-VALUE-FP |
| 41 |
; CHECK-VALUE-FP: Invalid value for '-spec-const' option! In "101:f32:4.40282347E+38": can't convert "4.40282347E+38" to 32-bit floating point number |
| 42 |
|
| 43 |
; RUN: not llvm-spirv -r -emit-opaque-pointers %t.spv -spec-const "101:i32:1024" 2>&1 | FileCheck %s --check-prefix=CHECK-VALUE |
| 44 |
; CHECK-VALUE: CL_INVALID_VALUE. In "101:i32:1024": Size of type i32 (4 bytes) does not match the size of the specialization constant in the module (1 bytes) |
| 45 |
|
| 46 |
; RUN: llvm-spirv -r -emit-opaque-pointers -o - %t.spv | llvm-dis | FileCheck %s --check-prefix=CHECK-DEFAULT |
| 47 |
; RUN: llvm-spirv -r -emit-opaque-pointers -spec-const "101:i8:42 102:i16:22 103:i32:33 104:i64:44 105:i8:0 106:i1:0 107:i1:1 108:f16:5.5 109:f32:6.6 110:f64:7.7 111:f64:8.8 101:i8:11" -o - %t.spv | llvm-dis | FileCheck %s --check-prefix=CHECK-SPEC |
| 48 |
|
| 49 |
; RUN: llvm-spirv -r -emit-opaque-pointers -o - %t.spv | llvm-dis | FileCheck %s --check-prefix=CHECK-DEFAULT |
| 50 |
; RUN: llvm-spirv -r -emit-opaque-pointers -spec-const "108:f16:0x1234 109:f32:0x12345678 110:f64:0x12345678ABCDEF00" -o - %t.spv | llvm-dis | FileCheck %s --check-prefix=CHECK-HEX |
| 51 |
|
| 52 |
; CHECK-DEFAULT: @bt = addrspace(2) constant i1 true, align 1 |
| 53 |
; CHECK-DEFAULT: @bf = addrspace(2) constant i1 false, align 1 |
| 54 |
; CHECK-DEFAULT: @c = addrspace(2) constant i8 97, align 1 |
| 55 |
; CHECK-DEFAULT: @s = addrspace(2) constant i16 1, align 2 |
| 56 |
; CHECK-DEFAULT: @i = addrspace(2) constant i32 2, align 4 |
| 57 |
; CHECK-DEFAULT: @l = addrspace(2) constant i64 3, align 8 |
| 58 |
; CHECK-DEFAULT: @h = addrspace(2) constant half 0xH3800, align 2 |
| 59 |
; CHECK-DEFAULT: @f = addrspace(2) constant float 0x40015C2900000000, align 4 |
| 60 |
; CHECK-DEFAULT: @d = addrspace(2) constant double 3.140000e+00, align 8 |
| 61 |
; CHECK-DEFAULT: @ss = addrspace(1) global %struct.S { i8 98, double 6.280000e+00 }, align 8 |
| 62 |
|
| 63 |
; CHECK-SPEC: @bt = addrspace(2) constant i1 false, align 1 |
| 64 |
; CHECK-SPEC: @bf = addrspace(2) constant i1 true, align 1 |
| 65 |
; CHECK-SPEC: @c = addrspace(2) constant i8 11, align 1 |
| 66 |
; CHECK-SPEC: @s = addrspace(2) constant i16 22, align 2 |
| 67 |
; CHECK-SPEC: @i = addrspace(2) constant i32 33, align 4 |
| 68 |
; CHECK-SPEC: @l = addrspace(2) constant i64 44, align 8 |
| 69 |
; CHECK-SPEC: @h = addrspace(2) constant half 0xH4580, align 2 |
| 70 |
; CHECK-SPEC: @f = addrspace(2) constant float 0x401A666660000000, align 4 |
| 71 |
; CHECK-SPEC: @d = addrspace(2) constant double 7.700000e+00, align 8 |
| 72 |
; CHECK-SPEC: @ss = addrspace(1) global %struct.S { i8 0, double 8.800000e+00 }, align 8 |
| 73 |
|
| 74 |
; CHECK-HEX: @h = addrspace(2) constant half 0xH1234, align 2 |
| 75 |
; Float literals are represented as doubles, so 0x12345678 becomes the value below. |
| 76 |
; CHECK-HEX: @f = addrspace(2) constant float 0x3A468ACF00000000, align 4 |
| 77 |
; CHECK-HEX: @d = addrspace(2) constant double 0x12345678ABCDEF00, align 8 |
| 78 |
|
| 79 |
; SPIR-V |
| 80 |
; Version: 1.0 |
| 81 |
; Generator: Khronos LLVM/SPIR-V Translator; 14 |
| 82 |
; Bound: 47 |
| 83 |
; Schema: 0 |
| 84 |
OpCapability Addresses |
| 85 |
OpCapability Linkage |
| 86 |
OpCapability Kernel |
| 87 |
OpCapability Float16Buffer |
| 88 |
OpCapability Float64 |
| 89 |
OpCapability Int64 |
| 90 |
OpCapability Int16 |
| 91 |
OpCapability Int8 |
| 92 |
%1 = OpExtInstImport "OpenCL.std" |
| 93 |
OpMemoryModel Physical64 OpenCL |
| 94 |
OpSource OpenCL_C 200000 |
| 95 |
OpName %bt "bt" |
| 96 |
OpName %bf "bf" |
| 97 |
OpName %c "c" |
| 98 |
OpName %s "s" |
| 99 |
OpName %i "i" |
| 100 |
OpName %l "l" |
| 101 |
OpName %h "h" |
| 102 |
OpName %f "f" |
| 103 |
OpName %d "d" |
| 104 |
OpName %struct_S "struct.S" |
| 105 |
OpName %ss "ss" |
| 106 |
OpDecorate %uchar_97 SpecId 101 |
| 107 |
OpDecorate %ushort_1 SpecId 102 |
| 108 |
OpDecorate %uint_2 SpecId 103 |
| 109 |
OpDecorate %ulong_3 SpecId 104 |
| 110 |
OpDecorate %uchar_98 SpecId 105 |
| 111 |
OpDecorate %true SpecId 106 |
| 112 |
OpDecorate %false SpecId 107 |
| 113 |
OpDecorate %half_0x1pn1 SpecId 108 |
| 114 |
OpDecorate %float_2_17000008 SpecId 109 |
| 115 |
OpDecorate %double_3_1400000000000001 SpecId 110 |
| 116 |
OpDecorate %double_6_2800000000000002 SpecId 111 |
| 117 |
OpDecorate %42 Constant |
| 118 |
%42 = OpDecorationGroup |
| 119 |
OpDecorate %43 Alignment 1 |
| 120 |
%43 = OpDecorationGroup |
| 121 |
OpDecorate %44 Alignment 2 |
| 122 |
%44 = OpDecorationGroup |
| 123 |
OpDecorate %45 Alignment 4 |
| 124 |
%45 = OpDecorationGroup |
| 125 |
OpDecorate %46 Alignment 8 |
| 126 |
%46 = OpDecorationGroup |
| 127 |
OpDecorate %c LinkageAttributes "c" Export |
| 128 |
OpDecorate %d LinkageAttributes "d" Export |
| 129 |
OpDecorate %f LinkageAttributes "f" Export |
| 130 |
OpDecorate %h LinkageAttributes "h" Export |
| 131 |
OpDecorate %i LinkageAttributes "i" Export |
| 132 |
OpDecorate %l LinkageAttributes "l" Export |
| 133 |
OpDecorate %s LinkageAttributes "s" Export |
| 134 |
OpDecorate %bf LinkageAttributes "bf" Export |
| 135 |
OpDecorate %ss LinkageAttributes "ss" Export |
| 136 |
OpDecorate %bt LinkageAttributes "bt" Export |
| 137 |
OpGroupDecorate %42 %bt %bf %c %s %i %l %h %f %d |
| 138 |
OpGroupDecorate %43 %bt %bf %c |
| 139 |
OpGroupDecorate %44 %s %h |
| 140 |
OpGroupDecorate %45 %i %f |
| 141 |
OpGroupDecorate %46 %l %d %ss |
| 142 |
%uchar = OpTypeInt 8 0 |
| 143 |
%ushort = OpTypeInt 16 0 |
| 144 |
%uint = OpTypeInt 32 0 |
| 145 |
%ulong = OpTypeInt 64 0 |
| 146 |
%uchar_97 = OpSpecConstant %uchar 97 |
| 147 |
%ushort_1 = OpSpecConstant %ushort 1 |
| 148 |
%uint_2 = OpSpecConstant %uint 2 |
| 149 |
%ulong_3 = OpSpecConstant %ulong 3 |
| 150 |
%uchar_98 = OpSpecConstant %uchar 98 |
| 151 |
%bool = OpTypeBool |
| 152 |
%_ptr_UniformConstant_bool = OpTypePointer UniformConstant %bool |
| 153 |
%_ptr_UniformConstant_uchar = OpTypePointer UniformConstant %uchar |
| 154 |
%_ptr_UniformConstant_ushort = OpTypePointer UniformConstant %ushort |
| 155 |
%_ptr_UniformConstant_uint = OpTypePointer UniformConstant %uint |
| 156 |
%_ptr_UniformConstant_ulong = OpTypePointer UniformConstant %ulong |
| 157 |
%half = OpTypeFloat 16 |
| 158 |
%_ptr_UniformConstant_half = OpTypePointer UniformConstant %half |
| 159 |
%float = OpTypeFloat 32 |
| 160 |
%_ptr_UniformConstant_float = OpTypePointer UniformConstant %float |
| 161 |
%double = OpTypeFloat 64 |
| 162 |
%_ptr_UniformConstant_double = OpTypePointer UniformConstant %double |
| 163 |
%struct_S = OpTypeStruct %uchar %double |
| 164 |
%_ptr_CrossWorkgroup_struct_S = OpTypePointer CrossWorkgroup %struct_S |
| 165 |
%true = OpSpecConstantTrue %bool |
| 166 |
%bt = OpVariable %_ptr_UniformConstant_bool UniformConstant %true |
| 167 |
%false = OpSpecConstantFalse %bool |
| 168 |
%bf = OpVariable %_ptr_UniformConstant_bool UniformConstant %false |
| 169 |
%c = OpVariable %_ptr_UniformConstant_uchar UniformConstant %uchar_97 |
| 170 |
%s = OpVariable %_ptr_UniformConstant_ushort UniformConstant %ushort_1 |
| 171 |
%i = OpVariable %_ptr_UniformConstant_uint UniformConstant %uint_2 |
| 172 |
%l = OpVariable %_ptr_UniformConstant_ulong UniformConstant %ulong_3 |
| 173 |
%half_0x1pn1 = OpSpecConstant %half 0x1p-1 |
| 174 |
%h = OpVariable %_ptr_UniformConstant_half UniformConstant %half_0x1pn1 |
| 175 |
%float_2_17000008 = OpSpecConstant %float 2.17000008 |
| 176 |
%f = OpVariable %_ptr_UniformConstant_float UniformConstant %float_2_17000008 |
| 177 |
%double_3_1400000000000001 = OpSpecConstant %double 3.1400000000000001 |
| 178 |
%d = OpVariable %_ptr_UniformConstant_double UniformConstant %double_3_1400000000000001 |
| 179 |
%double_6_2800000000000002 = OpSpecConstant %double 6.2800000000000002 |
| 180 |
%39 = OpSpecConstantComposite %struct_S %uchar_98 %double_6_2800000000000002 |
| 181 |
%ss = OpVariable %_ptr_CrossWorkgroup_struct_S CrossWorkgroup %39 |