1 // RUN: mlir-opt -mlir-disable-threading -test-spirv-target-env %s | FileCheck %s
3 // Note: The following tests check that a spv.target_env can properly control
4 // the conversion target and filter unavailable ops during the conversion.
5 // We don't care about the op argument consistency too much; so certain enum
6 // values for enum attributes may not make much sense for the test op.
8 // spv.AtomicCompareExchangeWeak is available from SPIR-V 1.0 to 1.3 under
10 // spv.AtomicCompareExchangeWeak has two memory semantics enum attribute,
11 // whose value, if containing AtomicCounterMemory bit, additionally requires
12 // AtomicStorage capability.
14 // spv.BitReverse is available in all SPIR-V versions under Shader capability.
16 // spv.GroupNonUniformBallot is available starting from SPIR-V 1.3 under
17 // GroupNonUniform capability.
19 // spv.SubgroupBallotKHR is available under in all SPIR-V versions under
20 // SubgroupBallotKHR capability and SPV_KHR_shader_ballot extension.
22 // The GeometryPointSize capability implies the Geometry capability, which
23 // implies the Shader capability.
25 // PhysicalStorageBuffer64 addressing model is available via extension
26 // SPV_EXT_physical_storage_buffer or SPV_KHR_physical_storage_buffer;
27 // both extensions are incorporated into SPIR-V 1.5.
29 // Vulkan memory model is available via extension SPV_KHR_vulkan_memory_model,
30 // which extensions are incorporated into SPIR-V 1.5.
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
36 // CHECK-LABEL: @cmp_exchange_weak_suitable_version_capabilities
37 func @cmp_exchange_weak_suitable_version_capabilities(%ptr: !spv.ptr<i32, Workgroup>, %value: i32, %comparator: i32) -> i32 attributes {
38 spv.target_env = #spv.target_env<#spv.vce<v1.1, [Kernel, AtomicStorage], []>, {}>
40 // CHECK: spv.AtomicCompareExchangeWeak "Workgroup" "AcquireRelease|AtomicCounterMemory" "Acquire"
41 %0 = "test.convert_to_atomic_compare_exchange_weak_op"(%ptr, %value, %comparator): (!spv.ptr<i32, Workgroup>, i32, i32) -> (i32)
45 // CHECK-LABEL: @cmp_exchange_weak_unsupported_version
46 func @cmp_exchange_weak_unsupported_version(%ptr: !spv.ptr<i32, Workgroup>, %value: i32, %comparator: i32) -> i32 attributes {
47 spv.target_env = #spv.target_env<#spv.vce<v1.4, [Kernel, AtomicStorage], []>, {}>
49 // CHECK: test.convert_to_atomic_compare_exchange_weak_op
50 %0 = "test.convert_to_atomic_compare_exchange_weak_op"(%ptr, %value, %comparator): (!spv.ptr<i32, Workgroup>, i32, i32) -> (i32)
54 //===----------------------------------------------------------------------===//
56 //===----------------------------------------------------------------------===//
58 // CHECK-LABEL: @group_non_uniform_ballot_suitable_version
59 func @group_non_uniform_ballot_suitable_version(%predicate: i1) -> vector<4xi32> attributes {
60 spv.target_env = #spv.target_env<#spv.vce<v1.4, [GroupNonUniformBallot], []>, {}>
62 // CHECK: spv.GroupNonUniformBallot "Workgroup"
63 %0 = "test.convert_to_group_non_uniform_ballot_op"(%predicate): (i1) -> (vector<4xi32>)
64 return %0: vector<4xi32>
67 // CHECK-LABEL: @group_non_uniform_ballot_unsupported_version
68 func @group_non_uniform_ballot_unsupported_version(%predicate: i1) -> vector<4xi32> attributes {
69 spv.target_env = #spv.target_env<#spv.vce<v1.1, [GroupNonUniformBallot], []>, {}>
71 // CHECK: test.convert_to_group_non_uniform_ballot_op
72 %0 = "test.convert_to_group_non_uniform_ballot_op"(%predicate): (i1) -> (vector<4xi32>)
73 return %0: vector<4xi32>
76 //===----------------------------------------------------------------------===//
78 //===----------------------------------------------------------------------===//
80 // CHECK-LABEL: @cmp_exchange_weak_missing_capability_kernel
81 func @cmp_exchange_weak_missing_capability_kernel(%ptr: !spv.ptr<i32, Workgroup>, %value: i32, %comparator: i32) -> i32 attributes {
82 spv.target_env = #spv.target_env<#spv.vce<v1.3, [AtomicStorage], []>, {}>
84 // CHECK: test.convert_to_atomic_compare_exchange_weak_op
85 %0 = "test.convert_to_atomic_compare_exchange_weak_op"(%ptr, %value, %comparator): (!spv.ptr<i32, Workgroup>, i32, i32) -> (i32)
89 // CHECK-LABEL: @cmp_exchange_weak_missing_capability_atomic_storage
90 func @cmp_exchange_weak_missing_capability_atomic_storage(%ptr: !spv.ptr<i32, Workgroup>, %value: i32, %comparator: i32) -> i32 attributes {
91 spv.target_env = #spv.target_env<#spv.vce<v1.3, [Kernel], []>, {}>
93 // CHECK: test.convert_to_atomic_compare_exchange_weak_op
94 %0 = "test.convert_to_atomic_compare_exchange_weak_op"(%ptr, %value, %comparator): (!spv.ptr<i32, Workgroup>, i32, i32) -> (i32)
98 // CHECK-LABEL: @subgroup_ballot_missing_capability
99 func @subgroup_ballot_missing_capability(%predicate: i1) -> vector<4xi32> attributes {
100 spv.target_env = #spv.target_env<#spv.vce<v1.4, [], [SPV_KHR_shader_ballot]>, {}>
102 // CHECK: test.convert_to_subgroup_ballot_op
103 %0 = "test.convert_to_subgroup_ballot_op"(%predicate): (i1) -> (vector<4xi32>)
104 return %0: vector<4xi32>
107 // CHECK-LABEL: @bit_reverse_directly_implied_capability
108 func @bit_reverse_directly_implied_capability(%operand: i32) -> i32 attributes {
109 spv.target_env = #spv.target_env<#spv.vce<v1.0, [Geometry], []>, {}>
111 // CHECK: spv.BitReverse
112 %0 = "test.convert_to_bit_reverse_op"(%operand): (i32) -> (i32)
116 // CHECK-LABEL: @bit_reverse_recursively_implied_capability
117 func @bit_reverse_recursively_implied_capability(%operand: i32) -> i32 attributes {
118 spv.target_env = #spv.target_env<#spv.vce<v1.0, [GeometryPointSize], []>, {}>
120 // CHECK: spv.BitReverse
121 %0 = "test.convert_to_bit_reverse_op"(%operand): (i32) -> (i32)
125 //===----------------------------------------------------------------------===//
127 //===----------------------------------------------------------------------===//
129 // CHECK-LABEL: @subgroup_ballot_suitable_extension
130 func @subgroup_ballot_suitable_extension(%predicate: i1) -> vector<4xi32> attributes {
131 spv.target_env = #spv.target_env<#spv.vce<v1.4, [SubgroupBallotKHR], [SPV_KHR_shader_ballot]>, {}>
133 // CHECK: spv.SubgroupBallotKHR
134 %0 = "test.convert_to_subgroup_ballot_op"(%predicate): (i1) -> (vector<4xi32>)
135 return %0: vector<4xi32>
138 // CHECK-LABEL: @subgroup_ballot_missing_extension
139 func @subgroup_ballot_missing_extension(%predicate: i1) -> vector<4xi32> attributes {
140 spv.target_env = #spv.target_env<#spv.vce<v1.4, [SubgroupBallotKHR], []>, {}>
142 // CHECK: test.convert_to_subgroup_ballot_op
143 %0 = "test.convert_to_subgroup_ballot_op"(%predicate): (i1) -> (vector<4xi32>)
144 return %0: vector<4xi32>
147 // CHECK-LABEL: @module_suitable_extension1
148 func @module_suitable_extension1() attributes {
149 spv.target_env = #spv.target_env<#spv.vce<v1.0, [VulkanMemoryModel, PhysicalStorageBufferAddresses], [SPV_KHR_vulkan_memory_model, SPV_EXT_physical_storage_buffer]>, {}>
151 // CHECK: spv.module PhysicalStorageBuffer64 Vulkan
152 "test.convert_to_module_op"() : () ->()
156 // CHECK-LABEL: @module_suitable_extension2
157 func @module_suitable_extension2() attributes {
158 spv.target_env = #spv.target_env<#spv.vce<v1.0, [VulkanMemoryModel, PhysicalStorageBufferAddresses], [SPV_KHR_vulkan_memory_model, SPV_KHR_physical_storage_buffer]>, {}>
160 // CHECK: spv.module PhysicalStorageBuffer64 Vulkan
161 "test.convert_to_module_op"() : () -> ()
165 // CHECK-LABEL: @module_missing_extension_mm
166 func @module_missing_extension_mm() attributes {
167 spv.target_env = #spv.target_env<#spv.vce<v1.0, [VulkanMemoryModel, PhysicalStorageBufferAddresses], [SPV_KHR_physical_storage_buffer]>, {}>
169 // CHECK: test.convert_to_module_op
170 "test.convert_to_module_op"() : () -> ()
174 // CHECK-LABEL: @module_missing_extension_am
175 func @module_missing_extension_am() attributes {
176 spv.target_env = #spv.target_env<#spv.vce<v1.0, [VulkanMemoryModel, PhysicalStorageBufferAddresses], [SPV_KHR_vulkan_memory_model]>, {}>
178 // CHECK: test.convert_to_module_op
179 "test.convert_to_module_op"() : () -> ()
183 // CHECK-LABEL: @module_implied_extension
184 func @module_implied_extension() attributes {
185 // Version 1.5 implies SPV_KHR_vulkan_memory_model and SPV_KHR_physical_storage_buffer.
186 spv.target_env = #spv.target_env<#spv.vce<v1.5, [VulkanMemoryModel, PhysicalStorageBufferAddresses], []>, {}>
188 // CHECK: spv.module PhysicalStorageBuffer64 Vulkan
189 "test.convert_to_module_op"() : () -> ()