1fd4e5da5Sopenharmony_ci// Copyright (c) 2019 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 <string> 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h" 18fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h" 19fd4e5da5Sopenharmony_ci 20fd4e5da5Sopenharmony_cinamespace spvtools { 21fd4e5da5Sopenharmony_cinamespace opt { 22fd4e5da5Sopenharmony_cinamespace { 23fd4e5da5Sopenharmony_ci 24fd4e5da5Sopenharmony_ciusing FixStorageClassTest = PassTest<::testing::Test>; 25fd4e5da5Sopenharmony_ci 26fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, FixAccessChain) { 27fd4e5da5Sopenharmony_ci const std::string text = R"( 28fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup_float 29fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 30fd4e5da5Sopenharmony_ci OpCapability Shader 31fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 32fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID 33fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 34fd4e5da5Sopenharmony_ci OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId 35fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 36fd4e5da5Sopenharmony_ci OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId 37fd4e5da5Sopenharmony_ci OpDecorate %8 DescriptorSet 0 38fd4e5da5Sopenharmony_ci OpDecorate %8 Binding 0 39fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 40fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 41fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 42fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 43fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 44fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 45fd4e5da5Sopenharmony_ci %float_2 = OpConstant %float 2 46fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 47fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 48fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10 49fd4e5da5Sopenharmony_ci%ptr = OpTypePointer Function %_arr_float_uint_10 50fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 51fd4e5da5Sopenharmony_ci %_struct_5 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 52fd4e5da5Sopenharmony_ci%_ptr_Workgroup__struct_5 = OpTypePointer Workgroup %_struct_5 53fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 54fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 55fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 56fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 57fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 58fd4e5da5Sopenharmony_ci %void = OpTypeVoid 59fd4e5da5Sopenharmony_ci %30 = OpTypeFunction %void 60fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 61fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 62fd4e5da5Sopenharmony_ci %6 = OpVariable %_ptr_Workgroup__struct_5 Workgroup 63fd4e5da5Sopenharmony_ci %8 = OpVariable %_ptr_Uniform__struct_7 Uniform 64fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input 65fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 66fd4e5da5Sopenharmony_ci%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input 67fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %30 68fd4e5da5Sopenharmony_ci %38 = OpLabel 69fd4e5da5Sopenharmony_ci %44 = OpLoad %v3uint %gl_LocalInvocationID 70fd4e5da5Sopenharmony_ci %50 = OpAccessChain %_ptr_Function_float %6 %int_0 %int_0 %int_0 71fd4e5da5Sopenharmony_ci %51 = OpLoad %float %50 72fd4e5da5Sopenharmony_ci %52 = OpFMul %float %float_2 %51 73fd4e5da5Sopenharmony_ci OpStore %50 %52 74fd4e5da5Sopenharmony_ci %55 = OpLoad %float %50 75fd4e5da5Sopenharmony_ci %59 = OpCompositeExtract %uint %44 0 76fd4e5da5Sopenharmony_ci %60 = OpAccessChain %_ptr_Uniform_float %8 %int_0 %59 77fd4e5da5Sopenharmony_ci OpStore %60 %55 78fd4e5da5Sopenharmony_ci OpReturn 79fd4e5da5Sopenharmony_ci OpFunctionEnd 80fd4e5da5Sopenharmony_ci)"; 81fd4e5da5Sopenharmony_ci 82fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 83fd4e5da5Sopenharmony_ci} 84fd4e5da5Sopenharmony_ci 85fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, FixLinkedAccessChain) { 86fd4e5da5Sopenharmony_ci const std::string text = R"( 87fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup__arr_float_uint_10 88fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup_float 89fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 90fd4e5da5Sopenharmony_ci OpCapability Shader 91fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 92fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID 93fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 94fd4e5da5Sopenharmony_ci OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId 95fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 96fd4e5da5Sopenharmony_ci OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId 97fd4e5da5Sopenharmony_ci OpDecorate %5 DescriptorSet 0 98fd4e5da5Sopenharmony_ci OpDecorate %5 Binding 0 99fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 100fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 101fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 102fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 103fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 104fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 105fd4e5da5Sopenharmony_ci %float_2 = OpConstant %float 2 106fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 107fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 108fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10 109fd4e5da5Sopenharmony_ci%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 110fd4e5da5Sopenharmony_ci%_ptr = OpTypePointer Function %_arr_float_uint_10 111fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 112fd4e5da5Sopenharmony_ci %_struct_17 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 113fd4e5da5Sopenharmony_ci%_ptr_Workgroup__struct_17 = OpTypePointer Workgroup %_struct_17 114fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 115fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 116fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 117fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 118fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 119fd4e5da5Sopenharmony_ci %void = OpTypeVoid 120fd4e5da5Sopenharmony_ci %23 = OpTypeFunction %void 121fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 122fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 123fd4e5da5Sopenharmony_ci %27 = OpVariable %_ptr_Workgroup__struct_17 Workgroup 124fd4e5da5Sopenharmony_ci %5 = OpVariable %_ptr_Uniform__struct_7 Uniform 125fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input 126fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 127fd4e5da5Sopenharmony_ci%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input 128fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %23 129fd4e5da5Sopenharmony_ci %28 = OpLabel 130fd4e5da5Sopenharmony_ci %29 = OpLoad %v3uint %gl_LocalInvocationID 131fd4e5da5Sopenharmony_ci %30 = OpAccessChain %_ptr_Function__arr_float_uint_10 %27 %int_0 %int_0 132fd4e5da5Sopenharmony_ci %31 = OpAccessChain %_ptr_Function_float %30 %int_0 133fd4e5da5Sopenharmony_ci %32 = OpLoad %float %31 134fd4e5da5Sopenharmony_ci %33 = OpFMul %float %float_2 %32 135fd4e5da5Sopenharmony_ci OpStore %31 %33 136fd4e5da5Sopenharmony_ci %34 = OpLoad %float %31 137fd4e5da5Sopenharmony_ci %35 = OpCompositeExtract %uint %29 0 138fd4e5da5Sopenharmony_ci %36 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %35 139fd4e5da5Sopenharmony_ci OpStore %36 %34 140fd4e5da5Sopenharmony_ci OpReturn 141fd4e5da5Sopenharmony_ci OpFunctionEnd 142fd4e5da5Sopenharmony_ci)"; 143fd4e5da5Sopenharmony_ci 144fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 145fd4e5da5Sopenharmony_ci} 146fd4e5da5Sopenharmony_ci 147fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, FixCopyObject) { 148fd4e5da5Sopenharmony_ci const std::string text = R"( 149fd4e5da5Sopenharmony_ci; CHECK: OpCopyObject %_ptr_Workgroup__struct_17 150fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup_float 151fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 152fd4e5da5Sopenharmony_ci OpCapability Shader 153fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 154fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID 155fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 156fd4e5da5Sopenharmony_ci OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId 157fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 158fd4e5da5Sopenharmony_ci OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId 159fd4e5da5Sopenharmony_ci OpDecorate %8 DescriptorSet 0 160fd4e5da5Sopenharmony_ci OpDecorate %8 Binding 0 161fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 162fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 163fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 164fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 165fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 166fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 167fd4e5da5Sopenharmony_ci %float_2 = OpConstant %float 2 168fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 169fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 170fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10 171fd4e5da5Sopenharmony_ci%ptr = OpTypePointer Function %_arr_float_uint_10 172fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 173fd4e5da5Sopenharmony_ci %_struct_17 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 174fd4e5da5Sopenharmony_ci%_ptr_Workgroup__struct_17 = OpTypePointer Workgroup %_struct_17 175fd4e5da5Sopenharmony_ci%_ptr_Function__struct_17 = OpTypePointer Function %_struct_17 176fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 177fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 178fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 179fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 180fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 181fd4e5da5Sopenharmony_ci %void = OpTypeVoid 182fd4e5da5Sopenharmony_ci %30 = OpTypeFunction %void 183fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 184fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 185fd4e5da5Sopenharmony_ci %6 = OpVariable %_ptr_Workgroup__struct_17 Workgroup 186fd4e5da5Sopenharmony_ci %8 = OpVariable %_ptr_Uniform__struct_7 Uniform 187fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input 188fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 189fd4e5da5Sopenharmony_ci%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input 190fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %30 191fd4e5da5Sopenharmony_ci %38 = OpLabel 192fd4e5da5Sopenharmony_ci %44 = OpLoad %v3uint %gl_LocalInvocationID 193fd4e5da5Sopenharmony_ci %cp = OpCopyObject %_ptr_Function__struct_17 %6 194fd4e5da5Sopenharmony_ci %50 = OpAccessChain %_ptr_Function_float %cp %int_0 %int_0 %int_0 195fd4e5da5Sopenharmony_ci %51 = OpLoad %float %50 196fd4e5da5Sopenharmony_ci %52 = OpFMul %float %float_2 %51 197fd4e5da5Sopenharmony_ci OpStore %50 %52 198fd4e5da5Sopenharmony_ci %55 = OpLoad %float %50 199fd4e5da5Sopenharmony_ci %59 = OpCompositeExtract %uint %44 0 200fd4e5da5Sopenharmony_ci %60 = OpAccessChain %_ptr_Uniform_float %8 %int_0 %59 201fd4e5da5Sopenharmony_ci OpStore %60 %55 202fd4e5da5Sopenharmony_ci OpReturn 203fd4e5da5Sopenharmony_ci OpFunctionEnd 204fd4e5da5Sopenharmony_ci)"; 205fd4e5da5Sopenharmony_ci 206fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 207fd4e5da5Sopenharmony_ci} 208fd4e5da5Sopenharmony_ci 209fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, FixPhiInSelMerge) { 210fd4e5da5Sopenharmony_ci const std::string text = R"( 211fd4e5da5Sopenharmony_ci; CHECK: OpPhi %_ptr_Workgroup__struct_19 212fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup_float 213fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 214fd4e5da5Sopenharmony_ci OpCapability Shader 215fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 216fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID 217fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 218fd4e5da5Sopenharmony_ci OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId 219fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 220fd4e5da5Sopenharmony_ci OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId 221fd4e5da5Sopenharmony_ci OpDecorate %5 DescriptorSet 0 222fd4e5da5Sopenharmony_ci OpDecorate %5 Binding 0 223fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 224fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 225fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 226fd4e5da5Sopenharmony_ci %bool = OpTypeBool 227fd4e5da5Sopenharmony_ci %true = OpConstantTrue %bool 228fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 229fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 230fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 231fd4e5da5Sopenharmony_ci %float_2 = OpConstant %float 2 232fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 233fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 234fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10 235fd4e5da5Sopenharmony_ci%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 236fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 237fd4e5da5Sopenharmony_ci %_struct_19 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 238fd4e5da5Sopenharmony_ci%_ptr_Workgroup__struct_19 = OpTypePointer Workgroup %_struct_19 239fd4e5da5Sopenharmony_ci%_ptr_Function__struct_19 = OpTypePointer Function %_struct_19 240fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 241fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 242fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 243fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 244fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 245fd4e5da5Sopenharmony_ci %void = OpTypeVoid 246fd4e5da5Sopenharmony_ci %25 = OpTypeFunction %void 247fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 248fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 249fd4e5da5Sopenharmony_ci %28 = OpVariable %_ptr_Workgroup__struct_19 Workgroup 250fd4e5da5Sopenharmony_ci %29 = OpVariable %_ptr_Workgroup__struct_19 Workgroup 251fd4e5da5Sopenharmony_ci %5 = OpVariable %_ptr_Uniform__struct_7 Uniform 252fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input 253fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 254fd4e5da5Sopenharmony_ci%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input 255fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %25 256fd4e5da5Sopenharmony_ci %30 = OpLabel 257fd4e5da5Sopenharmony_ci OpSelectionMerge %31 None 258fd4e5da5Sopenharmony_ci OpBranchConditional %true %32 %31 259fd4e5da5Sopenharmony_ci %32 = OpLabel 260fd4e5da5Sopenharmony_ci OpBranch %31 261fd4e5da5Sopenharmony_ci %31 = OpLabel 262fd4e5da5Sopenharmony_ci %33 = OpPhi %_ptr_Function__struct_19 %28 %30 %29 %32 263fd4e5da5Sopenharmony_ci %34 = OpLoad %v3uint %gl_LocalInvocationID 264fd4e5da5Sopenharmony_ci %35 = OpAccessChain %_ptr_Function_float %33 %int_0 %int_0 %int_0 265fd4e5da5Sopenharmony_ci %36 = OpLoad %float %35 266fd4e5da5Sopenharmony_ci %37 = OpFMul %float %float_2 %36 267fd4e5da5Sopenharmony_ci OpStore %35 %37 268fd4e5da5Sopenharmony_ci %38 = OpLoad %float %35 269fd4e5da5Sopenharmony_ci %39 = OpCompositeExtract %uint %34 0 270fd4e5da5Sopenharmony_ci %40 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %39 271fd4e5da5Sopenharmony_ci OpStore %40 %38 272fd4e5da5Sopenharmony_ci OpReturn 273fd4e5da5Sopenharmony_ci OpFunctionEnd 274fd4e5da5Sopenharmony_ci)"; 275fd4e5da5Sopenharmony_ci 276fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 277fd4e5da5Sopenharmony_ci} 278fd4e5da5Sopenharmony_ci 279fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, FixPhiInLoop) { 280fd4e5da5Sopenharmony_ci const std::string text = R"( 281fd4e5da5Sopenharmony_ci; CHECK: OpPhi %_ptr_Workgroup__struct_19 282fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup_float 283fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 284fd4e5da5Sopenharmony_ci OpCapability Shader 285fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 286fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID 287fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 288fd4e5da5Sopenharmony_ci OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId 289fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 290fd4e5da5Sopenharmony_ci OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId 291fd4e5da5Sopenharmony_ci OpDecorate %5 DescriptorSet 0 292fd4e5da5Sopenharmony_ci OpDecorate %5 Binding 0 293fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 294fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 295fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 296fd4e5da5Sopenharmony_ci %bool = OpTypeBool 297fd4e5da5Sopenharmony_ci %true = OpConstantTrue %bool 298fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 299fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 300fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 301fd4e5da5Sopenharmony_ci %float_2 = OpConstant %float 2 302fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 303fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 304fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10 305fd4e5da5Sopenharmony_ci%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 306fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 307fd4e5da5Sopenharmony_ci %_struct_19 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 308fd4e5da5Sopenharmony_ci%_ptr_Workgroup__struct_19 = OpTypePointer Workgroup %_struct_19 309fd4e5da5Sopenharmony_ci%_ptr_Function__struct_19 = OpTypePointer Function %_struct_19 310fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 311fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 312fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 313fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 314fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 315fd4e5da5Sopenharmony_ci %void = OpTypeVoid 316fd4e5da5Sopenharmony_ci %25 = OpTypeFunction %void 317fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 318fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 319fd4e5da5Sopenharmony_ci %28 = OpVariable %_ptr_Workgroup__struct_19 Workgroup 320fd4e5da5Sopenharmony_ci %29 = OpVariable %_ptr_Workgroup__struct_19 Workgroup 321fd4e5da5Sopenharmony_ci %5 = OpVariable %_ptr_Uniform__struct_7 Uniform 322fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input 323fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 324fd4e5da5Sopenharmony_ci%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input 325fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %25 326fd4e5da5Sopenharmony_ci %30 = OpLabel 327fd4e5da5Sopenharmony_ci OpSelectionMerge %31 None 328fd4e5da5Sopenharmony_ci OpBranchConditional %true %32 %31 329fd4e5da5Sopenharmony_ci %32 = OpLabel 330fd4e5da5Sopenharmony_ci OpBranch %31 331fd4e5da5Sopenharmony_ci %31 = OpLabel 332fd4e5da5Sopenharmony_ci %33 = OpPhi %_ptr_Function__struct_19 %28 %30 %29 %32 333fd4e5da5Sopenharmony_ci %34 = OpLoad %v3uint %gl_LocalInvocationID 334fd4e5da5Sopenharmony_ci %35 = OpAccessChain %_ptr_Function_float %33 %int_0 %int_0 %int_0 335fd4e5da5Sopenharmony_ci %36 = OpLoad %float %35 336fd4e5da5Sopenharmony_ci %37 = OpFMul %float %float_2 %36 337fd4e5da5Sopenharmony_ci OpStore %35 %37 338fd4e5da5Sopenharmony_ci %38 = OpLoad %float %35 339fd4e5da5Sopenharmony_ci %39 = OpCompositeExtract %uint %34 0 340fd4e5da5Sopenharmony_ci %40 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %39 341fd4e5da5Sopenharmony_ci OpStore %40 %38 342fd4e5da5Sopenharmony_ci OpReturn 343fd4e5da5Sopenharmony_ci OpFunctionEnd 344fd4e5da5Sopenharmony_ci)"; 345fd4e5da5Sopenharmony_ci 346fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 347fd4e5da5Sopenharmony_ci} 348fd4e5da5Sopenharmony_ci 349fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, DontChangeFunctionCalls) { 350fd4e5da5Sopenharmony_ci const std::string text = R"(OpCapability Shader 351fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 352fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %1 "testMain" 353fd4e5da5Sopenharmony_ciOpExecutionMode %1 LocalSize 8 8 1 354fd4e5da5Sopenharmony_ciOpDecorate %2 DescriptorSet 0 355fd4e5da5Sopenharmony_ciOpDecorate %2 Binding 0 356fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 357fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int 358fd4e5da5Sopenharmony_ci%_ptr_Workgroup_int = OpTypePointer Workgroup %int 359fd4e5da5Sopenharmony_ci%_ptr_Uniform_int = OpTypePointer Uniform %int 360fd4e5da5Sopenharmony_ci%void = OpTypeVoid 361fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void 362fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %_ptr_Uniform_int %_ptr_Function_int 363fd4e5da5Sopenharmony_ci%10 = OpVariable %_ptr_Workgroup_int Workgroup 364fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Uniform_int Uniform 365fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %8 366fd4e5da5Sopenharmony_ci%11 = OpLabel 367fd4e5da5Sopenharmony_ci%12 = OpFunctionCall %_ptr_Uniform_int %13 %10 368fd4e5da5Sopenharmony_ciOpReturn 369fd4e5da5Sopenharmony_ciOpFunctionEnd 370fd4e5da5Sopenharmony_ci%13 = OpFunction %_ptr_Uniform_int None %9 371fd4e5da5Sopenharmony_ci%14 = OpFunctionParameter %_ptr_Function_int 372fd4e5da5Sopenharmony_ci%15 = OpLabel 373fd4e5da5Sopenharmony_ciOpReturnValue %2 374fd4e5da5Sopenharmony_ciOpFunctionEnd 375fd4e5da5Sopenharmony_ci)"; 376fd4e5da5Sopenharmony_ci 377fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<FixStorageClass>(text, text, false, false); 378fd4e5da5Sopenharmony_ci} 379fd4e5da5Sopenharmony_ci 380fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, FixSelect) { 381fd4e5da5Sopenharmony_ci const std::string text = R"( 382fd4e5da5Sopenharmony_ci; CHECK: OpSelect %_ptr_Workgroup__struct_19 383fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup_float 384fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 385fd4e5da5Sopenharmony_ci OpCapability Shader 386fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 387fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID 388fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 389fd4e5da5Sopenharmony_ci OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId 390fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 391fd4e5da5Sopenharmony_ci OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId 392fd4e5da5Sopenharmony_ci OpDecorate %5 DescriptorSet 0 393fd4e5da5Sopenharmony_ci OpDecorate %5 Binding 0 394fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 395fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 396fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 397fd4e5da5Sopenharmony_ci %bool = OpTypeBool 398fd4e5da5Sopenharmony_ci %true = OpConstantTrue %bool 399fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 400fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 401fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 402fd4e5da5Sopenharmony_ci %float_2 = OpConstant %float 2 403fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 404fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 405fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10 406fd4e5da5Sopenharmony_ci%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 407fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 408fd4e5da5Sopenharmony_ci %_struct_19 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 409fd4e5da5Sopenharmony_ci%_ptr_Workgroup__struct_19 = OpTypePointer Workgroup %_struct_19 410fd4e5da5Sopenharmony_ci%_ptr_Function__struct_19 = OpTypePointer Function %_struct_19 411fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 412fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 413fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 414fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 415fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 416fd4e5da5Sopenharmony_ci %void = OpTypeVoid 417fd4e5da5Sopenharmony_ci %25 = OpTypeFunction %void 418fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 419fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 420fd4e5da5Sopenharmony_ci %28 = OpVariable %_ptr_Workgroup__struct_19 Workgroup 421fd4e5da5Sopenharmony_ci %29 = OpVariable %_ptr_Workgroup__struct_19 Workgroup 422fd4e5da5Sopenharmony_ci %5 = OpVariable %_ptr_Uniform__struct_7 Uniform 423fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input 424fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 425fd4e5da5Sopenharmony_ci%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input 426fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %25 427fd4e5da5Sopenharmony_ci %30 = OpLabel 428fd4e5da5Sopenharmony_ci %33 = OpSelect %_ptr_Function__struct_19 %true %28 %29 429fd4e5da5Sopenharmony_ci %34 = OpLoad %v3uint %gl_LocalInvocationID 430fd4e5da5Sopenharmony_ci %35 = OpAccessChain %_ptr_Function_float %33 %int_0 %int_0 %int_0 431fd4e5da5Sopenharmony_ci %36 = OpLoad %float %35 432fd4e5da5Sopenharmony_ci %37 = OpFMul %float %float_2 %36 433fd4e5da5Sopenharmony_ci OpStore %35 %37 434fd4e5da5Sopenharmony_ci %38 = OpLoad %float %35 435fd4e5da5Sopenharmony_ci %39 = OpCompositeExtract %uint %34 0 436fd4e5da5Sopenharmony_ci %40 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %39 437fd4e5da5Sopenharmony_ci OpStore %40 %38 438fd4e5da5Sopenharmony_ci OpReturn 439fd4e5da5Sopenharmony_ci OpFunctionEnd 440fd4e5da5Sopenharmony_ci)"; 441fd4e5da5Sopenharmony_ci 442fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 443fd4e5da5Sopenharmony_ci} 444fd4e5da5Sopenharmony_ci 445fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, BitCast) { 446fd4e5da5Sopenharmony_ci const std::string text = R"(OpCapability VariablePointersStorageBuffer 447fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 448fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %1 "main" 449fd4e5da5Sopenharmony_ci%void = OpTypeVoid 450fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 451fd4e5da5Sopenharmony_ci%_ptr_Output_void = OpTypePointer Output %void 452fd4e5da5Sopenharmony_ci%_ptr_Private__ptr_Output_void = OpTypePointer Private %_ptr_Output_void 453fd4e5da5Sopenharmony_ci%6 = OpVariable %_ptr_Private__ptr_Output_void Private 454fd4e5da5Sopenharmony_ci%1 = OpFunction %void Inline %3 455fd4e5da5Sopenharmony_ci%7 = OpLabel 456fd4e5da5Sopenharmony_ci%8 = OpBitcast %_ptr_Output_void %6 457fd4e5da5Sopenharmony_ciOpReturn 458fd4e5da5Sopenharmony_ciOpFunctionEnd 459fd4e5da5Sopenharmony_ci)"; 460fd4e5da5Sopenharmony_ci 461fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<FixStorageClass>(text, text, false); 462fd4e5da5Sopenharmony_ci} 463fd4e5da5Sopenharmony_ci 464fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, FixLinkedAccessChain2) { 465fd4e5da5Sopenharmony_ci // This case is similar to FixLinkedAccessChain. The difference is that the 466fd4e5da5Sopenharmony_ci // first OpAccessChain instruction starts as workgroup storage class. Only 467fd4e5da5Sopenharmony_ci // the second one needs to change. 468fd4e5da5Sopenharmony_ci const std::string text = R"( 469fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup__arr_float_uint_10 470fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Workgroup_float 471fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 472fd4e5da5Sopenharmony_ci OpCapability Shader 473fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 474fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID 475fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 476fd4e5da5Sopenharmony_ci OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId 477fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 478fd4e5da5Sopenharmony_ci OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId 479fd4e5da5Sopenharmony_ci OpDecorate %5 DescriptorSet 0 480fd4e5da5Sopenharmony_ci OpDecorate %5 Binding 0 481fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 482fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 483fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 484fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 485fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 486fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 487fd4e5da5Sopenharmony_ci %float_2 = OpConstant %float 2 488fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 489fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 490fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10 491fd4e5da5Sopenharmony_ci%_ptr_Workgroup__arr_float_uint_10 = OpTypePointer Workgroup %_arr_float_uint_10 492fd4e5da5Sopenharmony_ci%_ptr = OpTypePointer Function %_arr_float_uint_10 493fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 494fd4e5da5Sopenharmony_ci %_struct_17 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 495fd4e5da5Sopenharmony_ci%_ptr_Workgroup__struct_17 = OpTypePointer Workgroup %_struct_17 496fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 497fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 498fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 499fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 500fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 501fd4e5da5Sopenharmony_ci %void = OpTypeVoid 502fd4e5da5Sopenharmony_ci %23 = OpTypeFunction %void 503fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 504fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 505fd4e5da5Sopenharmony_ci %27 = OpVariable %_ptr_Workgroup__struct_17 Workgroup 506fd4e5da5Sopenharmony_ci %5 = OpVariable %_ptr_Uniform__struct_7 Uniform 507fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input 508fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 509fd4e5da5Sopenharmony_ci%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input 510fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %23 511fd4e5da5Sopenharmony_ci %28 = OpLabel 512fd4e5da5Sopenharmony_ci %29 = OpLoad %v3uint %gl_LocalInvocationID 513fd4e5da5Sopenharmony_ci %30 = OpAccessChain %_ptr_Workgroup__arr_float_uint_10 %27 %int_0 %int_0 514fd4e5da5Sopenharmony_ci %31 = OpAccessChain %_ptr_Function_float %30 %int_0 515fd4e5da5Sopenharmony_ci %32 = OpLoad %float %31 516fd4e5da5Sopenharmony_ci %33 = OpFMul %float %float_2 %32 517fd4e5da5Sopenharmony_ci OpStore %31 %33 518fd4e5da5Sopenharmony_ci %34 = OpLoad %float %31 519fd4e5da5Sopenharmony_ci %35 = OpCompositeExtract %uint %29 0 520fd4e5da5Sopenharmony_ci %36 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %35 521fd4e5da5Sopenharmony_ci OpStore %36 %34 522fd4e5da5Sopenharmony_ci OpReturn 523fd4e5da5Sopenharmony_ci OpFunctionEnd 524fd4e5da5Sopenharmony_ci)"; 525fd4e5da5Sopenharmony_ci 526fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 527fd4e5da5Sopenharmony_ci} 528fd4e5da5Sopenharmony_ci 529fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, AllowImageFormatMismatch) { 530fd4e5da5Sopenharmony_ci const std::string text = R"(OpCapability Shader 531fd4e5da5Sopenharmony_ciOpCapability SampledBuffer 532fd4e5da5Sopenharmony_ciOpCapability ImageBuffer 533fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 534fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" 535fd4e5da5Sopenharmony_ciOpExecutionMode %main LocalSize 1 1 1 536fd4e5da5Sopenharmony_ciOpSource HLSL 600 537fd4e5da5Sopenharmony_ciOpName %type_buffer_image "type.buffer.image" 538fd4e5da5Sopenharmony_ciOpName %Buf "Buf" 539fd4e5da5Sopenharmony_ciOpName %main "main" 540fd4e5da5Sopenharmony_ciOpName %src_main "src.main" 541fd4e5da5Sopenharmony_ciOpName %bb_entry "bb.entry" 542fd4e5da5Sopenharmony_ciOpName %type_buffer_image_0 "type.buffer.image" 543fd4e5da5Sopenharmony_ciOpName %b "b" 544fd4e5da5Sopenharmony_ciOpDecorate %Buf DescriptorSet 0 545fd4e5da5Sopenharmony_ciOpDecorate %Buf Binding 0 546fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 547fd4e5da5Sopenharmony_ci%type_buffer_image = OpTypeImage %float Buffer 2 0 0 2 Rgba16f 548fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_buffer_image = OpTypePointer UniformConstant %type_buffer_image 549fd4e5da5Sopenharmony_ci%void = OpTypeVoid 550fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void 551fd4e5da5Sopenharmony_ci%type_buffer_image_0 = OpTypeImage %float Buffer 2 0 0 2 Rgba32f 552fd4e5da5Sopenharmony_ci%_ptr_Function_type_buffer_image_0 = OpTypePointer Function %type_buffer_image_0 553fd4e5da5Sopenharmony_ci%Buf = OpVariable %_ptr_UniformConstant_type_buffer_image UniformConstant 554fd4e5da5Sopenharmony_ci%main = OpFunction %void None %11 555fd4e5da5Sopenharmony_ci%13 = OpLabel 556fd4e5da5Sopenharmony_ci%14 = OpFunctionCall %void %src_main 557fd4e5da5Sopenharmony_ciOpReturn 558fd4e5da5Sopenharmony_ciOpFunctionEnd 559fd4e5da5Sopenharmony_ci%src_main = OpFunction %void None %11 560fd4e5da5Sopenharmony_ci%bb_entry = OpLabel 561fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Function_type_buffer_image_0 Function 562fd4e5da5Sopenharmony_ci%15 = OpLoad %type_buffer_image %Buf 563fd4e5da5Sopenharmony_ciOpStore %b %15 564fd4e5da5Sopenharmony_ciOpReturn 565fd4e5da5Sopenharmony_ciOpFunctionEnd 566fd4e5da5Sopenharmony_ci)"; 567fd4e5da5Sopenharmony_ci 568fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<FixStorageClass>(text, text, false, false); 569fd4e5da5Sopenharmony_ci} 570fd4e5da5Sopenharmony_ci 571fd4e5da5Sopenharmony_ciusing FixTypeTest = PassTest<::testing::Test>; 572fd4e5da5Sopenharmony_ci 573fd4e5da5Sopenharmony_ciTEST_F(FixTypeTest, FixAccessChain) { 574fd4e5da5Sopenharmony_ci const std::string text = R"( 575fd4e5da5Sopenharmony_ci; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 576fd4e5da5Sopenharmony_ci; CHECK: [[ac2:%\w+]] = OpAccessChain %_ptr_Uniform_T [[ac1]] %int_0 577fd4e5da5Sopenharmony_ci OpCapability Shader 578fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 579fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %main "main" 580fd4e5da5Sopenharmony_ci OpExecutionMode %main LocalSize 1 1 1 581fd4e5da5Sopenharmony_ci OpSource HLSL 600 582fd4e5da5Sopenharmony_ci OpName %type_RWStructuredBuffer_S "type.RWStructuredBuffer.S" 583fd4e5da5Sopenharmony_ci OpName %S "S" 584fd4e5da5Sopenharmony_ci OpMemberName %S 0 "t" 585fd4e5da5Sopenharmony_ci OpName %T "T" 586fd4e5da5Sopenharmony_ci OpMemberName %T 0 "a" 587fd4e5da5Sopenharmony_ci OpName %A "A" 588fd4e5da5Sopenharmony_ci OpName %type_ACSBuffer_counter "type.ACSBuffer.counter" 589fd4e5da5Sopenharmony_ci OpMemberName %type_ACSBuffer_counter 0 "counter" 590fd4e5da5Sopenharmony_ci OpName %counter_var_A "counter.var.A" 591fd4e5da5Sopenharmony_ci OpName %main "main" 592fd4e5da5Sopenharmony_ci OpName %S_0 "S" 593fd4e5da5Sopenharmony_ci OpMemberName %S_0 0 "t" 594fd4e5da5Sopenharmony_ci OpName %T_0 "T" 595fd4e5da5Sopenharmony_ci OpMemberName %T_0 0 "a" 596fd4e5da5Sopenharmony_ci OpDecorate %A DescriptorSet 0 597fd4e5da5Sopenharmony_ci OpDecorate %A Binding 0 598fd4e5da5Sopenharmony_ci OpDecorate %counter_var_A DescriptorSet 0 599fd4e5da5Sopenharmony_ci OpDecorate %counter_var_A Binding 1 600fd4e5da5Sopenharmony_ci OpMemberDecorate %T 0 Offset 0 601fd4e5da5Sopenharmony_ci OpMemberDecorate %S 0 Offset 0 602fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_S ArrayStride 4 603fd4e5da5Sopenharmony_ci OpMemberDecorate %type_RWStructuredBuffer_S 0 Offset 0 604fd4e5da5Sopenharmony_ci OpDecorate %type_RWStructuredBuffer_S BufferBlock 605fd4e5da5Sopenharmony_ci OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0 606fd4e5da5Sopenharmony_ci OpDecorate %type_ACSBuffer_counter BufferBlock 607fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 608fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 609fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 610fd4e5da5Sopenharmony_ci %uint_0 = OpConstant %uint 0 611fd4e5da5Sopenharmony_ci %T = OpTypeStruct %int 612fd4e5da5Sopenharmony_ci %S = OpTypeStruct %T 613fd4e5da5Sopenharmony_ci%_runtimearr_S = OpTypeRuntimeArray %S 614fd4e5da5Sopenharmony_ci%type_RWStructuredBuffer_S = OpTypeStruct %_runtimearr_S 615fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_RWStructuredBuffer_S = OpTypePointer Uniform %type_RWStructuredBuffer_S 616fd4e5da5Sopenharmony_ci%type_ACSBuffer_counter = OpTypeStruct %int 617fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter 618fd4e5da5Sopenharmony_ci %void = OpTypeVoid 619fd4e5da5Sopenharmony_ci %18 = OpTypeFunction %void 620fd4e5da5Sopenharmony_ci %T_0 = OpTypeStruct %int 621fd4e5da5Sopenharmony_ci %S_0 = OpTypeStruct %T_0 622fd4e5da5Sopenharmony_ci%_ptr_Function_S_0 = OpTypePointer Function %S_0 623fd4e5da5Sopenharmony_ci%_ptr_Uniform_S = OpTypePointer Uniform %S 624fd4e5da5Sopenharmony_ci%_ptr_Uniform_T = OpTypePointer Uniform %T 625fd4e5da5Sopenharmony_ci %22 = OpTypeFunction %T_0 %_ptr_Function_S_0 626fd4e5da5Sopenharmony_ci%_ptr_Function_T_0 = OpTypePointer Function %T_0 627fd4e5da5Sopenharmony_ci %A = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_S Uniform 628fd4e5da5Sopenharmony_ci%counter_var_A = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform 629fd4e5da5Sopenharmony_ci %main = OpFunction %void None %18 630fd4e5da5Sopenharmony_ci %24 = OpLabel 631fd4e5da5Sopenharmony_ci %25 = OpVariable %_ptr_Function_T_0 Function 632fd4e5da5Sopenharmony_ci %26 = OpVariable %_ptr_Function_S_0 Function 633fd4e5da5Sopenharmony_ci %27 = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 634fd4e5da5Sopenharmony_ci %28 = OpAccessChain %_ptr_Function_T_0 %27 %int_0 635fd4e5da5Sopenharmony_ci OpReturn 636fd4e5da5Sopenharmony_ci OpFunctionEnd 637fd4e5da5Sopenharmony_ci)"; 638fd4e5da5Sopenharmony_ci 639fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 640fd4e5da5Sopenharmony_ci} 641fd4e5da5Sopenharmony_ci 642fd4e5da5Sopenharmony_ciTEST_F(FixTypeTest, FixLoad) { 643fd4e5da5Sopenharmony_ci const std::string text = R"( 644fd4e5da5Sopenharmony_ci; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 645fd4e5da5Sopenharmony_ci; CHECK: [[ac2:%\w+]] = OpAccessChain %_ptr_Uniform_T [[ac1]] %int_0 646fd4e5da5Sopenharmony_ci; CHECK: [[ld:%\w+]] = OpLoad %T [[ac2]] 647fd4e5da5Sopenharmony_ci OpCapability Shader 648fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 649fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %main "main" 650fd4e5da5Sopenharmony_ci OpExecutionMode %main LocalSize 1 1 1 651fd4e5da5Sopenharmony_ci OpSource HLSL 600 652fd4e5da5Sopenharmony_ci OpName %type_RWStructuredBuffer_S "type.RWStructuredBuffer.S" 653fd4e5da5Sopenharmony_ci OpName %S "S" 654fd4e5da5Sopenharmony_ci OpMemberName %S 0 "t" 655fd4e5da5Sopenharmony_ci OpName %T "T" 656fd4e5da5Sopenharmony_ci OpMemberName %T 0 "a" 657fd4e5da5Sopenharmony_ci OpName %A "A" 658fd4e5da5Sopenharmony_ci OpName %type_ACSBuffer_counter "type.ACSBuffer.counter" 659fd4e5da5Sopenharmony_ci OpMemberName %type_ACSBuffer_counter 0 "counter" 660fd4e5da5Sopenharmony_ci OpName %counter_var_A "counter.var.A" 661fd4e5da5Sopenharmony_ci OpName %main "main" 662fd4e5da5Sopenharmony_ci OpName %S_0 "S" 663fd4e5da5Sopenharmony_ci OpMemberName %S_0 0 "t" 664fd4e5da5Sopenharmony_ci OpName %T_0 "T" 665fd4e5da5Sopenharmony_ci OpMemberName %T_0 0 "a" 666fd4e5da5Sopenharmony_ci OpDecorate %A DescriptorSet 0 667fd4e5da5Sopenharmony_ci OpDecorate %A Binding 0 668fd4e5da5Sopenharmony_ci OpDecorate %counter_var_A DescriptorSet 0 669fd4e5da5Sopenharmony_ci OpDecorate %counter_var_A Binding 1 670fd4e5da5Sopenharmony_ci OpMemberDecorate %T 0 Offset 0 671fd4e5da5Sopenharmony_ci OpMemberDecorate %S 0 Offset 0 672fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_S ArrayStride 4 673fd4e5da5Sopenharmony_ci OpMemberDecorate %type_RWStructuredBuffer_S 0 Offset 0 674fd4e5da5Sopenharmony_ci OpDecorate %type_RWStructuredBuffer_S BufferBlock 675fd4e5da5Sopenharmony_ci OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0 676fd4e5da5Sopenharmony_ci OpDecorate %type_ACSBuffer_counter BufferBlock 677fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 678fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 679fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 680fd4e5da5Sopenharmony_ci %uint_0 = OpConstant %uint 0 681fd4e5da5Sopenharmony_ci %T = OpTypeStruct %int 682fd4e5da5Sopenharmony_ci %S = OpTypeStruct %T 683fd4e5da5Sopenharmony_ci%_runtimearr_S = OpTypeRuntimeArray %S 684fd4e5da5Sopenharmony_ci%type_RWStructuredBuffer_S = OpTypeStruct %_runtimearr_S 685fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_RWStructuredBuffer_S = OpTypePointer Uniform %type_RWStructuredBuffer_S 686fd4e5da5Sopenharmony_ci%type_ACSBuffer_counter = OpTypeStruct %int 687fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter 688fd4e5da5Sopenharmony_ci %void = OpTypeVoid 689fd4e5da5Sopenharmony_ci %18 = OpTypeFunction %void 690fd4e5da5Sopenharmony_ci %T_0 = OpTypeStruct %int 691fd4e5da5Sopenharmony_ci %S_0 = OpTypeStruct %T_0 692fd4e5da5Sopenharmony_ci%_ptr_Function_S_0 = OpTypePointer Function %S_0 693fd4e5da5Sopenharmony_ci%_ptr_Uniform_S = OpTypePointer Uniform %S 694fd4e5da5Sopenharmony_ci%_ptr_Uniform_T = OpTypePointer Uniform %T 695fd4e5da5Sopenharmony_ci %22 = OpTypeFunction %T_0 %_ptr_Function_S_0 696fd4e5da5Sopenharmony_ci%_ptr_Function_T_0 = OpTypePointer Function %T_0 697fd4e5da5Sopenharmony_ci %A = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_S Uniform 698fd4e5da5Sopenharmony_ci%counter_var_A = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform 699fd4e5da5Sopenharmony_ci %main = OpFunction %void None %18 700fd4e5da5Sopenharmony_ci %24 = OpLabel 701fd4e5da5Sopenharmony_ci %25 = OpVariable %_ptr_Function_T_0 Function 702fd4e5da5Sopenharmony_ci %26 = OpVariable %_ptr_Function_S_0 Function 703fd4e5da5Sopenharmony_ci %27 = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 704fd4e5da5Sopenharmony_ci %28 = OpAccessChain %_ptr_Uniform_T %27 %int_0 705fd4e5da5Sopenharmony_ci %29 = OpLoad %T_0 %28 706fd4e5da5Sopenharmony_ci OpReturn 707fd4e5da5Sopenharmony_ci OpFunctionEnd 708fd4e5da5Sopenharmony_ci)"; 709fd4e5da5Sopenharmony_ci 710fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 711fd4e5da5Sopenharmony_ci} 712fd4e5da5Sopenharmony_ci 713fd4e5da5Sopenharmony_ciTEST_F(FixTypeTest, FixStore) { 714fd4e5da5Sopenharmony_ci const std::string text = R"( 715fd4e5da5Sopenharmony_ci; CHECK: [[ld:%\w+]] = OpLoad %T 716fd4e5da5Sopenharmony_ci; CHECK: OpStore 717fd4e5da5Sopenharmony_ci OpCapability Shader 718fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 719fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %main "main" 720fd4e5da5Sopenharmony_ci OpExecutionMode %main LocalSize 1 1 1 721fd4e5da5Sopenharmony_ci OpSource HLSL 600 722fd4e5da5Sopenharmony_ci OpName %type_RWStructuredBuffer_S "type.RWStructuredBuffer.S" 723fd4e5da5Sopenharmony_ci OpName %S "S" 724fd4e5da5Sopenharmony_ci OpMemberName %S 0 "t" 725fd4e5da5Sopenharmony_ci OpName %T "T" 726fd4e5da5Sopenharmony_ci OpMemberName %T 0 "a" 727fd4e5da5Sopenharmony_ci OpName %A "A" 728fd4e5da5Sopenharmony_ci OpName %type_ACSBuffer_counter "type.ACSBuffer.counter" 729fd4e5da5Sopenharmony_ci OpMemberName %type_ACSBuffer_counter 0 "counter" 730fd4e5da5Sopenharmony_ci OpName %counter_var_A "counter.var.A" 731fd4e5da5Sopenharmony_ci OpName %main "main" 732fd4e5da5Sopenharmony_ci OpName %S_0 "S" 733fd4e5da5Sopenharmony_ci OpMemberName %S_0 0 "t" 734fd4e5da5Sopenharmony_ci OpName %T_0 "T" 735fd4e5da5Sopenharmony_ci OpMemberName %T_0 0 "a" 736fd4e5da5Sopenharmony_ci OpDecorate %A DescriptorSet 0 737fd4e5da5Sopenharmony_ci OpDecorate %A Binding 0 738fd4e5da5Sopenharmony_ci OpDecorate %counter_var_A DescriptorSet 0 739fd4e5da5Sopenharmony_ci OpDecorate %counter_var_A Binding 1 740fd4e5da5Sopenharmony_ci OpMemberDecorate %T 0 Offset 0 741fd4e5da5Sopenharmony_ci OpMemberDecorate %S 0 Offset 0 742fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_S ArrayStride 4 743fd4e5da5Sopenharmony_ci OpMemberDecorate %type_RWStructuredBuffer_S 0 Offset 0 744fd4e5da5Sopenharmony_ci OpDecorate %type_RWStructuredBuffer_S BufferBlock 745fd4e5da5Sopenharmony_ci OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0 746fd4e5da5Sopenharmony_ci OpDecorate %type_ACSBuffer_counter BufferBlock 747fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 748fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 749fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 750fd4e5da5Sopenharmony_ci %uint_0 = OpConstant %uint 0 751fd4e5da5Sopenharmony_ci %T = OpTypeStruct %int 752fd4e5da5Sopenharmony_ci %S = OpTypeStruct %T 753fd4e5da5Sopenharmony_ci%_runtimearr_S = OpTypeRuntimeArray %S 754fd4e5da5Sopenharmony_ci%type_RWStructuredBuffer_S = OpTypeStruct %_runtimearr_S 755fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_RWStructuredBuffer_S = OpTypePointer Uniform %type_RWStructuredBuffer_S 756fd4e5da5Sopenharmony_ci%type_ACSBuffer_counter = OpTypeStruct %int 757fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter 758fd4e5da5Sopenharmony_ci %void = OpTypeVoid 759fd4e5da5Sopenharmony_ci %18 = OpTypeFunction %void 760fd4e5da5Sopenharmony_ci %T_0 = OpTypeStruct %int 761fd4e5da5Sopenharmony_ci %S_0 = OpTypeStruct %T_0 762fd4e5da5Sopenharmony_ci%_ptr_Function_S_0 = OpTypePointer Function %S_0 763fd4e5da5Sopenharmony_ci%_ptr_Uniform_S = OpTypePointer Uniform %S 764fd4e5da5Sopenharmony_ci%_ptr_Uniform_T = OpTypePointer Uniform %T 765fd4e5da5Sopenharmony_ci %22 = OpTypeFunction %T_0 %_ptr_Function_S_0 766fd4e5da5Sopenharmony_ci%_ptr_Function_T_0 = OpTypePointer Function %T_0 767fd4e5da5Sopenharmony_ci %A = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_S Uniform 768fd4e5da5Sopenharmony_ci%counter_var_A = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform 769fd4e5da5Sopenharmony_ci %main = OpFunction %void None %18 770fd4e5da5Sopenharmony_ci %24 = OpLabel 771fd4e5da5Sopenharmony_ci %25 = OpVariable %_ptr_Function_T_0 Function 772fd4e5da5Sopenharmony_ci %26 = OpVariable %_ptr_Function_S_0 Function 773fd4e5da5Sopenharmony_ci %27 = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 774fd4e5da5Sopenharmony_ci %28 = OpAccessChain %_ptr_Uniform_T %27 %int_0 775fd4e5da5Sopenharmony_ci %29 = OpLoad %T %28 776fd4e5da5Sopenharmony_ci OpStore %25 %29 777fd4e5da5Sopenharmony_ci OpReturn 778fd4e5da5Sopenharmony_ci OpFunctionEnd 779fd4e5da5Sopenharmony_ci)"; 780fd4e5da5Sopenharmony_ci 781fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 782fd4e5da5Sopenharmony_ci} 783fd4e5da5Sopenharmony_ci 784fd4e5da5Sopenharmony_ciTEST_F(FixTypeTest, FixSelect) { 785fd4e5da5Sopenharmony_ci const std::string text = R"( 786fd4e5da5Sopenharmony_ci; CHECK: OpSelect %_ptr_Uniform__struct_3 787fd4e5da5Sopenharmony_ci OpCapability Shader 788fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 789fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "main" 790fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 1 1 1 791fd4e5da5Sopenharmony_ci OpSource HLSL 600 792fd4e5da5Sopenharmony_ci OpDecorate %2 DescriptorSet 0 793fd4e5da5Sopenharmony_ci OpDecorate %2 Binding 0 794fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_3 0 Offset 0 795fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr__struct_3 ArrayStride 4 796fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_5 0 Offset 0 797fd4e5da5Sopenharmony_ci OpDecorate %_struct_5 BufferBlock 798fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 799fd4e5da5Sopenharmony_ci %uint_0 = OpConstant %uint 0 800fd4e5da5Sopenharmony_ci %uint_1 = OpConstant %uint 1 801fd4e5da5Sopenharmony_ci %_struct_3 = OpTypeStruct %uint 802fd4e5da5Sopenharmony_ci%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3 803fd4e5da5Sopenharmony_ci %_struct_5 = OpTypeStruct %_runtimearr__struct_3 804fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5 805fd4e5da5Sopenharmony_ci %void = OpTypeVoid 806fd4e5da5Sopenharmony_ci %11 = OpTypeFunction %void 807fd4e5da5Sopenharmony_ci %_struct_12 = OpTypeStruct %uint 808fd4e5da5Sopenharmony_ci%_ptr_Function__struct_12 = OpTypePointer Function %_struct_12 809fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint 810fd4e5da5Sopenharmony_ci %bool = OpTypeBool 811fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_3 = OpTypePointer Uniform %_struct_3 812fd4e5da5Sopenharmony_ci %2 = OpVariable %_ptr_Uniform__struct_5 Uniform 813fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %11 814fd4e5da5Sopenharmony_ci %17 = OpLabel 815fd4e5da5Sopenharmony_ci %18 = OpAccessChain %_ptr_Uniform_uint %2 %uint_0 %uint_0 %uint_0 816fd4e5da5Sopenharmony_ci %19 = OpLoad %uint %18 817fd4e5da5Sopenharmony_ci %20 = OpSGreaterThan %bool %19 %uint_0 818fd4e5da5Sopenharmony_ci %21 = OpAccessChain %_ptr_Uniform__struct_3 %2 %uint_0 %uint_0 819fd4e5da5Sopenharmony_ci %22 = OpAccessChain %_ptr_Uniform__struct_3 %2 %uint_0 %uint_1 820fd4e5da5Sopenharmony_ci %23 = OpSelect %_ptr_Function__struct_12 %20 %21 %22 821fd4e5da5Sopenharmony_ci OpReturn 822fd4e5da5Sopenharmony_ci OpFunctionEnd 823fd4e5da5Sopenharmony_ci)"; 824fd4e5da5Sopenharmony_ci 825fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 826fd4e5da5Sopenharmony_ci} 827fd4e5da5Sopenharmony_ci 828fd4e5da5Sopenharmony_ciTEST_F(FixTypeTest, FixPhiInLoop) { 829fd4e5da5Sopenharmony_ci const std::string text = R"( 830fd4e5da5Sopenharmony_ci; CHECK: [[ac_init:%\w+]] = OpAccessChain %_ptr_Uniform__struct_3 831fd4e5da5Sopenharmony_ci; CHECK: [[ac_phi:%\w+]] = OpPhi %_ptr_Uniform__struct_3 [[ac_init]] {{%\w+}} [[ac_update:%\w+]] {{%\w+}} 832fd4e5da5Sopenharmony_ci; CHECK: [[ac_update]] = OpPtrAccessChain %_ptr_Uniform__struct_3 [[ac_phi]] %int_1 833fd4e5da5Sopenharmony_ci OpCapability Shader 834fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 835fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "main" 836fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 1 1 1 837fd4e5da5Sopenharmony_ci OpSource HLSL 600 838fd4e5da5Sopenharmony_ci OpDecorate %2 DescriptorSet 0 839fd4e5da5Sopenharmony_ci OpDecorate %2 Binding 0 840fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_3 0 Offset 0 841fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr__struct_3 ArrayStride 4 842fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_5 0 Offset 0 843fd4e5da5Sopenharmony_ci OpDecorate %_struct_5 BufferBlock 844fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 845fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 846fd4e5da5Sopenharmony_ci %int_1 = OpConstant %int 1 847fd4e5da5Sopenharmony_ci %_struct_3 = OpTypeStruct %int 848fd4e5da5Sopenharmony_ci %_struct_9 = OpTypeStruct %int 849fd4e5da5Sopenharmony_ci%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3 850fd4e5da5Sopenharmony_ci %_struct_5 = OpTypeStruct %_runtimearr__struct_3 851fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5 852fd4e5da5Sopenharmony_ci %void = OpTypeVoid 853fd4e5da5Sopenharmony_ci %12 = OpTypeFunction %void 854fd4e5da5Sopenharmony_ci %bool = OpTypeBool 855fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_3 = OpTypePointer Uniform %_struct_3 856fd4e5da5Sopenharmony_ci%_ptr_Function__struct_9 = OpTypePointer Function %_struct_9 857fd4e5da5Sopenharmony_ci %2 = OpVariable %_ptr_Uniform__struct_5 Uniform 858fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %12 859fd4e5da5Sopenharmony_ci %16 = OpLabel 860fd4e5da5Sopenharmony_ci %17 = OpAccessChain %_ptr_Uniform__struct_3 %2 %int_0 %int_0 861fd4e5da5Sopenharmony_ci OpBranch %18 862fd4e5da5Sopenharmony_ci %18 = OpLabel 863fd4e5da5Sopenharmony_ci %20 = OpPhi %_ptr_Function__struct_9 %17 %16 %21 %22 864fd4e5da5Sopenharmony_ci %23 = OpUndef %bool 865fd4e5da5Sopenharmony_ci OpLoopMerge %24 %22 None 866fd4e5da5Sopenharmony_ci OpBranchConditional %23 %22 %24 867fd4e5da5Sopenharmony_ci %22 = OpLabel 868fd4e5da5Sopenharmony_ci %21 = OpPtrAccessChain %_ptr_Function__struct_9 %20 %int_1 869fd4e5da5Sopenharmony_ci OpBranch %18 870fd4e5da5Sopenharmony_ci %24 = OpLabel 871fd4e5da5Sopenharmony_ci OpReturn 872fd4e5da5Sopenharmony_ci OpFunctionEnd 873fd4e5da5Sopenharmony_ci)"; 874fd4e5da5Sopenharmony_ci 875fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 876fd4e5da5Sopenharmony_ci} 877fd4e5da5Sopenharmony_ciTEST_F(FixStorageClassTest, SupportsU64Index) { 878fd4e5da5Sopenharmony_ci const std::string text = R"( 879fd4e5da5Sopenharmony_ci; CHECK: OpAccessChain %_ptr_Uniform_float 880fd4e5da5Sopenharmony_ci OpCapability Shader 881fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 882fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %1 "testMain" %gl_LocalInvocationID 883fd4e5da5Sopenharmony_ci OpExecutionMode %1 LocalSize 8 8 1 884fd4e5da5Sopenharmony_ci OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId 885fd4e5da5Sopenharmony_ci OpDecorate %8 DescriptorSet 0 886fd4e5da5Sopenharmony_ci OpDecorate %8 Binding 0 887fd4e5da5Sopenharmony_ci OpDecorate %_runtimearr_float ArrayStride 4 888fd4e5da5Sopenharmony_ci OpMemberDecorate %_struct_7 0 Offset 0 889fd4e5da5Sopenharmony_ci OpDecorate %_struct_7 BufferBlock 890fd4e5da5Sopenharmony_ci %ulong = OpTypeInt 64 0 891fd4e5da5Sopenharmony_ci %ulong_0 = OpConstant %ulong 0 892fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 893fd4e5da5Sopenharmony_ci %float_123 = OpConstant %float 123 894fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 895fd4e5da5Sopenharmony_ci %uint_10 = OpConstant %uint 10 896fd4e5da5Sopenharmony_ci%_runtimearr_float = OpTypeRuntimeArray %float 897fd4e5da5Sopenharmony_ci %_struct_7 = OpTypeStruct %_runtimearr_float 898fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 899fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 900fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint 901fd4e5da5Sopenharmony_ci %void = OpTypeVoid 902fd4e5da5Sopenharmony_ci %30 = OpTypeFunction %void 903fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 904fd4e5da5Sopenharmony_ci %8 = OpVariable %_ptr_Uniform__struct_7 Uniform 905fd4e5da5Sopenharmony_ci%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input 906fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %30 907fd4e5da5Sopenharmony_ci %38 = OpLabel 908fd4e5da5Sopenharmony_ci %44 = OpLoad %v3uint %gl_LocalInvocationID 909fd4e5da5Sopenharmony_ci %59 = OpCompositeExtract %uint %44 0 910fd4e5da5Sopenharmony_ci %60 = OpAccessChain %_ptr_Uniform_float %8 %ulong_0 %59 911fd4e5da5Sopenharmony_ci OpStore %60 %float_123 912fd4e5da5Sopenharmony_ci OpReturn 913fd4e5da5Sopenharmony_ci OpFunctionEnd 914fd4e5da5Sopenharmony_ci)"; 915fd4e5da5Sopenharmony_ci 916fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<FixStorageClass>(text, false); 917fd4e5da5Sopenharmony_ci} 918fd4e5da5Sopenharmony_ci 919fd4e5da5Sopenharmony_ci} // namespace 920fd4e5da5Sopenharmony_ci} // namespace opt 921fd4e5da5Sopenharmony_ci} // namespace spvtools 922