1fd4e5da5Sopenharmony_ci// Copyright (c) 2018 Google LLC 2fd4e5da5Sopenharmony_ci// 3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 6fd4e5da5Sopenharmony_ci// 7fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 13fd4e5da5Sopenharmony_ci// limitations under the License. 14fd4e5da5Sopenharmony_ci 15fd4e5da5Sopenharmony_ci#include "assembly_builder.h" 16fd4e5da5Sopenharmony_ci#include "pass_fixture.h" 17fd4e5da5Sopenharmony_ci#include "pass_utils.h" 18fd4e5da5Sopenharmony_ci 19fd4e5da5Sopenharmony_cinamespace { 20fd4e5da5Sopenharmony_ci 21fd4e5da5Sopenharmony_ciusing namespace spvtools; 22fd4e5da5Sopenharmony_ci 23fd4e5da5Sopenharmony_ciusing UpgradeMemoryModelTest = opt::PassTest<::testing::Test>; 24fd4e5da5Sopenharmony_ci 25fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, InvalidMemoryModelOpenCL) { 26fd4e5da5Sopenharmony_ci const std::string text = R"( 27fd4e5da5Sopenharmony_ci; CHECK: OpMemoryModel Logical OpenCL 28fd4e5da5Sopenharmony_ciOpCapability Kernel 29fd4e5da5Sopenharmony_ciOpCapability Linkage 30fd4e5da5Sopenharmony_ciOpMemoryModel Logical OpenCL 31fd4e5da5Sopenharmony_ci)"; 32fd4e5da5Sopenharmony_ci 33fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 34fd4e5da5Sopenharmony_ci} 35fd4e5da5Sopenharmony_ci 36fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, InvalidMemoryModelVulkan) { 37fd4e5da5Sopenharmony_ci const std::string text = R"( 38fd4e5da5Sopenharmony_ci; CHECK: OpMemoryModel Logical Vulkan 39fd4e5da5Sopenharmony_ciOpCapability Shader 40fd4e5da5Sopenharmony_ciOpCapability Linkage 41fd4e5da5Sopenharmony_ciOpCapability VulkanMemoryModel 42fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model" 43fd4e5da5Sopenharmony_ciOpMemoryModel Logical Vulkan 44fd4e5da5Sopenharmony_ci)"; 45fd4e5da5Sopenharmony_ci 46fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 47fd4e5da5Sopenharmony_ci} 48fd4e5da5Sopenharmony_ci 49fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, JustMemoryModel) { 50fd4e5da5Sopenharmony_ci const std::string text = R"( 51fd4e5da5Sopenharmony_ci; CHECK: OpCapability VulkanMemoryModel 52fd4e5da5Sopenharmony_ci; CHECK: OpExtension "SPV_KHR_vulkan_memory_model" 53fd4e5da5Sopenharmony_ci; CHECK: OpMemoryModel Logical Vulkan 54fd4e5da5Sopenharmony_ciOpCapability Shader 55fd4e5da5Sopenharmony_ciOpCapability Linkage 56fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 57fd4e5da5Sopenharmony_ci)"; 58fd4e5da5Sopenharmony_ci 59fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 60fd4e5da5Sopenharmony_ci} 61fd4e5da5Sopenharmony_ci 62fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, RemoveDecorations) { 63fd4e5da5Sopenharmony_ci const std::string text = R"( 64fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 65fd4e5da5Sopenharmony_ciOpCapability Shader 66fd4e5da5Sopenharmony_ciOpCapability Linkage 67fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 68fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 69fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 70fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 71fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 72fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Uniform Uniform 73fd4e5da5Sopenharmony_ci)"; 74fd4e5da5Sopenharmony_ci 75fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 76fd4e5da5Sopenharmony_ci} 77fd4e5da5Sopenharmony_ci 78fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, WorkgroupVariable) { 79fd4e5da5Sopenharmony_ci const std::string text = R"( 80fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2 81fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 82fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 83fd4e5da5Sopenharmony_ciOpCapability Shader 84fd4e5da5Sopenharmony_ciOpCapability Linkage 85fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 86fd4e5da5Sopenharmony_ci%void = OpTypeVoid 87fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 88fd4e5da5Sopenharmony_ci%ptr_int_Workgroup = OpTypePointer Workgroup %int 89fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Workgroup Workgroup 90fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 91fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 92fd4e5da5Sopenharmony_ci%1 = OpLabel 93fd4e5da5Sopenharmony_ci%ld = OpLoad %int %var 94fd4e5da5Sopenharmony_ciOpStore %var %ld 95fd4e5da5Sopenharmony_ciOpReturn 96fd4e5da5Sopenharmony_ciOpFunctionEnd 97fd4e5da5Sopenharmony_ci)"; 98fd4e5da5Sopenharmony_ci 99fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 100fd4e5da5Sopenharmony_ci} 101fd4e5da5Sopenharmony_ci 102fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, WorkgroupFunctionParameter) { 103fd4e5da5Sopenharmony_ci const std::string text = R"( 104fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2 105fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 106fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 107fd4e5da5Sopenharmony_ciOpCapability Shader 108fd4e5da5Sopenharmony_ciOpCapability Linkage 109fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 110fd4e5da5Sopenharmony_ci%void = OpTypeVoid 111fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 112fd4e5da5Sopenharmony_ci%ptr_int_Workgroup = OpTypePointer Workgroup %int 113fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_int_Workgroup 114fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 115fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_int_Workgroup 116fd4e5da5Sopenharmony_ci%1 = OpLabel 117fd4e5da5Sopenharmony_ci%ld = OpLoad %int %param 118fd4e5da5Sopenharmony_ciOpStore %param %ld 119fd4e5da5Sopenharmony_ciOpReturn 120fd4e5da5Sopenharmony_ciOpFunctionEnd 121fd4e5da5Sopenharmony_ci)"; 122fd4e5da5Sopenharmony_ci 123fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 124fd4e5da5Sopenharmony_ci} 125fd4e5da5Sopenharmony_ci 126fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SimpleUniformVariable) { 127fd4e5da5Sopenharmony_ci const std::string text = R"( 128fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 129fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 130fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 131fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 132fd4e5da5Sopenharmony_ciOpCapability Shader 133fd4e5da5Sopenharmony_ciOpCapability Linkage 134fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 135fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 136fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 137fd4e5da5Sopenharmony_ci%void = OpTypeVoid 138fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 139fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 140fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Uniform Uniform 141fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 142fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 143fd4e5da5Sopenharmony_ci%1 = OpLabel 144fd4e5da5Sopenharmony_ci%ld = OpLoad %int %var 145fd4e5da5Sopenharmony_ciOpStore %var %ld 146fd4e5da5Sopenharmony_ciOpReturn 147fd4e5da5Sopenharmony_ciOpFunctionEnd 148fd4e5da5Sopenharmony_ci)"; 149fd4e5da5Sopenharmony_ci 150fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 151fd4e5da5Sopenharmony_ci} 152fd4e5da5Sopenharmony_ci 153fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameter) { 154fd4e5da5Sopenharmony_ci const std::string text = R"( 155fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 156fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 157fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 158fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 159fd4e5da5Sopenharmony_ciOpCapability Shader 160fd4e5da5Sopenharmony_ciOpCapability Linkage 161fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 162fd4e5da5Sopenharmony_ciOpDecorate %param Coherent 163fd4e5da5Sopenharmony_ciOpDecorate %param Volatile 164fd4e5da5Sopenharmony_ci%void = OpTypeVoid 165fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 166fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 167fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_int_Uniform 168fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 169fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_int_Uniform 170fd4e5da5Sopenharmony_ci%1 = OpLabel 171fd4e5da5Sopenharmony_ci%ld = OpLoad %int %param 172fd4e5da5Sopenharmony_ciOpStore %param %ld 173fd4e5da5Sopenharmony_ciOpReturn 174fd4e5da5Sopenharmony_ciOpFunctionEnd 175fd4e5da5Sopenharmony_ci)"; 176fd4e5da5Sopenharmony_ci 177fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 178fd4e5da5Sopenharmony_ci} 179fd4e5da5Sopenharmony_ci 180fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SimpleUniformVariableOnlyVolatile) { 181fd4e5da5Sopenharmony_ci const std::string text = R"( 182fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 183fd4e5da5Sopenharmony_ci; CHECK-NOT: OpConstant 184fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile 185fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile 186fd4e5da5Sopenharmony_ciOpCapability Shader 187fd4e5da5Sopenharmony_ciOpCapability Linkage 188fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 189fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 190fd4e5da5Sopenharmony_ci%void = OpTypeVoid 191fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 192fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 193fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Uniform Uniform 194fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 195fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 196fd4e5da5Sopenharmony_ci%1 = OpLabel 197fd4e5da5Sopenharmony_ci%ld = OpLoad %int %var 198fd4e5da5Sopenharmony_ciOpStore %var %ld 199fd4e5da5Sopenharmony_ciOpReturn 200fd4e5da5Sopenharmony_ciOpFunctionEnd 201fd4e5da5Sopenharmony_ci)"; 202fd4e5da5Sopenharmony_ci 203fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 204fd4e5da5Sopenharmony_ci} 205fd4e5da5Sopenharmony_ci 206fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SimpleUniformVariableCopied) { 207fd4e5da5Sopenharmony_ci const std::string text = R"( 208fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 209fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 210fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 211fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 212fd4e5da5Sopenharmony_ciOpCapability Shader 213fd4e5da5Sopenharmony_ciOpCapability Linkage 214fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 215fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 216fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 217fd4e5da5Sopenharmony_ci%void = OpTypeVoid 218fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 219fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 220fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Uniform Uniform 221fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 222fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 223fd4e5da5Sopenharmony_ci%1 = OpLabel 224fd4e5da5Sopenharmony_ci%copy = OpCopyObject %ptr_int_Uniform %var 225fd4e5da5Sopenharmony_ci%ld = OpLoad %int %copy 226fd4e5da5Sopenharmony_ciOpStore %copy %ld 227fd4e5da5Sopenharmony_ciOpReturn 228fd4e5da5Sopenharmony_ciOpFunctionEnd 229fd4e5da5Sopenharmony_ci)"; 230fd4e5da5Sopenharmony_ci 231fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 232fd4e5da5Sopenharmony_ci} 233fd4e5da5Sopenharmony_ci 234fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterCopied) { 235fd4e5da5Sopenharmony_ci const std::string text = R"( 236fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 237fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 238fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 239fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 240fd4e5da5Sopenharmony_ciOpCapability Shader 241fd4e5da5Sopenharmony_ciOpCapability Linkage 242fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 243fd4e5da5Sopenharmony_ciOpDecorate %param Coherent 244fd4e5da5Sopenharmony_ciOpDecorate %param Volatile 245fd4e5da5Sopenharmony_ci%void = OpTypeVoid 246fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 247fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 248fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_int_Uniform 249fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 250fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_int_Uniform 251fd4e5da5Sopenharmony_ci%1 = OpLabel 252fd4e5da5Sopenharmony_ci%copy = OpCopyObject %ptr_int_Uniform %param 253fd4e5da5Sopenharmony_ci%ld = OpLoad %int %copy 254fd4e5da5Sopenharmony_ci%copy2 = OpCopyObject %ptr_int_Uniform %param 255fd4e5da5Sopenharmony_ciOpStore %copy2 %ld 256fd4e5da5Sopenharmony_ciOpReturn 257fd4e5da5Sopenharmony_ciOpFunctionEnd 258fd4e5da5Sopenharmony_ci)"; 259fd4e5da5Sopenharmony_ci 260fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 261fd4e5da5Sopenharmony_ci} 262fd4e5da5Sopenharmony_ci 263fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SimpleUniformVariableAccessChain) { 264fd4e5da5Sopenharmony_ci const std::string text = R"( 265fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 266fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 267fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 268fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 269fd4e5da5Sopenharmony_ciOpCapability Shader 270fd4e5da5Sopenharmony_ciOpCapability Linkage 271fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 272fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 273fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 274fd4e5da5Sopenharmony_ci%void = OpTypeVoid 275fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 276fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 277fd4e5da5Sopenharmony_ci%int3 = OpConstant %int 3 278fd4e5da5Sopenharmony_ci%int_array_3 = OpTypeArray %int %int3 279fd4e5da5Sopenharmony_ci%ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3 280fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 281fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_intarray_Uniform Uniform 282fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 283fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 284fd4e5da5Sopenharmony_ci%1 = OpLabel 285fd4e5da5Sopenharmony_ci%gep = OpAccessChain %ptr_int_Uniform %var %int0 286fd4e5da5Sopenharmony_ci%ld = OpLoad %int %gep 287fd4e5da5Sopenharmony_ciOpStore %gep %ld 288fd4e5da5Sopenharmony_ciOpReturn 289fd4e5da5Sopenharmony_ciOpFunctionEnd 290fd4e5da5Sopenharmony_ci)"; 291fd4e5da5Sopenharmony_ci 292fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 293fd4e5da5Sopenharmony_ci} 294fd4e5da5Sopenharmony_ci 295fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterAccessChain) { 296fd4e5da5Sopenharmony_ci const std::string text = R"( 297fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 298fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 299fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 300fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 301fd4e5da5Sopenharmony_ciOpCapability Shader 302fd4e5da5Sopenharmony_ciOpCapability Linkage 303fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 304fd4e5da5Sopenharmony_ciOpDecorate %param Coherent 305fd4e5da5Sopenharmony_ciOpDecorate %param Volatile 306fd4e5da5Sopenharmony_ci%void = OpTypeVoid 307fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 308fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 309fd4e5da5Sopenharmony_ci%int3 = OpConstant %int 3 310fd4e5da5Sopenharmony_ci%int_array_3 = OpTypeArray %int %int3 311fd4e5da5Sopenharmony_ci%ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3 312fd4e5da5Sopenharmony_ci%ptr_int_Uniform = OpTypePointer Uniform %int 313fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_intarray_Uniform 314fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 315fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_intarray_Uniform 316fd4e5da5Sopenharmony_ci%1 = OpLabel 317fd4e5da5Sopenharmony_ci%ld_gep = OpAccessChain %ptr_int_Uniform %param %int0 318fd4e5da5Sopenharmony_ci%ld = OpLoad %int %ld_gep 319fd4e5da5Sopenharmony_ci%st_gep = OpAccessChain %ptr_int_Uniform %param %int0 320fd4e5da5Sopenharmony_ciOpStore %st_gep %ld 321fd4e5da5Sopenharmony_ciOpReturn 322fd4e5da5Sopenharmony_ciOpFunctionEnd 323fd4e5da5Sopenharmony_ci)"; 324fd4e5da5Sopenharmony_ci 325fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 326fd4e5da5Sopenharmony_ci} 327fd4e5da5Sopenharmony_ci 328fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VariablePointerSelect) { 329fd4e5da5Sopenharmony_ci const std::string text = R"( 330fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 331fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 332fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 333fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 334fd4e5da5Sopenharmony_ciOpCapability Shader 335fd4e5da5Sopenharmony_ciOpCapability Linkage 336fd4e5da5Sopenharmony_ciOpCapability VariablePointers 337fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_variable_pointers" 338fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 339fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 340fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 341fd4e5da5Sopenharmony_ci%void = OpTypeVoid 342fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 343fd4e5da5Sopenharmony_ci%bool = OpTypeBool 344fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool 345fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 346fd4e5da5Sopenharmony_ci%null = OpConstantNull %ptr_int_StorageBuffer 347fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_StorageBuffer StorageBuffer 348fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 349fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 350fd4e5da5Sopenharmony_ci%1 = OpLabel 351fd4e5da5Sopenharmony_ci%select = OpSelect %ptr_int_StorageBuffer %true %var %null 352fd4e5da5Sopenharmony_ci%ld = OpLoad %int %select 353fd4e5da5Sopenharmony_ciOpStore %var %ld 354fd4e5da5Sopenharmony_ciOpReturn 355fd4e5da5Sopenharmony_ciOpFunctionEnd 356fd4e5da5Sopenharmony_ci)"; 357fd4e5da5Sopenharmony_ci 358fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 359fd4e5da5Sopenharmony_ci} 360fd4e5da5Sopenharmony_ci 361fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VariablePointerSelectConservative) { 362fd4e5da5Sopenharmony_ci const std::string text = R"( 363fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 364fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 365fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]] 366fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]] 367fd4e5da5Sopenharmony_ciOpCapability Shader 368fd4e5da5Sopenharmony_ciOpCapability Linkage 369fd4e5da5Sopenharmony_ciOpCapability VariablePointers 370fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_variable_pointers" 371fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 372fd4e5da5Sopenharmony_ciOpDecorate %var1 Coherent 373fd4e5da5Sopenharmony_ciOpDecorate %var2 Volatile 374fd4e5da5Sopenharmony_ci%void = OpTypeVoid 375fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 376fd4e5da5Sopenharmony_ci%bool = OpTypeBool 377fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool 378fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 379fd4e5da5Sopenharmony_ci%var1 = OpVariable %ptr_int_StorageBuffer StorageBuffer 380fd4e5da5Sopenharmony_ci%var2 = OpVariable %ptr_int_StorageBuffer StorageBuffer 381fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 382fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 383fd4e5da5Sopenharmony_ci%1 = OpLabel 384fd4e5da5Sopenharmony_ci%select = OpSelect %ptr_int_StorageBuffer %true %var1 %var2 385fd4e5da5Sopenharmony_ci%ld = OpLoad %int %select 386fd4e5da5Sopenharmony_ciOpStore %select %ld 387fd4e5da5Sopenharmony_ciOpReturn 388fd4e5da5Sopenharmony_ciOpFunctionEnd 389fd4e5da5Sopenharmony_ci)"; 390fd4e5da5Sopenharmony_ci 391fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 392fd4e5da5Sopenharmony_ci} 393fd4e5da5Sopenharmony_ci 394fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VariablePointerIncrement) { 395fd4e5da5Sopenharmony_ci const std::string text = R"( 396fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{%\w+}} Coherent 397fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 398fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 399fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 400fd4e5da5Sopenharmony_ciOpCapability Shader 401fd4e5da5Sopenharmony_ciOpCapability Linkage 402fd4e5da5Sopenharmony_ciOpCapability VariablePointers 403fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_variable_pointers" 404fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 405fd4e5da5Sopenharmony_ciOpDecorate %param Coherent 406fd4e5da5Sopenharmony_ciOpDecorate %ptr_int_StorageBuffer ArrayStride 4 407fd4e5da5Sopenharmony_ci%void = OpTypeVoid 408fd4e5da5Sopenharmony_ci%bool = OpTypeBool 409fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 410fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 411fd4e5da5Sopenharmony_ci%int1 = OpConstant %int 1 412fd4e5da5Sopenharmony_ci%int10 = OpConstant %int 10 413fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 414fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_int_StorageBuffer 415fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 416fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_int_StorageBuffer 417fd4e5da5Sopenharmony_ci%1 = OpLabel 418fd4e5da5Sopenharmony_ciOpBranch %2 419fd4e5da5Sopenharmony_ci%2 = OpLabel 420fd4e5da5Sopenharmony_ci%phi = OpPhi %ptr_int_StorageBuffer %param %1 %ptr_next %2 421fd4e5da5Sopenharmony_ci%iv = OpPhi %int %int0 %1 %inc %2 422fd4e5da5Sopenharmony_ci%inc = OpIAdd %int %iv %int1 423fd4e5da5Sopenharmony_ci%ptr_next = OpPtrAccessChain %ptr_int_StorageBuffer %phi %int1 424fd4e5da5Sopenharmony_ci%cmp = OpIEqual %bool %iv %int10 425fd4e5da5Sopenharmony_ciOpLoopMerge %3 %2 None 426fd4e5da5Sopenharmony_ciOpBranchConditional %cmp %3 %2 427fd4e5da5Sopenharmony_ci%3 = OpLabel 428fd4e5da5Sopenharmony_ci%ld = OpLoad %int %phi 429fd4e5da5Sopenharmony_ciOpStore %phi %ld 430fd4e5da5Sopenharmony_ciOpReturn 431fd4e5da5Sopenharmony_ciOpFunctionEnd 432fd4e5da5Sopenharmony_ci)"; 433fd4e5da5Sopenharmony_ci 434fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 435fd4e5da5Sopenharmony_ci} 436fd4e5da5Sopenharmony_ci 437fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentStructElement) { 438fd4e5da5Sopenharmony_ci const std::string text = R"( 439fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 440fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 441fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 442fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 443fd4e5da5Sopenharmony_ciOpCapability Shader 444fd4e5da5Sopenharmony_ciOpCapability Linkage 445fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 446fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 447fd4e5da5Sopenharmony_ciOpMemberDecorate %struct 0 Coherent 448fd4e5da5Sopenharmony_ci%void = OpTypeVoid 449fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 450fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 451fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %int 452fd4e5da5Sopenharmony_ci%ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct 453fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 454fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer 455fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 456fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_struct_StorageBuffer 457fd4e5da5Sopenharmony_ci%1 = OpLabel 458fd4e5da5Sopenharmony_ci%gep = OpAccessChain %ptr_int_StorageBuffer %param %int0 459fd4e5da5Sopenharmony_ci%ld = OpLoad %int %gep 460fd4e5da5Sopenharmony_ciOpStore %gep %ld 461fd4e5da5Sopenharmony_ciOpReturn 462fd4e5da5Sopenharmony_ciOpFunctionEnd 463fd4e5da5Sopenharmony_ci)"; 464fd4e5da5Sopenharmony_ci 465fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 466fd4e5da5Sopenharmony_ci} 467fd4e5da5Sopenharmony_ci 468fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentElementFullStructAccess) { 469fd4e5da5Sopenharmony_ci const std::string text = R"( 470fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 471fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 472fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 473fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 474fd4e5da5Sopenharmony_ciOpCapability Shader 475fd4e5da5Sopenharmony_ciOpCapability Linkage 476fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 477fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 478fd4e5da5Sopenharmony_ciOpMemberDecorate %struct 0 Coherent 479fd4e5da5Sopenharmony_ci%void = OpTypeVoid 480fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 481fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %int 482fd4e5da5Sopenharmony_ci%ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct 483fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer 484fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 485fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_struct_StorageBuffer 486fd4e5da5Sopenharmony_ci%1 = OpLabel 487fd4e5da5Sopenharmony_ci%ld = OpLoad %struct %param 488fd4e5da5Sopenharmony_ciOpStore %param %ld 489fd4e5da5Sopenharmony_ciOpReturn 490fd4e5da5Sopenharmony_ciOpFunctionEnd 491fd4e5da5Sopenharmony_ci)"; 492fd4e5da5Sopenharmony_ci 493fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 494fd4e5da5Sopenharmony_ci} 495fd4e5da5Sopenharmony_ci 496fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentElementNotAccessed) { 497fd4e5da5Sopenharmony_ci const std::string text = R"( 498fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 499fd4e5da5Sopenharmony_ci; CHECK-NOT: MakePointerAvailable 500fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 501fd4e5da5Sopenharmony_ci; CHECK-NOT: MakePointerVisible 502fd4e5da5Sopenharmony_ciOpCapability Shader 503fd4e5da5Sopenharmony_ciOpCapability Linkage 504fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 505fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 506fd4e5da5Sopenharmony_ciOpMemberDecorate %struct 1 Coherent 507fd4e5da5Sopenharmony_ci%void = OpTypeVoid 508fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 509fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 510fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %int %int 511fd4e5da5Sopenharmony_ci%ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct 512fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 513fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer 514fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 515fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_struct_StorageBuffer 516fd4e5da5Sopenharmony_ci%1 = OpLabel 517fd4e5da5Sopenharmony_ci%gep = OpAccessChain %ptr_int_StorageBuffer %param %int0 518fd4e5da5Sopenharmony_ci%ld = OpLoad %int %gep 519fd4e5da5Sopenharmony_ciOpStore %gep %ld 520fd4e5da5Sopenharmony_ciOpReturn 521fd4e5da5Sopenharmony_ciOpFunctionEnd 522fd4e5da5Sopenharmony_ci)"; 523fd4e5da5Sopenharmony_ci 524fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 525fd4e5da5Sopenharmony_ci} 526fd4e5da5Sopenharmony_ci 527fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, MultiIndexAccessCoherent) { 528fd4e5da5Sopenharmony_ci const std::string text = R"( 529fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 530fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 531fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 532fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 533fd4e5da5Sopenharmony_ciOpCapability Shader 534fd4e5da5Sopenharmony_ciOpCapability Linkage 535fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 536fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 537fd4e5da5Sopenharmony_ciOpMemberDecorate %inner 1 Coherent 538fd4e5da5Sopenharmony_ci%void = OpTypeVoid 539fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 540fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 541fd4e5da5Sopenharmony_ci%int1 = OpConstant %int 1 542fd4e5da5Sopenharmony_ci%inner = OpTypeStruct %int %int 543fd4e5da5Sopenharmony_ci%middle = OpTypeStruct %inner 544fd4e5da5Sopenharmony_ci%outer = OpTypeStruct %middle %middle 545fd4e5da5Sopenharmony_ci%ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer 546fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 547fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer 548fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 549fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_outer_StorageBuffer 550fd4e5da5Sopenharmony_ci%1 = OpLabel 551fd4e5da5Sopenharmony_ci%ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int1 552fd4e5da5Sopenharmony_ci%ld = OpLoad %int %ld_gep 553fd4e5da5Sopenharmony_ci%st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int1 554fd4e5da5Sopenharmony_ciOpStore %st_gep %ld 555fd4e5da5Sopenharmony_ciOpReturn 556fd4e5da5Sopenharmony_ciOpFunctionEnd 557fd4e5da5Sopenharmony_ci)"; 558fd4e5da5Sopenharmony_ci 559fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 560fd4e5da5Sopenharmony_ci} 561fd4e5da5Sopenharmony_ci 562fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, MultiIndexAccessNonCoherent) { 563fd4e5da5Sopenharmony_ci const std::string text = R"( 564fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 565fd4e5da5Sopenharmony_ci; CHECK-NOT: MakePointerAvailable 566fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 567fd4e5da5Sopenharmony_ci; CHECK-NOT: MakePointerVisible 568fd4e5da5Sopenharmony_ciOpCapability Shader 569fd4e5da5Sopenharmony_ciOpCapability Linkage 570fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 571fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 572fd4e5da5Sopenharmony_ciOpMemberDecorate %inner 1 Coherent 573fd4e5da5Sopenharmony_ci%void = OpTypeVoid 574fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 575fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 576fd4e5da5Sopenharmony_ci%int1 = OpConstant %int 1 577fd4e5da5Sopenharmony_ci%inner = OpTypeStruct %int %int 578fd4e5da5Sopenharmony_ci%middle = OpTypeStruct %inner 579fd4e5da5Sopenharmony_ci%outer = OpTypeStruct %middle %middle 580fd4e5da5Sopenharmony_ci%ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer 581fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 582fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer 583fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 584fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_outer_StorageBuffer 585fd4e5da5Sopenharmony_ci%1 = OpLabel 586fd4e5da5Sopenharmony_ci%ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int0 587fd4e5da5Sopenharmony_ci%ld = OpLoad %int %ld_gep 588fd4e5da5Sopenharmony_ci%st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int0 589fd4e5da5Sopenharmony_ciOpStore %st_gep %ld 590fd4e5da5Sopenharmony_ciOpReturn 591fd4e5da5Sopenharmony_ciOpFunctionEnd 592fd4e5da5Sopenharmony_ci)"; 593fd4e5da5Sopenharmony_ci 594fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 595fd4e5da5Sopenharmony_ci} 596fd4e5da5Sopenharmony_ci 597fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainCoherent) { 598fd4e5da5Sopenharmony_ci const std::string text = R"( 599fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 600fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 601fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 602fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 603fd4e5da5Sopenharmony_ciOpCapability Shader 604fd4e5da5Sopenharmony_ciOpCapability Linkage 605fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 606fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 607fd4e5da5Sopenharmony_ciOpMemberDecorate %inner 1 Coherent 608fd4e5da5Sopenharmony_ci%void = OpTypeVoid 609fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 610fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 611fd4e5da5Sopenharmony_ci%int1 = OpConstant %int 1 612fd4e5da5Sopenharmony_ci%inner = OpTypeStruct %int %int 613fd4e5da5Sopenharmony_ci%middle = OpTypeStruct %inner 614fd4e5da5Sopenharmony_ci%outer = OpTypeStruct %middle %middle 615fd4e5da5Sopenharmony_ci%ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer 616fd4e5da5Sopenharmony_ci%ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle 617fd4e5da5Sopenharmony_ci%ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner 618fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 619fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer 620fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 621fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_outer_StorageBuffer 622fd4e5da5Sopenharmony_ci%1 = OpLabel 623fd4e5da5Sopenharmony_ci%ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0 624fd4e5da5Sopenharmony_ci%ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0 625fd4e5da5Sopenharmony_ci%ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1 626fd4e5da5Sopenharmony_ci%ld = OpLoad %int %ld_gep3 627fd4e5da5Sopenharmony_ci%st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1 628fd4e5da5Sopenharmony_ci%st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0 629fd4e5da5Sopenharmony_ci%st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1 630fd4e5da5Sopenharmony_ciOpStore %st_gep3 %ld 631fd4e5da5Sopenharmony_ciOpReturn 632fd4e5da5Sopenharmony_ciOpFunctionEnd 633fd4e5da5Sopenharmony_ci)"; 634fd4e5da5Sopenharmony_ci 635fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 636fd4e5da5Sopenharmony_ci} 637fd4e5da5Sopenharmony_ci 638fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainNonCoherent) { 639fd4e5da5Sopenharmony_ci const std::string text = R"( 640fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 641fd4e5da5Sopenharmony_ci; CHECK-NOT: MakePointerAvailable 642fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 643fd4e5da5Sopenharmony_ci; CHECK-NOT: MakePointerVisible 644fd4e5da5Sopenharmony_ciOpCapability Shader 645fd4e5da5Sopenharmony_ciOpCapability Linkage 646fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 647fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 648fd4e5da5Sopenharmony_ciOpMemberDecorate %inner 1 Coherent 649fd4e5da5Sopenharmony_ci%void = OpTypeVoid 650fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 651fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 652fd4e5da5Sopenharmony_ci%int1 = OpConstant %int 1 653fd4e5da5Sopenharmony_ci%inner = OpTypeStruct %int %int 654fd4e5da5Sopenharmony_ci%middle = OpTypeStruct %inner 655fd4e5da5Sopenharmony_ci%outer = OpTypeStruct %middle %middle 656fd4e5da5Sopenharmony_ci%ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer 657fd4e5da5Sopenharmony_ci%ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle 658fd4e5da5Sopenharmony_ci%ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner 659fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 660fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer 661fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 662fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_outer_StorageBuffer 663fd4e5da5Sopenharmony_ci%1 = OpLabel 664fd4e5da5Sopenharmony_ci%ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0 665fd4e5da5Sopenharmony_ci%ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0 666fd4e5da5Sopenharmony_ci%ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int0 667fd4e5da5Sopenharmony_ci%ld = OpLoad %int %ld_gep3 668fd4e5da5Sopenharmony_ci%st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1 669fd4e5da5Sopenharmony_ci%st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0 670fd4e5da5Sopenharmony_ci%st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int0 671fd4e5da5Sopenharmony_ciOpStore %st_gep3 %ld 672fd4e5da5Sopenharmony_ciOpReturn 673fd4e5da5Sopenharmony_ciOpFunctionEnd 674fd4e5da5Sopenharmony_ci)"; 675fd4e5da5Sopenharmony_ci 676fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 677fd4e5da5Sopenharmony_ci} 678fd4e5da5Sopenharmony_ci 679fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentStructElementAccess) { 680fd4e5da5Sopenharmony_ci const std::string text = R"( 681fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 682fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 683fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 684fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 685fd4e5da5Sopenharmony_ciOpCapability Shader 686fd4e5da5Sopenharmony_ciOpCapability Linkage 687fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 688fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 689fd4e5da5Sopenharmony_ciOpMemberDecorate %middle 0 Coherent 690fd4e5da5Sopenharmony_ci%void = OpTypeVoid 691fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 692fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 693fd4e5da5Sopenharmony_ci%int1 = OpConstant %int 1 694fd4e5da5Sopenharmony_ci%inner = OpTypeStruct %int %int 695fd4e5da5Sopenharmony_ci%middle = OpTypeStruct %inner 696fd4e5da5Sopenharmony_ci%outer = OpTypeStruct %middle %middle 697fd4e5da5Sopenharmony_ci%ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer 698fd4e5da5Sopenharmony_ci%ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle 699fd4e5da5Sopenharmony_ci%ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner 700fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 701fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer 702fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 703fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_outer_StorageBuffer 704fd4e5da5Sopenharmony_ci%1 = OpLabel 705fd4e5da5Sopenharmony_ci%ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0 706fd4e5da5Sopenharmony_ci%ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0 707fd4e5da5Sopenharmony_ci%ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1 708fd4e5da5Sopenharmony_ci%ld = OpLoad %int %ld_gep3 709fd4e5da5Sopenharmony_ci%st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1 710fd4e5da5Sopenharmony_ci%st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0 711fd4e5da5Sopenharmony_ci%st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1 712fd4e5da5Sopenharmony_ciOpStore %st_gep3 %ld 713fd4e5da5Sopenharmony_ciOpReturn 714fd4e5da5Sopenharmony_ciOpFunctionEnd 715fd4e5da5Sopenharmony_ci)"; 716fd4e5da5Sopenharmony_ci 717fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 718fd4e5da5Sopenharmony_ci} 719fd4e5da5Sopenharmony_ci 720fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, NonCoherentLoadCoherentStore) { 721fd4e5da5Sopenharmony_ci const std::string text = R"( 722fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 723fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 724fd4e5da5Sopenharmony_ci; CHECK-NOT: MakePointerVisible 725fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] 726fd4e5da5Sopenharmony_ciOpCapability Shader 727fd4e5da5Sopenharmony_ciOpCapability Linkage 728fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 729fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 730fd4e5da5Sopenharmony_ciOpMemberDecorate %outer 1 Coherent 731fd4e5da5Sopenharmony_ci%void = OpTypeVoid 732fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 733fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 734fd4e5da5Sopenharmony_ci%int1 = OpConstant %int 1 735fd4e5da5Sopenharmony_ci%inner = OpTypeStruct %int %int 736fd4e5da5Sopenharmony_ci%middle = OpTypeStruct %inner 737fd4e5da5Sopenharmony_ci%outer = OpTypeStruct %middle %middle 738fd4e5da5Sopenharmony_ci%ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer 739fd4e5da5Sopenharmony_ci%ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle 740fd4e5da5Sopenharmony_ci%ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner 741fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 742fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer 743fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 744fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_outer_StorageBuffer 745fd4e5da5Sopenharmony_ci%1 = OpLabel 746fd4e5da5Sopenharmony_ci%ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0 747fd4e5da5Sopenharmony_ci%ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0 748fd4e5da5Sopenharmony_ci%ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1 749fd4e5da5Sopenharmony_ci%ld = OpLoad %int %ld_gep3 750fd4e5da5Sopenharmony_ci%st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1 751fd4e5da5Sopenharmony_ci%st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0 752fd4e5da5Sopenharmony_ci%st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1 753fd4e5da5Sopenharmony_ciOpStore %st_gep3 %ld 754fd4e5da5Sopenharmony_ciOpReturn 755fd4e5da5Sopenharmony_ciOpFunctionEnd 756fd4e5da5Sopenharmony_ci)"; 757fd4e5da5Sopenharmony_ci 758fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 759fd4e5da5Sopenharmony_ci} 760fd4e5da5Sopenharmony_ci 761fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CopyMemory) { 762fd4e5da5Sopenharmony_ci const std::string text = R"( 763fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 764fd4e5da5Sopenharmony_ci; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5 765fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[queuefamily]] 766fd4e5da5Sopenharmony_ci; CHECK-NOT: [[queuefamily]] 767fd4e5da5Sopenharmony_ciOpCapability Shader 768fd4e5da5Sopenharmony_ciOpCapability Linkage 769fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 770fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 771fd4e5da5Sopenharmony_ciOpDecorate %in_var Coherent 772fd4e5da5Sopenharmony_ciOpDecorate %out_var Volatile 773fd4e5da5Sopenharmony_ci%void = OpTypeVoid 774fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 775fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 776fd4e5da5Sopenharmony_ci%in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer 777fd4e5da5Sopenharmony_ci%out_var = OpVariable %ptr_int_StorageBuffer StorageBuffer 778fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 779fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 780fd4e5da5Sopenharmony_ci%1 = OpLabel 781fd4e5da5Sopenharmony_ciOpCopyMemory %out_var %in_var 782fd4e5da5Sopenharmony_ciOpReturn 783fd4e5da5Sopenharmony_ciOpFunctionEnd 784fd4e5da5Sopenharmony_ci)"; 785fd4e5da5Sopenharmony_ci 786fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 787fd4e5da5Sopenharmony_ci} 788fd4e5da5Sopenharmony_ci 789fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CopyMemorySized) { 790fd4e5da5Sopenharmony_ci const std::string text = R"( 791fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 792fd4e5da5Sopenharmony_ci; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5 793fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemorySized {{%\w+}} {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[queuefamily]] 794fd4e5da5Sopenharmony_ci; CHECK-NOT: [[queuefamily]] 795fd4e5da5Sopenharmony_ciOpCapability Shader 796fd4e5da5Sopenharmony_ciOpCapability Linkage 797fd4e5da5Sopenharmony_ciOpCapability Addresses 798fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 799fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 800fd4e5da5Sopenharmony_ciOpDecorate %out_param Coherent 801fd4e5da5Sopenharmony_ciOpDecorate %in_param Volatile 802fd4e5da5Sopenharmony_ci%void = OpTypeVoid 803fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 804fd4e5da5Sopenharmony_ci%int4 = OpConstant %int 4 805fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 806fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_int_StorageBuffer %ptr_int_StorageBuffer 807fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 808fd4e5da5Sopenharmony_ci%in_param = OpFunctionParameter %ptr_int_StorageBuffer 809fd4e5da5Sopenharmony_ci%out_param = OpFunctionParameter %ptr_int_StorageBuffer 810fd4e5da5Sopenharmony_ci%1 = OpLabel 811fd4e5da5Sopenharmony_ciOpCopyMemorySized %out_param %in_param %int4 812fd4e5da5Sopenharmony_ciOpReturn 813fd4e5da5Sopenharmony_ciOpFunctionEnd 814fd4e5da5Sopenharmony_ci)"; 815fd4e5da5Sopenharmony_ci 816fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 817fd4e5da5Sopenharmony_ci} 818fd4e5da5Sopenharmony_ci 819fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CopyMemoryTwoScopes) { 820fd4e5da5Sopenharmony_ci const std::string text = R"( 821fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 822fd4e5da5Sopenharmony_ci; CHECK-DAG: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5 823fd4e5da5Sopenharmony_ci; CHECK-DAG: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2 824fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|MakePointerVisible|NonPrivatePointer [[workgroup]] [[queuefamily]] 825fd4e5da5Sopenharmony_ciOpCapability Shader 826fd4e5da5Sopenharmony_ciOpCapability Linkage 827fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 828fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 829fd4e5da5Sopenharmony_ciOpDecorate %in_var Coherent 830fd4e5da5Sopenharmony_ciOpDecorate %out_var Coherent 831fd4e5da5Sopenharmony_ci%void = OpTypeVoid 832fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 833fd4e5da5Sopenharmony_ci%ptr_int_Workgroup = OpTypePointer Workgroup %int 834fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 835fd4e5da5Sopenharmony_ci%in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer 836fd4e5da5Sopenharmony_ci%out_var = OpVariable %ptr_int_Workgroup Workgroup 837fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 838fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 839fd4e5da5Sopenharmony_ci%1 = OpLabel 840fd4e5da5Sopenharmony_ciOpCopyMemory %out_var %in_var 841fd4e5da5Sopenharmony_ciOpReturn 842fd4e5da5Sopenharmony_ciOpFunctionEnd 843fd4e5da5Sopenharmony_ci)"; 844fd4e5da5Sopenharmony_ci 845fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 846fd4e5da5Sopenharmony_ci} 847fd4e5da5Sopenharmony_ci 848fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileImageRead) { 849fd4e5da5Sopenharmony_ci const std::string text = R"( 850fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 851fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile 852fd4e5da5Sopenharmony_ci; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexel 853fd4e5da5Sopenharmony_ciOpCapability Shader 854fd4e5da5Sopenharmony_ciOpCapability Linkage 855fd4e5da5Sopenharmony_ciOpCapability StorageImageReadWithoutFormat 856fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 857fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 858fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 859fd4e5da5Sopenharmony_ci%void = OpTypeVoid 860fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 861fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 862fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 863fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 864fd4e5da5Sopenharmony_ci%v2int_0 = OpConstantComposite %v2int %int0 %int0 865fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 2 Unknown 866fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 867fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_image_StorageBuffer StorageBuffer 868fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 869fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 870fd4e5da5Sopenharmony_ci%1 = OpLabel 871fd4e5da5Sopenharmony_ci%ld = OpLoad %image %var 872fd4e5da5Sopenharmony_ci%rd = OpImageRead %float %ld %v2int_0 873fd4e5da5Sopenharmony_ciOpReturn 874fd4e5da5Sopenharmony_ciOpFunctionEnd 875fd4e5da5Sopenharmony_ci)"; 876fd4e5da5Sopenharmony_ci 877fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 878fd4e5da5Sopenharmony_ci} 879fd4e5da5Sopenharmony_ci 880fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentImageRead) { 881fd4e5da5Sopenharmony_ci const std::string text = R"( 882fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 883fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 884fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 885fd4e5da5Sopenharmony_ci; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]] 886fd4e5da5Sopenharmony_ciOpCapability Shader 887fd4e5da5Sopenharmony_ciOpCapability Linkage 888fd4e5da5Sopenharmony_ciOpCapability StorageImageReadWithoutFormat 889fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 890fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 891fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 892fd4e5da5Sopenharmony_ci%void = OpTypeVoid 893fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 894fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 895fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 896fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 897fd4e5da5Sopenharmony_ci%v2int_0 = OpConstantComposite %v2int %int0 %int0 898fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 2 Unknown 899fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 900fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_image_StorageBuffer StorageBuffer 901fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 902fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 903fd4e5da5Sopenharmony_ci%1 = OpLabel 904fd4e5da5Sopenharmony_ci%ld = OpLoad %image %var 905fd4e5da5Sopenharmony_ci%rd = OpImageRead %float %ld %v2int_0 906fd4e5da5Sopenharmony_ciOpReturn 907fd4e5da5Sopenharmony_ciOpFunctionEnd 908fd4e5da5Sopenharmony_ci)"; 909fd4e5da5Sopenharmony_ci 910fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 911fd4e5da5Sopenharmony_ci} 912fd4e5da5Sopenharmony_ci 913fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentImageReadExtractedFromSampledImage) { 914fd4e5da5Sopenharmony_ci const std::string text = R"( 915fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 916fd4e5da5Sopenharmony_ci; CHECK: [[image:%\w+]] = OpTypeImage 917fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 918fd4e5da5Sopenharmony_ci; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 919fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 920fd4e5da5Sopenharmony_ci; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]] 921fd4e5da5Sopenharmony_ciOpCapability Shader 922fd4e5da5Sopenharmony_ciOpCapability Linkage 923fd4e5da5Sopenharmony_ciOpCapability StorageImageReadWithoutFormat 924fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 925fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 926fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 927fd4e5da5Sopenharmony_ci%void = OpTypeVoid 928fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 929fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 930fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 931fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 932fd4e5da5Sopenharmony_ci%v2int_0 = OpConstantComposite %v2int %int0 %int0 933fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 0 Unknown 934fd4e5da5Sopenharmony_ci%sampled_image = OpTypeSampledImage %image 935fd4e5da5Sopenharmony_ci%sampler = OpTypeSampler 936fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 937fd4e5da5Sopenharmony_ci%ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler 938fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_image_StorageBuffer StorageBuffer 939fd4e5da5Sopenharmony_ci%sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer 940fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 941fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 942fd4e5da5Sopenharmony_ci%1 = OpLabel 943fd4e5da5Sopenharmony_ci%ld = OpLoad %image %var 944fd4e5da5Sopenharmony_ci%ld_sampler = OpLoad %sampler %sampler_var 945fd4e5da5Sopenharmony_ci%sample = OpSampledImage %sampled_image %ld %ld_sampler 946fd4e5da5Sopenharmony_ci%extract = OpImage %image %sample 947fd4e5da5Sopenharmony_ci%rd = OpImageRead %float %extract %v2int_0 948fd4e5da5Sopenharmony_ciOpReturn 949fd4e5da5Sopenharmony_ciOpFunctionEnd 950fd4e5da5Sopenharmony_ci)"; 951fd4e5da5Sopenharmony_ci 952fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 953fd4e5da5Sopenharmony_ci} 954fd4e5da5Sopenharmony_ci 955fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileImageWrite) { 956fd4e5da5Sopenharmony_ci const std::string text = R"( 957fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 958fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile 959fd4e5da5Sopenharmony_ci; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexel 960fd4e5da5Sopenharmony_ciOpCapability Shader 961fd4e5da5Sopenharmony_ciOpCapability Linkage 962fd4e5da5Sopenharmony_ciOpCapability StorageImageWriteWithoutFormat 963fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 964fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 965fd4e5da5Sopenharmony_ciOpDecorate %param Volatile 966fd4e5da5Sopenharmony_ci%void = OpTypeVoid 967fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 968fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 969fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 970fd4e5da5Sopenharmony_ci%float0 = OpConstant %float 0 971fd4e5da5Sopenharmony_ci%v2int_null = OpConstantNull %v2int 972fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 0 Unknown 973fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 974fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_image_StorageBuffer 975fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 976fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_image_StorageBuffer 977fd4e5da5Sopenharmony_ci%1 = OpLabel 978fd4e5da5Sopenharmony_ci%ld = OpLoad %image %param 979fd4e5da5Sopenharmony_ciOpImageWrite %ld %v2int_null %float0 980fd4e5da5Sopenharmony_ciOpReturn 981fd4e5da5Sopenharmony_ciOpFunctionEnd 982fd4e5da5Sopenharmony_ci)"; 983fd4e5da5Sopenharmony_ci 984fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 985fd4e5da5Sopenharmony_ci} 986fd4e5da5Sopenharmony_ci 987fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentImageWrite) { 988fd4e5da5Sopenharmony_ci const std::string text = R"( 989fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 990fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 991fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer 992fd4e5da5Sopenharmony_ci; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailable|NonPrivateTexel [[scope]] 993fd4e5da5Sopenharmony_ciOpCapability Shader 994fd4e5da5Sopenharmony_ciOpCapability Linkage 995fd4e5da5Sopenharmony_ciOpCapability StorageImageWriteWithoutFormat 996fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 997fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 998fd4e5da5Sopenharmony_ciOpDecorate %param Coherent 999fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1000fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1001fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 1002fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1003fd4e5da5Sopenharmony_ci%float0 = OpConstant %float 0 1004fd4e5da5Sopenharmony_ci%v2int_null = OpConstantNull %v2int 1005fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 0 Unknown 1006fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 1007fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_image_StorageBuffer 1008fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1009fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_image_StorageBuffer 1010fd4e5da5Sopenharmony_ci%1 = OpLabel 1011fd4e5da5Sopenharmony_ci%ld = OpLoad %image %param 1012fd4e5da5Sopenharmony_ciOpImageWrite %ld %v2int_null %float0 1013fd4e5da5Sopenharmony_ciOpReturn 1014fd4e5da5Sopenharmony_ciOpFunctionEnd 1015fd4e5da5Sopenharmony_ci)"; 1016fd4e5da5Sopenharmony_ci 1017fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1018fd4e5da5Sopenharmony_ci} 1019fd4e5da5Sopenharmony_ci 1020fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentImageWriteExtractFromSampledImage) { 1021fd4e5da5Sopenharmony_ci const std::string text = R"( 1022fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 1023fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1024fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer 1025fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 1026fd4e5da5Sopenharmony_ci; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailable|NonPrivateTexel [[scope]] 1027fd4e5da5Sopenharmony_ciOpCapability Shader 1028fd4e5da5Sopenharmony_ciOpCapability Linkage 1029fd4e5da5Sopenharmony_ciOpCapability StorageImageWriteWithoutFormat 1030fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 1031fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1032fd4e5da5Sopenharmony_ciOpDecorate %param Coherent 1033fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1034fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1035fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 1036fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1037fd4e5da5Sopenharmony_ci%float0 = OpConstant %float 0 1038fd4e5da5Sopenharmony_ci%v2int_null = OpConstantNull %v2int 1039fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 0 Unknown 1040fd4e5da5Sopenharmony_ci%sampled_image = OpTypeSampledImage %image 1041fd4e5da5Sopenharmony_ci%sampler = OpTypeSampler 1042fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 1043fd4e5da5Sopenharmony_ci%ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler 1044fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void %ptr_image_StorageBuffer %ptr_sampler_StorageBuffer 1045fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1046fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %ptr_image_StorageBuffer 1047fd4e5da5Sopenharmony_ci%sampler_param = OpFunctionParameter %ptr_sampler_StorageBuffer 1048fd4e5da5Sopenharmony_ci%1 = OpLabel 1049fd4e5da5Sopenharmony_ci%ld = OpLoad %image %param 1050fd4e5da5Sopenharmony_ci%ld_sampler = OpLoad %sampler %sampler_param 1051fd4e5da5Sopenharmony_ci%sample = OpSampledImage %sampled_image %ld %ld_sampler 1052fd4e5da5Sopenharmony_ci%extract = OpImage %image %sample 1053fd4e5da5Sopenharmony_ciOpImageWrite %extract %v2int_null %float0 1054fd4e5da5Sopenharmony_ciOpReturn 1055fd4e5da5Sopenharmony_ciOpFunctionEnd 1056fd4e5da5Sopenharmony_ci)"; 1057fd4e5da5Sopenharmony_ci 1058fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1059fd4e5da5Sopenharmony_ci} 1060fd4e5da5Sopenharmony_ci 1061fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileImageSparseRead) { 1062fd4e5da5Sopenharmony_ci const std::string text = R"( 1063fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 1064fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile 1065fd4e5da5Sopenharmony_ci; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexel 1066fd4e5da5Sopenharmony_ciOpCapability Shader 1067fd4e5da5Sopenharmony_ciOpCapability Linkage 1068fd4e5da5Sopenharmony_ciOpCapability StorageImageReadWithoutFormat 1069fd4e5da5Sopenharmony_ciOpCapability SparseResidency 1070fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 1071fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1072fd4e5da5Sopenharmony_ciOpDecorate %var Volatile 1073fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1074fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1075fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 1076fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1077fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 1078fd4e5da5Sopenharmony_ci%v2int_0 = OpConstantComposite %v2int %int0 %int0 1079fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 2 Unknown 1080fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %int %float 1081fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 1082fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_image_StorageBuffer StorageBuffer 1083fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1084fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1085fd4e5da5Sopenharmony_ci%1 = OpLabel 1086fd4e5da5Sopenharmony_ci%ld = OpLoad %image %var 1087fd4e5da5Sopenharmony_ci%rd = OpImageSparseRead %struct %ld %v2int_0 1088fd4e5da5Sopenharmony_ciOpReturn 1089fd4e5da5Sopenharmony_ciOpFunctionEnd 1090fd4e5da5Sopenharmony_ci)"; 1091fd4e5da5Sopenharmony_ci 1092fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1093fd4e5da5Sopenharmony_ci} 1094fd4e5da5Sopenharmony_ci 1095fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentImageSparseRead) { 1096fd4e5da5Sopenharmony_ci const std::string text = R"( 1097fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 1098fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1099fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 1100fd4e5da5Sopenharmony_ci; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]] 1101fd4e5da5Sopenharmony_ciOpCapability Shader 1102fd4e5da5Sopenharmony_ciOpCapability Linkage 1103fd4e5da5Sopenharmony_ciOpCapability StorageImageReadWithoutFormat 1104fd4e5da5Sopenharmony_ciOpCapability SparseResidency 1105fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 1106fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1107fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 1108fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1109fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1110fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 1111fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1112fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 1113fd4e5da5Sopenharmony_ci%v2int_0 = OpConstantComposite %v2int %int0 %int0 1114fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 2 Unknown 1115fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %int %float 1116fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 1117fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_image_StorageBuffer StorageBuffer 1118fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1119fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1120fd4e5da5Sopenharmony_ci%1 = OpLabel 1121fd4e5da5Sopenharmony_ci%ld = OpLoad %image %var 1122fd4e5da5Sopenharmony_ci%rd = OpImageSparseRead %struct %ld %v2int_0 1123fd4e5da5Sopenharmony_ciOpReturn 1124fd4e5da5Sopenharmony_ciOpFunctionEnd 1125fd4e5da5Sopenharmony_ci)"; 1126fd4e5da5Sopenharmony_ci 1127fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1128fd4e5da5Sopenharmony_ci} 1129fd4e5da5Sopenharmony_ci 1130fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, 1131fd4e5da5Sopenharmony_ci CoherentImageSparseReadExtractedFromSampledImage) { 1132fd4e5da5Sopenharmony_ci const std::string text = R"( 1133fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate 1134fd4e5da5Sopenharmony_ci; CHECK: [[image:%\w+]] = OpTypeImage 1135fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1136fd4e5da5Sopenharmony_ci; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]] 1137fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 1138fd4e5da5Sopenharmony_ci; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]] 1139fd4e5da5Sopenharmony_ciOpCapability Shader 1140fd4e5da5Sopenharmony_ciOpCapability Linkage 1141fd4e5da5Sopenharmony_ciOpCapability StorageImageReadWithoutFormat 1142fd4e5da5Sopenharmony_ciOpCapability SparseResidency 1143fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 1144fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1145fd4e5da5Sopenharmony_ciOpDecorate %var Coherent 1146fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1147fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1148fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2 1149fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1150fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0 1151fd4e5da5Sopenharmony_ci%v2int_0 = OpConstantComposite %v2int %int0 %int0 1152fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 2D 0 0 0 0 Unknown 1153fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %int %float 1154fd4e5da5Sopenharmony_ci%sampled_image = OpTypeSampledImage %image 1155fd4e5da5Sopenharmony_ci%sampler = OpTypeSampler 1156fd4e5da5Sopenharmony_ci%ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image 1157fd4e5da5Sopenharmony_ci%ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler 1158fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_image_StorageBuffer StorageBuffer 1159fd4e5da5Sopenharmony_ci%sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer 1160fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1161fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1162fd4e5da5Sopenharmony_ci%1 = OpLabel 1163fd4e5da5Sopenharmony_ci%ld = OpLoad %image %var 1164fd4e5da5Sopenharmony_ci%ld_sampler = OpLoad %sampler %sampler_var 1165fd4e5da5Sopenharmony_ci%sample = OpSampledImage %sampled_image %ld %ld_sampler 1166fd4e5da5Sopenharmony_ci%extract = OpImage %image %sample 1167fd4e5da5Sopenharmony_ci%rd = OpImageSparseRead %struct %extract %v2int_0 1168fd4e5da5Sopenharmony_ciOpReturn 1169fd4e5da5Sopenharmony_ciOpFunctionEnd 1170fd4e5da5Sopenharmony_ci)"; 1171fd4e5da5Sopenharmony_ci 1172fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1173fd4e5da5Sopenharmony_ci} 1174fd4e5da5Sopenharmony_ci 1175fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, TessellationControlBarrierNoChange) { 1176fd4e5da5Sopenharmony_ci const std::string text = R"( 1177fd4e5da5Sopenharmony_ci; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0 1178fd4e5da5Sopenharmony_ci; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2 1179fd4e5da5Sopenharmony_ci; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[none]] 1180fd4e5da5Sopenharmony_ciOpCapability Tessellation 1181fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1182fd4e5da5Sopenharmony_ciOpEntryPoint TessellationControl %func "func" 1183fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1184fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1185fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1186fd4e5da5Sopenharmony_ci%workgroup = OpConstant %int 2 1187fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1188fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1189fd4e5da5Sopenharmony_ci%1 = OpLabel 1190fd4e5da5Sopenharmony_ciOpControlBarrier %workgroup %workgroup %none 1191fd4e5da5Sopenharmony_ciOpReturn 1192fd4e5da5Sopenharmony_ciOpFunctionEnd 1193fd4e5da5Sopenharmony_ci)"; 1194fd4e5da5Sopenharmony_ci 1195fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1196fd4e5da5Sopenharmony_ci} 1197fd4e5da5Sopenharmony_ci 1198fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutput) { 1199fd4e5da5Sopenharmony_ci const std::string text = R"( 1200fd4e5da5Sopenharmony_ci; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2 1201fd4e5da5Sopenharmony_ci; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096 1202fd4e5da5Sopenharmony_ci; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]] 1203fd4e5da5Sopenharmony_ciOpCapability Tessellation 1204fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1205fd4e5da5Sopenharmony_ciOpEntryPoint TessellationControl %func "func" %var 1206fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1207fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1208fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1209fd4e5da5Sopenharmony_ci%workgroup = OpConstant %int 2 1210fd4e5da5Sopenharmony_ci%ptr_int_Output = OpTypePointer Output %int 1211fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Output Output 1212fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1213fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1214fd4e5da5Sopenharmony_ci%1 = OpLabel 1215fd4e5da5Sopenharmony_ci%ld = OpLoad %int %var 1216fd4e5da5Sopenharmony_ciOpControlBarrier %workgroup %workgroup %none 1217fd4e5da5Sopenharmony_ciOpStore %var %ld 1218fd4e5da5Sopenharmony_ciOpReturn 1219fd4e5da5Sopenharmony_ciOpFunctionEnd 1220fd4e5da5Sopenharmony_ci)"; 1221fd4e5da5Sopenharmony_ci 1222fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1223fd4e5da5Sopenharmony_ci} 1224fd4e5da5Sopenharmony_ci 1225fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, TessellationMemoryBarrierNoChange) { 1226fd4e5da5Sopenharmony_ci const std::string text = R"( 1227fd4e5da5Sopenharmony_ci; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0 1228fd4e5da5Sopenharmony_ci; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2 1229fd4e5da5Sopenharmony_ci; CHECK: OpMemoryBarrier [[workgroup]] [[none]] 1230fd4e5da5Sopenharmony_ciOpCapability Tessellation 1231fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1232fd4e5da5Sopenharmony_ciOpEntryPoint TessellationControl %func "func" %var 1233fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1234fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1235fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1236fd4e5da5Sopenharmony_ci%workgroup = OpConstant %int 2 1237fd4e5da5Sopenharmony_ci%ptr_int_Output = OpTypePointer Output %int 1238fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Output Output 1239fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1240fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1241fd4e5da5Sopenharmony_ci%1 = OpLabel 1242fd4e5da5Sopenharmony_ci%ld = OpLoad %int %var 1243fd4e5da5Sopenharmony_ciOpMemoryBarrier %workgroup %none 1244fd4e5da5Sopenharmony_ciOpStore %var %ld 1245fd4e5da5Sopenharmony_ciOpReturn 1246fd4e5da5Sopenharmony_ciOpFunctionEnd 1247fd4e5da5Sopenharmony_ci)"; 1248fd4e5da5Sopenharmony_ci 1249fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1250fd4e5da5Sopenharmony_ci} 1251fd4e5da5Sopenharmony_ci 1252fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutputSubFunction) { 1253fd4e5da5Sopenharmony_ci const std::string text = R"( 1254fd4e5da5Sopenharmony_ci; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2 1255fd4e5da5Sopenharmony_ci; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096 1256fd4e5da5Sopenharmony_ci; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]] 1257fd4e5da5Sopenharmony_ciOpCapability Tessellation 1258fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1259fd4e5da5Sopenharmony_ciOpEntryPoint TessellationControl %func "func" %var 1260fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1261fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1262fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1263fd4e5da5Sopenharmony_ci%workgroup = OpConstant %int 2 1264fd4e5da5Sopenharmony_ci%ptr_int_Output = OpTypePointer Output %int 1265fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Output Output 1266fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1267fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1268fd4e5da5Sopenharmony_ci%1 = OpLabel 1269fd4e5da5Sopenharmony_ci%call = OpFunctionCall %void %sub_func 1270fd4e5da5Sopenharmony_ciOpReturn 1271fd4e5da5Sopenharmony_ciOpFunctionEnd 1272fd4e5da5Sopenharmony_ci%sub_func = OpFunction %void None %func_ty 1273fd4e5da5Sopenharmony_ci%2 = OpLabel 1274fd4e5da5Sopenharmony_ci%ld = OpLoad %int %var 1275fd4e5da5Sopenharmony_ciOpControlBarrier %workgroup %workgroup %none 1276fd4e5da5Sopenharmony_ciOpStore %var %ld 1277fd4e5da5Sopenharmony_ciOpReturn 1278fd4e5da5Sopenharmony_ciOpFunctionEnd 1279fd4e5da5Sopenharmony_ci)"; 1280fd4e5da5Sopenharmony_ci 1281fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1282fd4e5da5Sopenharmony_ci} 1283fd4e5da5Sopenharmony_ci 1284fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, 1285fd4e5da5Sopenharmony_ci TessellationControlBarrierAddOutputDifferentFunctions) { 1286fd4e5da5Sopenharmony_ci const std::string text = R"( 1287fd4e5da5Sopenharmony_ci; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2 1288fd4e5da5Sopenharmony_ci; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096 1289fd4e5da5Sopenharmony_ci; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]] 1290fd4e5da5Sopenharmony_ciOpCapability Tessellation 1291fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1292fd4e5da5Sopenharmony_ciOpEntryPoint TessellationControl %func "func" %var 1293fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1294fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1295fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1296fd4e5da5Sopenharmony_ci%workgroup = OpConstant %int 2 1297fd4e5da5Sopenharmony_ci%ptr_int_Output = OpTypePointer Output %int 1298fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_Output Output 1299fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1300fd4e5da5Sopenharmony_ci%ld_func_ty = OpTypeFunction %int 1301fd4e5da5Sopenharmony_ci%st_func_ty = OpTypeFunction %void %int 1302fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1303fd4e5da5Sopenharmony_ci%1 = OpLabel 1304fd4e5da5Sopenharmony_ci%call_ld = OpFunctionCall %int %ld_func 1305fd4e5da5Sopenharmony_ci%call_barrier = OpFunctionCall %void %barrier_func 1306fd4e5da5Sopenharmony_ci%call_st = OpFunctionCall %void %st_func %call_ld 1307fd4e5da5Sopenharmony_ciOpReturn 1308fd4e5da5Sopenharmony_ciOpFunctionEnd 1309fd4e5da5Sopenharmony_ci%ld_func = OpFunction %int None %ld_func_ty 1310fd4e5da5Sopenharmony_ci%2 = OpLabel 1311fd4e5da5Sopenharmony_ci%ld = OpLoad %int %var 1312fd4e5da5Sopenharmony_ciOpReturnValue %ld 1313fd4e5da5Sopenharmony_ciOpFunctionEnd 1314fd4e5da5Sopenharmony_ci%barrier_func = OpFunction %void None %func_ty 1315fd4e5da5Sopenharmony_ci%3 = OpLabel 1316fd4e5da5Sopenharmony_ciOpControlBarrier %workgroup %workgroup %none 1317fd4e5da5Sopenharmony_ciOpReturn 1318fd4e5da5Sopenharmony_ciOpFunctionEnd 1319fd4e5da5Sopenharmony_ci%st_func = OpFunction %void None %st_func_ty 1320fd4e5da5Sopenharmony_ci%param = OpFunctionParameter %int 1321fd4e5da5Sopenharmony_ci%4 = OpLabel 1322fd4e5da5Sopenharmony_ciOpStore %var %param 1323fd4e5da5Sopenharmony_ciOpReturn 1324fd4e5da5Sopenharmony_ciOpFunctionEnd 1325fd4e5da5Sopenharmony_ci)"; 1326fd4e5da5Sopenharmony_ci 1327fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1328fd4e5da5Sopenharmony_ci} 1329fd4e5da5Sopenharmony_ci 1330fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, ChangeControlBarrierMemoryScope) { 1331fd4e5da5Sopenharmony_ci std::string text = R"( 1332fd4e5da5Sopenharmony_ci; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2 1333fd4e5da5Sopenharmony_ci; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5 1334fd4e5da5Sopenharmony_ci; CHECK: OpControlBarrier [[workgroup]] [[queuefamily]] 1335fd4e5da5Sopenharmony_ciOpCapability Shader 1336fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1337fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1338fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1339fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1340fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1341fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 1342fd4e5da5Sopenharmony_ci%workgroup = OpConstant %int 2 1343fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1344fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1345fd4e5da5Sopenharmony_ci%1 = OpLabel 1346fd4e5da5Sopenharmony_ciOpControlBarrier %workgroup %device %none 1347fd4e5da5Sopenharmony_ciOpReturn 1348fd4e5da5Sopenharmony_ciOpFunctionEnd 1349fd4e5da5Sopenharmony_ci)"; 1350fd4e5da5Sopenharmony_ci 1351fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1352fd4e5da5Sopenharmony_ci} 1353fd4e5da5Sopenharmony_ci 1354fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, ChangeMemoryBarrierMemoryScope) { 1355fd4e5da5Sopenharmony_ci std::string text = R"( 1356fd4e5da5Sopenharmony_ci; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5 1357fd4e5da5Sopenharmony_ci; CHECK: OpMemoryBarrier [[queuefamily]] 1358fd4e5da5Sopenharmony_ciOpCapability Shader 1359fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1360fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1361fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1362fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1363fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1364fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 1365fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1366fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1367fd4e5da5Sopenharmony_ci%1 = OpLabel 1368fd4e5da5Sopenharmony_ciOpMemoryBarrier %device %none 1369fd4e5da5Sopenharmony_ciOpReturn 1370fd4e5da5Sopenharmony_ciOpFunctionEnd 1371fd4e5da5Sopenharmony_ci)"; 1372fd4e5da5Sopenharmony_ci 1373fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1374fd4e5da5Sopenharmony_ci} 1375fd4e5da5Sopenharmony_ci 1376fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, ChangeAtomicMemoryScope) { 1377fd4e5da5Sopenharmony_ci std::string text = R"( 1378fd4e5da5Sopenharmony_ci; CHECK: [[int:%\w+]] = OpTypeInt 1379fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable 1380fd4e5da5Sopenharmony_ci; CHECK: [[qf:%\w+]] = OpConstant [[int]] 5 1381fd4e5da5Sopenharmony_ci; CHECK: OpAtomicLoad [[int]] [[var]] [[qf]] 1382fd4e5da5Sopenharmony_ci; CHECK: OpAtomicStore [[var]] [[qf]] 1383fd4e5da5Sopenharmony_ci; CHECK: OpAtomicExchange [[int]] [[var]] [[qf]] 1384fd4e5da5Sopenharmony_ci; CHECK: OpAtomicCompareExchange [[int]] [[var]] [[qf]] 1385fd4e5da5Sopenharmony_ci; CHECK: OpAtomicIIncrement [[int]] [[var]] [[qf]] 1386fd4e5da5Sopenharmony_ci; CHECK: OpAtomicIDecrement [[int]] [[var]] [[qf]] 1387fd4e5da5Sopenharmony_ci; CHECK: OpAtomicIAdd [[int]] [[var]] [[qf]] 1388fd4e5da5Sopenharmony_ci; CHECK: OpAtomicISub [[int]] [[var]] [[qf]] 1389fd4e5da5Sopenharmony_ci; CHECK: OpAtomicSMin [[int]] [[var]] [[qf]] 1390fd4e5da5Sopenharmony_ci; CHECK: OpAtomicSMax [[int]] [[var]] [[qf]] 1391fd4e5da5Sopenharmony_ci; CHECK: OpAtomicUMin [[int]] [[var]] [[qf]] 1392fd4e5da5Sopenharmony_ci; CHECK: OpAtomicUMax [[int]] [[var]] [[qf]] 1393fd4e5da5Sopenharmony_ci; CHECK: OpAtomicAnd [[int]] [[var]] [[qf]] 1394fd4e5da5Sopenharmony_ci; CHECK: OpAtomicOr [[int]] [[var]] [[qf]] 1395fd4e5da5Sopenharmony_ci; CHECK: OpAtomicXor [[int]] [[var]] [[qf]] 1396fd4e5da5Sopenharmony_ciOpCapability Shader 1397fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 1398fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1399fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1400fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1401fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1402fd4e5da5Sopenharmony_ci%none = OpConstant %int 0 1403fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 1404fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1405fd4e5da5Sopenharmony_ci%ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int 1406fd4e5da5Sopenharmony_ci%var = OpVariable %ptr_int_StorageBuffer StorageBuffer 1407fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1408fd4e5da5Sopenharmony_ci%1 = OpLabel 1409fd4e5da5Sopenharmony_ci%ld = OpAtomicLoad %int %var %device %none 1410fd4e5da5Sopenharmony_ciOpAtomicStore %var %device %none %ld 1411fd4e5da5Sopenharmony_ci%ex = OpAtomicExchange %int %var %device %none %ld 1412fd4e5da5Sopenharmony_ci%cmp_ex = OpAtomicCompareExchange %int %var %device %none %none %ld %ld 1413fd4e5da5Sopenharmony_ci%inc = OpAtomicIIncrement %int %var %device %none 1414fd4e5da5Sopenharmony_ci%dec = OpAtomicIDecrement %int %var %device %none 1415fd4e5da5Sopenharmony_ci%add = OpAtomicIAdd %int %var %device %none %ld 1416fd4e5da5Sopenharmony_ci%sub = OpAtomicISub %int %var %device %none %ld 1417fd4e5da5Sopenharmony_ci%smin = OpAtomicSMin %int %var %device %none %ld 1418fd4e5da5Sopenharmony_ci%smax = OpAtomicSMax %int %var %device %none %ld 1419fd4e5da5Sopenharmony_ci%umin = OpAtomicUMin %int %var %device %none %ld 1420fd4e5da5Sopenharmony_ci%umax = OpAtomicUMax %int %var %device %none %ld 1421fd4e5da5Sopenharmony_ci%and = OpAtomicAnd %int %var %device %none %ld 1422fd4e5da5Sopenharmony_ci%or = OpAtomicOr %int %var %device %none %ld 1423fd4e5da5Sopenharmony_ci%xor = OpAtomicXor %int %var %device %none %ld 1424fd4e5da5Sopenharmony_ciOpReturn 1425fd4e5da5Sopenharmony_ciOpFunctionEnd 1426fd4e5da5Sopenharmony_ci)"; 1427fd4e5da5Sopenharmony_ci 1428fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1429fd4e5da5Sopenharmony_ci} 1430fd4e5da5Sopenharmony_ci 1431fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeModfNoFlags) { 1432fd4e5da5Sopenharmony_ci const std::string text = R"( 1433fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1434fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1435fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]] 1436fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer 1437fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]] 1438fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]] 1439fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1440fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1 1441fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] 1442fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 1443fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1444fd4e5da5Sopenharmony_ciOpCapability Shader 1445fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1446fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1447fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1448fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1449fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1450fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1451fd4e5da5Sopenharmony_ci%ptr_ssbo_float = OpTypePointer StorageBuffer %float 1452fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer 1453fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1454fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1455fd4e5da5Sopenharmony_ci%1 = OpLabel 1456fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Modf %float_0 %ssbo_var 1457fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1458fd4e5da5Sopenharmony_ciOpReturn 1459fd4e5da5Sopenharmony_ciOpFunctionEnd 1460fd4e5da5Sopenharmony_ci)"; 1461fd4e5da5Sopenharmony_ci 1462fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1463fd4e5da5Sopenharmony_ci} 1464fd4e5da5Sopenharmony_ci 1465fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeModfWorkgroupCoherent) { 1466fd4e5da5Sopenharmony_ci const std::string text = R"( 1467fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1468fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1469fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[float]] 1470fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup 1471fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]] 1472fd4e5da5Sopenharmony_ci; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2 1473fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]] 1474fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1475fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1 1476fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[wg_scope]] 1477fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1478fd4e5da5Sopenharmony_ciOpCapability Shader 1479fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1480fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1481fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1482fd4e5da5Sopenharmony_ciOpDecorate %wg_var Coherent 1483fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1484fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1485fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1486fd4e5da5Sopenharmony_ci%ptr_wg_float = OpTypePointer Workgroup %float 1487fd4e5da5Sopenharmony_ci%wg_var = OpVariable %ptr_wg_float Workgroup 1488fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1489fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1490fd4e5da5Sopenharmony_ci%1 = OpLabel 1491fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Modf %float_0 %wg_var 1492fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1493fd4e5da5Sopenharmony_ciOpReturn 1494fd4e5da5Sopenharmony_ciOpFunctionEnd 1495fd4e5da5Sopenharmony_ci)"; 1496fd4e5da5Sopenharmony_ci 1497fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1498fd4e5da5Sopenharmony_ci} 1499fd4e5da5Sopenharmony_ci 1500fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOCoherent) { 1501fd4e5da5Sopenharmony_ci const std::string text = R"( 1502fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1503fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1504fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]] 1505fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer 1506fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]] 1507fd4e5da5Sopenharmony_ci; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5 1508fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]] 1509fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1510fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1 1511fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[qf_scope]] 1512fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1513fd4e5da5Sopenharmony_ciOpCapability Shader 1514fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1515fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1516fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1517fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Coherent 1518fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1519fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1520fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1521fd4e5da5Sopenharmony_ci%ptr_ssbo_float = OpTypePointer StorageBuffer %float 1522fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer 1523fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1524fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1525fd4e5da5Sopenharmony_ci%1 = OpLabel 1526fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Modf %float_0 %ssbo_var 1527fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1528fd4e5da5Sopenharmony_ciOpReturn 1529fd4e5da5Sopenharmony_ciOpFunctionEnd 1530fd4e5da5Sopenharmony_ci)"; 1531fd4e5da5Sopenharmony_ci 1532fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1533fd4e5da5Sopenharmony_ci} 1534fd4e5da5Sopenharmony_ci 1535fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOVolatile) { 1536fd4e5da5Sopenharmony_ci const std::string text = R"( 1537fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1538fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1539fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]] 1540fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer 1541fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]] 1542fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]] 1543fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1544fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1 1545fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] Volatile 1546fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1547fd4e5da5Sopenharmony_ciOpCapability Shader 1548fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1549fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1550fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1551fd4e5da5Sopenharmony_ciOpDecorate %wg_var Volatile 1552fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1553fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1554fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1555fd4e5da5Sopenharmony_ci%ptr_ssbo_float = OpTypePointer StorageBuffer %float 1556fd4e5da5Sopenharmony_ci%wg_var = OpVariable %ptr_ssbo_float StorageBuffer 1557fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1558fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1559fd4e5da5Sopenharmony_ci%1 = OpLabel 1560fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Modf %float_0 %wg_var 1561fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1562fd4e5da5Sopenharmony_ciOpReturn 1563fd4e5da5Sopenharmony_ciOpFunctionEnd 1564fd4e5da5Sopenharmony_ci)"; 1565fd4e5da5Sopenharmony_ci 1566fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1567fd4e5da5Sopenharmony_ci} 1568fd4e5da5Sopenharmony_ci 1569fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeFrexpNoFlags) { 1570fd4e5da5Sopenharmony_ci const std::string text = R"( 1571fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1572fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1573fd4e5da5Sopenharmony_ci; CHECK: [[int:%\w+]] = OpTypeInt 32 0 1574fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]] 1575fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer 1576fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]] 1577fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]] 1578fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1579fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1 1580fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] 1581fd4e5da5Sopenharmony_ci; CHECK-NOT: NonPrivatePointer 1582fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1583fd4e5da5Sopenharmony_ciOpCapability Shader 1584fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1585fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1586fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1587fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1588fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1589fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1590fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1591fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1592fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 1593fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1594fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1595fd4e5da5Sopenharmony_ci%1 = OpLabel 1596fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Frexp %float_0 %ssbo_var 1597fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1598fd4e5da5Sopenharmony_ciOpReturn 1599fd4e5da5Sopenharmony_ciOpFunctionEnd 1600fd4e5da5Sopenharmony_ci)"; 1601fd4e5da5Sopenharmony_ci 1602fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1603fd4e5da5Sopenharmony_ci} 1604fd4e5da5Sopenharmony_ci 1605fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeFrexpWorkgroupCoherent) { 1606fd4e5da5Sopenharmony_ci const std::string text = R"( 1607fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1608fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1609fd4e5da5Sopenharmony_ci; CHECK: [[int:%\w+]] = OpTypeInt 32 0 1610fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[int]] 1611fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup 1612fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]] 1613fd4e5da5Sopenharmony_ci; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2 1614fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]] 1615fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1616fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1 1617fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[wg_scope]] 1618fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1619fd4e5da5Sopenharmony_ciOpCapability Shader 1620fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1621fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1622fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1623fd4e5da5Sopenharmony_ciOpDecorate %wg_var Coherent 1624fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1625fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1626fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1627fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1628fd4e5da5Sopenharmony_ci%ptr_wg_int = OpTypePointer Workgroup %int 1629fd4e5da5Sopenharmony_ci%wg_var = OpVariable %ptr_wg_int Workgroup 1630fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1631fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1632fd4e5da5Sopenharmony_ci%1 = OpLabel 1633fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Frexp %float_0 %wg_var 1634fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1635fd4e5da5Sopenharmony_ciOpReturn 1636fd4e5da5Sopenharmony_ciOpFunctionEnd 1637fd4e5da5Sopenharmony_ci)"; 1638fd4e5da5Sopenharmony_ci 1639fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1640fd4e5da5Sopenharmony_ci} 1641fd4e5da5Sopenharmony_ci 1642fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOCoherent) { 1643fd4e5da5Sopenharmony_ci const std::string text = R"( 1644fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1645fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1646fd4e5da5Sopenharmony_ci; CHECK: [[int:%\w+]] = OpTypeInt 32 0 1647fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]] 1648fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer 1649fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]] 1650fd4e5da5Sopenharmony_ci; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5 1651fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]] 1652fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1653fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1 1654fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[qf_scope]] 1655fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1656fd4e5da5Sopenharmony_ciOpCapability Shader 1657fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1658fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1659fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1660fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Coherent 1661fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1662fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1663fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1664fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1665fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1666fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 1667fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1668fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1669fd4e5da5Sopenharmony_ci%1 = OpLabel 1670fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Frexp %float_0 %ssbo_var 1671fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1672fd4e5da5Sopenharmony_ciOpReturn 1673fd4e5da5Sopenharmony_ciOpFunctionEnd 1674fd4e5da5Sopenharmony_ci)"; 1675fd4e5da5Sopenharmony_ci 1676fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1677fd4e5da5Sopenharmony_ci} 1678fd4e5da5Sopenharmony_ci 1679fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOVolatile) { 1680fd4e5da5Sopenharmony_ci const std::string text = R"( 1681fd4e5da5Sopenharmony_ci; CHECK: [[float:%\w+]] = OpTypeFloat 32 1682fd4e5da5Sopenharmony_ci; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0 1683fd4e5da5Sopenharmony_ci; CHECK: [[int:%\w+]] = OpTypeInt 32 0 1684fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]] 1685fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer 1686fd4e5da5Sopenharmony_ci; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]] 1687fd4e5da5Sopenharmony_ci; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]] 1688fd4e5da5Sopenharmony_ci; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0 1689fd4e5da5Sopenharmony_ci; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1 1690fd4e5da5Sopenharmony_ci; CHECK: OpStore [[var]] [[ex1]] Volatile 1691fd4e5da5Sopenharmony_ci; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]] 1692fd4e5da5Sopenharmony_ciOpCapability Shader 1693fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1694fd4e5da5Sopenharmony_ci%import = OpExtInstImport "GLSL.std.450" 1695fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" 1696fd4e5da5Sopenharmony_ciOpDecorate %wg_var Volatile 1697fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1698fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1699fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1700fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1701fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1702fd4e5da5Sopenharmony_ci%wg_var = OpVariable %ptr_ssbo_int StorageBuffer 1703fd4e5da5Sopenharmony_ci%func_ty = OpTypeFunction %void 1704fd4e5da5Sopenharmony_ci%func = OpFunction %void None %func_ty 1705fd4e5da5Sopenharmony_ci%1 = OpLabel 1706fd4e5da5Sopenharmony_ci%2 = OpExtInst %float %import Frexp %float_0 %wg_var 1707fd4e5da5Sopenharmony_ci%3 = OpFAdd %float %float_0 %2 1708fd4e5da5Sopenharmony_ciOpReturn 1709fd4e5da5Sopenharmony_ciOpFunctionEnd 1710fd4e5da5Sopenharmony_ci)"; 1711fd4e5da5Sopenharmony_ci 1712fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1713fd4e5da5Sopenharmony_ci} 1714fd4e5da5Sopenharmony_ci 1715fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14NormalizeCopyMemoryAddOperands) { 1716fd4e5da5Sopenharmony_ci const std::string text = R"( 1717fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} None None 1718fd4e5da5Sopenharmony_ciOpCapability Shader 1719fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1720fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1721fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1722fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1723fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1724fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1725fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1726fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1727fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1728fd4e5da5Sopenharmony_ci%entry = OpLabel 1729fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src 1730fd4e5da5Sopenharmony_ciOpReturn 1731fd4e5da5Sopenharmony_ciOpFunctionEnd 1732fd4e5da5Sopenharmony_ci)"; 1733fd4e5da5Sopenharmony_ci 1734fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1735fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1736fd4e5da5Sopenharmony_ci} 1737fd4e5da5Sopenharmony_ci 1738fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14NormalizeCopyMemoryDuplicateOperand) { 1739fd4e5da5Sopenharmony_ci const std::string text = R"( 1740fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Nontemporal Nontemporal 1741fd4e5da5Sopenharmony_ciOpCapability Shader 1742fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1743fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1744fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1745fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1746fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1747fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1748fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1749fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1750fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1751fd4e5da5Sopenharmony_ci%entry = OpLabel 1752fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src Nontemporal 1753fd4e5da5Sopenharmony_ciOpReturn 1754fd4e5da5Sopenharmony_ciOpFunctionEnd 1755fd4e5da5Sopenharmony_ci)"; 1756fd4e5da5Sopenharmony_ci 1757fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1758fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1759fd4e5da5Sopenharmony_ci} 1760fd4e5da5Sopenharmony_ci 1761fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14NormalizeCopyMemoryDuplicateOperands) { 1762fd4e5da5Sopenharmony_ci const std::string text = R"( 1763fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned 4 Aligned 4 1764fd4e5da5Sopenharmony_ciOpCapability Shader 1765fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1766fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1767fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1768fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1769fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1770fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1771fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1772fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1773fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1774fd4e5da5Sopenharmony_ci%entry = OpLabel 1775fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src Aligned 4 1776fd4e5da5Sopenharmony_ciOpReturn 1777fd4e5da5Sopenharmony_ciOpFunctionEnd 1778fd4e5da5Sopenharmony_ci)"; 1779fd4e5da5Sopenharmony_ci 1780fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1781fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1782fd4e5da5Sopenharmony_ci} 1783fd4e5da5Sopenharmony_ci 1784fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryDstCoherent) { 1785fd4e5da5Sopenharmony_ci const std::string text = R"( 1786fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1787fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] None 1788fd4e5da5Sopenharmony_ciOpCapability Shader 1789fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1790fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1791fd4e5da5Sopenharmony_ciOpDecorate %dst Coherent 1792fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1793fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1794fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1795fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1796fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1797fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1798fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1799fd4e5da5Sopenharmony_ci%entry = OpLabel 1800fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src 1801fd4e5da5Sopenharmony_ciOpReturn 1802fd4e5da5Sopenharmony_ciOpFunctionEnd 1803fd4e5da5Sopenharmony_ci)"; 1804fd4e5da5Sopenharmony_ci 1805fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1806fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1807fd4e5da5Sopenharmony_ci} 1808fd4e5da5Sopenharmony_ci 1809fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryDstCoherentPreviousArgs) { 1810fd4e5da5Sopenharmony_ci const std::string text = R"( 1811fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1812fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned|MakePointerAvailable|NonPrivatePointer 4 [[scope]] Aligned 4 1813fd4e5da5Sopenharmony_ciOpCapability Shader 1814fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1815fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1816fd4e5da5Sopenharmony_ciOpDecorate %dst Coherent 1817fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1818fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1819fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1820fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1821fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1822fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1823fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1824fd4e5da5Sopenharmony_ci%entry = OpLabel 1825fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src Aligned 4 1826fd4e5da5Sopenharmony_ciOpReturn 1827fd4e5da5Sopenharmony_ciOpFunctionEnd 1828fd4e5da5Sopenharmony_ci)"; 1829fd4e5da5Sopenharmony_ci 1830fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1831fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1832fd4e5da5Sopenharmony_ci} 1833fd4e5da5Sopenharmony_ci 1834fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemorySrcCoherent) { 1835fd4e5da5Sopenharmony_ci const std::string text = R"( 1836fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1837fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} None MakePointerVisible|NonPrivatePointer [[scope]] 1838fd4e5da5Sopenharmony_ciOpCapability Shader 1839fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1840fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1841fd4e5da5Sopenharmony_ciOpDecorate %src Coherent 1842fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1843fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1844fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1845fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1846fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1847fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1848fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1849fd4e5da5Sopenharmony_ci%entry = OpLabel 1850fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src 1851fd4e5da5Sopenharmony_ciOpReturn 1852fd4e5da5Sopenharmony_ciOpFunctionEnd 1853fd4e5da5Sopenharmony_ci)"; 1854fd4e5da5Sopenharmony_ci 1855fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1856fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1857fd4e5da5Sopenharmony_ci} 1858fd4e5da5Sopenharmony_ci 1859fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemorySrcCoherentPreviousArgs) { 1860fd4e5da5Sopenharmony_ci const std::string text = R"( 1861fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1862fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned 4 Aligned|MakePointerVisible|NonPrivatePointer 4 [[scope]] 1863fd4e5da5Sopenharmony_ciOpCapability Shader 1864fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1865fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1866fd4e5da5Sopenharmony_ciOpDecorate %src Coherent 1867fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1868fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1869fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1870fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1871fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1872fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1873fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1874fd4e5da5Sopenharmony_ci%entry = OpLabel 1875fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src Aligned 4 1876fd4e5da5Sopenharmony_ciOpReturn 1877fd4e5da5Sopenharmony_ciOpFunctionEnd 1878fd4e5da5Sopenharmony_ci)"; 1879fd4e5da5Sopenharmony_ci 1880fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1881fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1882fd4e5da5Sopenharmony_ci} 1883fd4e5da5Sopenharmony_ci 1884fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothCoherent) { 1885fd4e5da5Sopenharmony_ci const std::string text = R"( 1886fd4e5da5Sopenharmony_ci; CHECK-DAG: [[queue:%\w+]] = OpConstant {{%\w+}} 5 1887fd4e5da5Sopenharmony_ci; CHECK-DAG: [[wg:%\w+]] = OpConstant {{%\w+}} 2 1888fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[wg]] MakePointerVisible|NonPrivatePointer [[queue]] 1889fd4e5da5Sopenharmony_ciOpCapability Shader 1890fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1891fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1892fd4e5da5Sopenharmony_ciOpDecorate %src Coherent 1893fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1894fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1895fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1896fd4e5da5Sopenharmony_ci%ptr_wg_int = OpTypePointer Workgroup %int 1897fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1898fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_wg_int Workgroup 1899fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1900fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1901fd4e5da5Sopenharmony_ci%entry = OpLabel 1902fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src 1903fd4e5da5Sopenharmony_ciOpReturn 1904fd4e5da5Sopenharmony_ciOpFunctionEnd 1905fd4e5da5Sopenharmony_ci)"; 1906fd4e5da5Sopenharmony_ci 1907fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1908fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1909fd4e5da5Sopenharmony_ci} 1910fd4e5da5Sopenharmony_ci 1911fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothCoherentPreviousArgs) { 1912fd4e5da5Sopenharmony_ci const std::string text = R"( 1913fd4e5da5Sopenharmony_ci; CHECK-DAG: [[queue:%\w+]] = OpConstant {{%\w+}} 5 1914fd4e5da5Sopenharmony_ci; CHECK-DAG: [[wg:%\w+]] = OpConstant {{%\w+}} 2 1915fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned|MakePointerAvailable|NonPrivatePointer 4 [[queue]] Aligned|MakePointerVisible|NonPrivatePointer 4 [[wg]] 1916fd4e5da5Sopenharmony_ciOpCapability Shader 1917fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1918fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1919fd4e5da5Sopenharmony_ciOpDecorate %dst Coherent 1920fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1921fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1922fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1923fd4e5da5Sopenharmony_ci%ptr_wg_int = OpTypePointer Workgroup %int 1924fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_wg_int Workgroup 1925fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1926fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1927fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1928fd4e5da5Sopenharmony_ci%entry = OpLabel 1929fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src Aligned 4 1930fd4e5da5Sopenharmony_ciOpReturn 1931fd4e5da5Sopenharmony_ciOpFunctionEnd 1932fd4e5da5Sopenharmony_ci)"; 1933fd4e5da5Sopenharmony_ci 1934fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1935fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1936fd4e5da5Sopenharmony_ci} 1937fd4e5da5Sopenharmony_ci 1938fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothVolatile) { 1939fd4e5da5Sopenharmony_ci const std::string text = R"( 1940fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile Volatile 1941fd4e5da5Sopenharmony_ciOpCapability Shader 1942fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1943fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1944fd4e5da5Sopenharmony_ciOpDecorate %src Volatile 1945fd4e5da5Sopenharmony_ciOpDecorate %dst Volatile 1946fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1947fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1948fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1949fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1950fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1951fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1952fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1953fd4e5da5Sopenharmony_ci%entry = OpLabel 1954fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src 1955fd4e5da5Sopenharmony_ciOpReturn 1956fd4e5da5Sopenharmony_ciOpFunctionEnd 1957fd4e5da5Sopenharmony_ci)"; 1958fd4e5da5Sopenharmony_ci 1959fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1960fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1961fd4e5da5Sopenharmony_ci} 1962fd4e5da5Sopenharmony_ci 1963fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothVolatilePreviousArgs) { 1964fd4e5da5Sopenharmony_ci const std::string text = R"( 1965fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile|Aligned 4 Volatile|Aligned 4 1966fd4e5da5Sopenharmony_ciOpCapability Shader 1967fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1968fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1969fd4e5da5Sopenharmony_ciOpDecorate %src Volatile 1970fd4e5da5Sopenharmony_ciOpDecorate %dst Volatile 1971fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1972fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1973fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1974fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 1975fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 1976fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 1977fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 1978fd4e5da5Sopenharmony_ci%entry = OpLabel 1979fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src Aligned 4 1980fd4e5da5Sopenharmony_ciOpReturn 1981fd4e5da5Sopenharmony_ciOpFunctionEnd 1982fd4e5da5Sopenharmony_ci)"; 1983fd4e5da5Sopenharmony_ci 1984fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 1985fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 1986fd4e5da5Sopenharmony_ci} 1987fd4e5da5Sopenharmony_ci 1988fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryDstCoherentTwoOperands) { 1989fd4e5da5Sopenharmony_ci const std::string text = R"( 1990fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 1991fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] None 1992fd4e5da5Sopenharmony_ciOpCapability Shader 1993fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1994fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 1995fd4e5da5Sopenharmony_ciOpDecorate %dst Coherent 1996fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1997fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1998fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 1999fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 2000fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 2001fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2002fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2003fd4e5da5Sopenharmony_ci%entry = OpLabel 2004fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src None None 2005fd4e5da5Sopenharmony_ciOpReturn 2006fd4e5da5Sopenharmony_ciOpFunctionEnd 2007fd4e5da5Sopenharmony_ci)"; 2008fd4e5da5Sopenharmony_ci 2009fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 2010fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2011fd4e5da5Sopenharmony_ci} 2012fd4e5da5Sopenharmony_ci 2013fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, 2014fd4e5da5Sopenharmony_ci SPV14CopyMemoryDstCoherentPreviousArgsTwoOperands) { 2015fd4e5da5Sopenharmony_ci const std::string text = R"( 2016fd4e5da5Sopenharmony_ci; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5 2017fd4e5da5Sopenharmony_ci; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned|MakePointerAvailable|NonPrivatePointer 4 [[scope]] Aligned 8 2018fd4e5da5Sopenharmony_ciOpCapability Shader 2019fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2020fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func" %src %dst 2021fd4e5da5Sopenharmony_ciOpDecorate %dst Coherent 2022fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2023fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2024fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2025fd4e5da5Sopenharmony_ci%src = OpVariable %ptr_ssbo_int StorageBuffer 2026fd4e5da5Sopenharmony_ci%dst = OpVariable %ptr_ssbo_int StorageBuffer 2027fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2028fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2029fd4e5da5Sopenharmony_ci%entry = OpLabel 2030fd4e5da5Sopenharmony_ciOpCopyMemory %dst %src Aligned 4 Aligned 8 2031fd4e5da5Sopenharmony_ciOpReturn 2032fd4e5da5Sopenharmony_ciOpFunctionEnd 2033fd4e5da5Sopenharmony_ci)"; 2034fd4e5da5Sopenharmony_ci 2035fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 2036fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2037fd4e5da5Sopenharmony_ci} 2038fd4e5da5Sopenharmony_ci 2039fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileAtomicLoad) { 2040fd4e5da5Sopenharmony_ci const std::string text = R"( 2041fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{.*}} Volatile 2042fd4e5da5Sopenharmony_ci; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32768 2043fd4e5da5Sopenharmony_ci; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[volatile]] 2044fd4e5da5Sopenharmony_ciOpCapability Shader 2045fd4e5da5Sopenharmony_ciOpCapability Linkage 2046fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2047fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Volatile 2048fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2049fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2050fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 2051fd4e5da5Sopenharmony_ci%relaxed = OpConstant %int 0 2052fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2053fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 2054fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2055fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2056fd4e5da5Sopenharmony_ci%entry = OpLabel 2057fd4e5da5Sopenharmony_ci%ld = OpAtomicLoad %int %ssbo_var %device %relaxed 2058fd4e5da5Sopenharmony_ciOpReturn 2059fd4e5da5Sopenharmony_ciOpFunctionEnd 2060fd4e5da5Sopenharmony_ci)"; 2061fd4e5da5Sopenharmony_ci 2062fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2063fd4e5da5Sopenharmony_ci} 2064fd4e5da5Sopenharmony_ci 2065fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileAtomicLoadPreviousFlags) { 2066fd4e5da5Sopenharmony_ci const std::string text = R"( 2067fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{.*}} Volatile 2068fd4e5da5Sopenharmony_ci; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32834 2069fd4e5da5Sopenharmony_ci; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[volatile]] 2070fd4e5da5Sopenharmony_ciOpCapability Shader 2071fd4e5da5Sopenharmony_ciOpCapability Linkage 2072fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2073fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Volatile 2074fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2075fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2076fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 2077fd4e5da5Sopenharmony_ci%acquire_ssbo = OpConstant %int 66 2078fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2079fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 2080fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2081fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2082fd4e5da5Sopenharmony_ci%entry = OpLabel 2083fd4e5da5Sopenharmony_ci%ld = OpAtomicLoad %int %ssbo_var %device %acquire_ssbo 2084fd4e5da5Sopenharmony_ciOpReturn 2085fd4e5da5Sopenharmony_ciOpFunctionEnd 2086fd4e5da5Sopenharmony_ci)"; 2087fd4e5da5Sopenharmony_ci 2088fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2089fd4e5da5Sopenharmony_ci} 2090fd4e5da5Sopenharmony_ci 2091fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileAtomicStore) { 2092fd4e5da5Sopenharmony_ci const std::string text = R"( 2093fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{.*}} Volatile 2094fd4e5da5Sopenharmony_ci; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant {{.*}} 32768 2095fd4e5da5Sopenharmony_ci; CHECK: OpAtomicStore {{.*}} {{.*}} [[volatile]] 2096fd4e5da5Sopenharmony_ciOpCapability Shader 2097fd4e5da5Sopenharmony_ciOpCapability Linkage 2098fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2099fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Volatile 2100fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2101fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2102fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 2103fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 2104fd4e5da5Sopenharmony_ci%relaxed = OpConstant %int 0 2105fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2106fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 2107fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2108fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2109fd4e5da5Sopenharmony_ci%entry = OpLabel 2110fd4e5da5Sopenharmony_ciOpAtomicStore %ssbo_var %device %relaxed %int_0 2111fd4e5da5Sopenharmony_ciOpReturn 2112fd4e5da5Sopenharmony_ciOpFunctionEnd 2113fd4e5da5Sopenharmony_ci)"; 2114fd4e5da5Sopenharmony_ci 2115fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2116fd4e5da5Sopenharmony_ci} 2117fd4e5da5Sopenharmony_ci 2118fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileAtomicStorePreviousFlags) { 2119fd4e5da5Sopenharmony_ci const std::string text = R"( 2120fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{.*}} Volatile 2121fd4e5da5Sopenharmony_ci; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant {{.*}} 32836 2122fd4e5da5Sopenharmony_ci; CHECK: OpAtomicStore {{.*}} {{.*}} [[volatile]] 2123fd4e5da5Sopenharmony_ciOpCapability Shader 2124fd4e5da5Sopenharmony_ciOpCapability Linkage 2125fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2126fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Volatile 2127fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2128fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2129fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 2130fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 2131fd4e5da5Sopenharmony_ci%release_ssbo = OpConstant %int 68 2132fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2133fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 2134fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2135fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2136fd4e5da5Sopenharmony_ci%entry = OpLabel 2137fd4e5da5Sopenharmony_ciOpAtomicStore %ssbo_var %device %release_ssbo %int_0 2138fd4e5da5Sopenharmony_ciOpReturn 2139fd4e5da5Sopenharmony_ciOpFunctionEnd 2140fd4e5da5Sopenharmony_ci)"; 2141fd4e5da5Sopenharmony_ci 2142fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2143fd4e5da5Sopenharmony_ci} 2144fd4e5da5Sopenharmony_ci 2145fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileAtomicCompareExchange) { 2146fd4e5da5Sopenharmony_ci const std::string text = R"( 2147fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{.*}} Volatile 2148fd4e5da5Sopenharmony_ci; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32768 2149fd4e5da5Sopenharmony_ci; CHECK: OpAtomicCompareExchange [[int]] {{.*}} {{.*}} [[volatile]] [[volatile]] 2150fd4e5da5Sopenharmony_ciOpCapability Shader 2151fd4e5da5Sopenharmony_ciOpCapability Linkage 2152fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2153fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Volatile 2154fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2155fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2156fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 2157fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 2158fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 2159fd4e5da5Sopenharmony_ci%relaxed = OpConstant %int 0 2160fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2161fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 2162fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2163fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2164fd4e5da5Sopenharmony_ci%entry = OpLabel 2165fd4e5da5Sopenharmony_ci%ld = OpAtomicCompareExchange %int %ssbo_var %device %relaxed %relaxed %int_0 %int_1 2166fd4e5da5Sopenharmony_ciOpReturn 2167fd4e5da5Sopenharmony_ciOpFunctionEnd 2168fd4e5da5Sopenharmony_ci)"; 2169fd4e5da5Sopenharmony_ci 2170fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2171fd4e5da5Sopenharmony_ci} 2172fd4e5da5Sopenharmony_ci 2173fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileAtomicCompareExchangePreviousFlags) { 2174fd4e5da5Sopenharmony_ci const std::string text = R"( 2175fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{.*}} Volatile 2176fd4e5da5Sopenharmony_ci; CHECK: [[volatile_acq_rel:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32840 2177fd4e5da5Sopenharmony_ci; CHECK: [[volatile_acq:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32834 2178fd4e5da5Sopenharmony_ci; CHECK: OpAtomicCompareExchange [[int]] {{.*}} {{.*}} [[volatile_acq_rel]] [[volatile_acq]] 2179fd4e5da5Sopenharmony_ciOpCapability Shader 2180fd4e5da5Sopenharmony_ciOpCapability Linkage 2181fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2182fd4e5da5Sopenharmony_ciOpDecorate %ssbo_var Volatile 2183fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2184fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2185fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 2186fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 2187fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 2188fd4e5da5Sopenharmony_ci%acq_ssbo = OpConstant %int 66 2189fd4e5da5Sopenharmony_ci%acq_rel_ssbo = OpConstant %int 72 2190fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2191fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer 2192fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2193fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2194fd4e5da5Sopenharmony_ci%entry = OpLabel 2195fd4e5da5Sopenharmony_ci%ld = OpAtomicCompareExchange %int %ssbo_var %device %acq_rel_ssbo %acq_ssbo %int_0 %int_1 2196fd4e5da5Sopenharmony_ciOpReturn 2197fd4e5da5Sopenharmony_ciOpFunctionEnd 2198fd4e5da5Sopenharmony_ci)"; 2199fd4e5da5Sopenharmony_ci 2200fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2201fd4e5da5Sopenharmony_ci} 2202fd4e5da5Sopenharmony_ci 2203fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, VolatileAtomicLoadMemberDecoration) { 2204fd4e5da5Sopenharmony_ci const std::string text = R"( 2205fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate {{.*}} {{.*}} Volatile 2206fd4e5da5Sopenharmony_ci; CHECK: [[relaxed:%[a-zA-Z0-9_]+]] = OpConstant {{.*}} 0 2207fd4e5da5Sopenharmony_ci; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32768 2208fd4e5da5Sopenharmony_ci; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[relaxed]] 2209fd4e5da5Sopenharmony_ci; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[volatile]] 2210fd4e5da5Sopenharmony_ciOpCapability Shader 2211fd4e5da5Sopenharmony_ciOpCapability Linkage 2212fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2213fd4e5da5Sopenharmony_ciOpMemberDecorate %struct 1 Volatile 2214fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2215fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2216fd4e5da5Sopenharmony_ci%device = OpConstant %int 1 2217fd4e5da5Sopenharmony_ci%relaxed = OpConstant %int 0 2218fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 2219fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 2220fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2221fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %int %int 2222fd4e5da5Sopenharmony_ci%ptr_ssbo_struct = OpTypePointer StorageBuffer %struct 2223fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_struct StorageBuffer 2224fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2225fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2226fd4e5da5Sopenharmony_ci%entry = OpLabel 2227fd4e5da5Sopenharmony_ci%gep0 = OpAccessChain %ptr_ssbo_int %ssbo_var %int_0 2228fd4e5da5Sopenharmony_ci%ld0 = OpAtomicLoad %int %gep0 %device %relaxed 2229fd4e5da5Sopenharmony_ci%gep1 = OpAccessChain %ptr_ssbo_int %ssbo_var %int_1 2230fd4e5da5Sopenharmony_ci%ld1 = OpAtomicLoad %int %gep1 %device %relaxed 2231fd4e5da5Sopenharmony_ciOpReturn 2232fd4e5da5Sopenharmony_ciOpFunctionEnd 2233fd4e5da5Sopenharmony_ci)"; 2234fd4e5da5Sopenharmony_ci 2235fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2236fd4e5da5Sopenharmony_ci} 2237fd4e5da5Sopenharmony_ci 2238fd4e5da5Sopenharmony_ciTEST_F(UpgradeMemoryModelTest, CoherentStructMemberInArray) { 2239fd4e5da5Sopenharmony_ci const std::string text = R"( 2240fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorate 2241fd4e5da5Sopenharmony_ci; CHECK: [[int:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 2242fd4e5da5Sopenharmony_ci; CHECK: [[device:%[a-zA-Z0-9_]+]] = OpConstant [[int]] 1 2243fd4e5da5Sopenharmony_ci; CHECK: OpLoad [[int]] {{.*}} MakePointerVisible|NonPrivatePointer 2244fd4e5da5Sopenharmony_ciOpCapability Shader 2245fd4e5da5Sopenharmony_ciOpCapability Linkage 2246fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 2247fd4e5da5Sopenharmony_ciOpMemberDecorate %inner 1 Coherent 2248fd4e5da5Sopenharmony_ci%void = OpTypeVoid 2249fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 2250fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 2251fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 2252fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4 2253fd4e5da5Sopenharmony_ci%inner = OpTypeStruct %int %int 2254fd4e5da5Sopenharmony_ci%array = OpTypeArray %inner %int_4 2255fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %array 2256fd4e5da5Sopenharmony_ci%ptr_ssbo_struct = OpTypePointer StorageBuffer %struct 2257fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2258fd4e5da5Sopenharmony_ci%ssbo_var = OpVariable %ptr_ssbo_struct StorageBuffer 2259fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2260fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2261fd4e5da5Sopenharmony_ci%entry = OpLabel 2262fd4e5da5Sopenharmony_ci%gep = OpAccessChain %ptr_ssbo_int %ssbo_var %int_0 %int_0 %int_1 2263fd4e5da5Sopenharmony_ci%ld = OpLoad %int %gep 2264fd4e5da5Sopenharmony_ciOpReturn 2265fd4e5da5Sopenharmony_ciOpFunctionEnd 2266fd4e5da5Sopenharmony_ci)"; 2267fd4e5da5Sopenharmony_ci 2268fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true); 2269fd4e5da5Sopenharmony_ci} 2270fd4e5da5Sopenharmony_ci 2271fd4e5da5Sopenharmony_ci} // namespace 2272