123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774 |
- // Copyright (c) 2018 Google LLC
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #include <string>
- #include "gmock/gmock.h"
- #include "test/opt/assembly_builder.h"
- #include "test/opt/pass_fixture.h"
- #include "test/opt/pass_utils.h"
- namespace spvtools {
- namespace opt {
- namespace {
- using CombineAccessChainsTest = PassTest<::testing::Test>;
- TEST_F(CombineAccessChainsTest, PtrAccessChainFromAccessChainConstant) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int3:%\w+]] = OpConstant [[int]] 3
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: OpAccessChain [[ptr_int]] [[var]] [[int3]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpAccessChain %ptr_Workgroup_uint %var %uint_0
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, PtrAccessChainFromInBoundsAccessChainConstant) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int3:%\w+]] = OpConstant [[int]] 3
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: OpAccessChain [[ptr_int]] [[var]] [[int3]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpInBoundsAccessChain %ptr_Workgroup_uint %var %uint_0
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, PtrAccessChainFromAccessChainCombineConstant) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[int2:%\w+]] = OpConstant [[int]] 2
- ; CHECK: OpAccessChain [[ptr_int]] [[var]] [[int2]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpAccessChain %ptr_Workgroup_uint %var %uint_1
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %uint_1
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, PtrAccessChainFromAccessChainNonConstant) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[ld1:%\w+]] = OpLoad
- ; CHECK: [[ld2:%\w+]] = OpLoad
- ; CHECK: [[add:%\w+]] = OpIAdd [[int]] [[ld1]] [[ld2]]
- ; CHECK: OpAccessChain [[ptr_int]] [[var]] [[add]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Function_uint = OpTypePointer Function %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %local_var = OpVariable %ptr_Function_uint Function
- %ld1 = OpLoad %uint %local_var
- %gep = OpAccessChain %ptr_Workgroup_uint %var %ld1
- %ld2 = OpLoad %uint %local_var
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %ld2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, PtrAccessChainFromAccessChainExtraIndices) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int1:%\w+]] = OpConstant [[int]] 1
- ; CHECK: [[int2:%\w+]] = OpConstant [[int]] 2
- ; CHECK: [[int3:%\w+]] = OpConstant [[int]] 3
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: OpAccessChain [[ptr_int]] [[var]] [[int1]] [[int2]] [[int3]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %uint_array_4_array_4 = OpTypeArray %uint_array_4 %uint_4
- %uint_array_4_array_4_array_4 = OpTypeArray %uint_array_4_array_4 %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Function_uint = OpTypePointer Function %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %ptr_Workgroup_uint_array_4_array_4 = OpTypePointer Workgroup %uint_array_4_array_4
- %ptr_Workgroup_uint_array_4_array_4_array_4 = OpTypePointer Workgroup %uint_array_4_array_4_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4_array_4_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpAccessChain %ptr_Workgroup_uint_array_4 %var %uint_1 %uint_0
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %uint_2 %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest,
- PtrAccessChainFromPtrAccessChainCombineElementOperand) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int3:%\w+]] = OpConstant [[int]] 3
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[int6:%\w+]] = OpConstant [[int]] 6
- ; CHECK: OpPtrAccessChain [[ptr_int]] [[var]] [[int6]] [[int3]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_3
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %uint_3 %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest,
- PtrAccessChainFromPtrAccessChainOnlyElementOperand) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int4:%\w+]] = OpConstant [[int]] 4
- ; CHECK: [[array:%\w+]] = OpTypeArray [[int]] [[int4]]
- ; CHECK: [[ptr_array:%\w+]] = OpTypePointer Workgroup [[array]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[int6:%\w+]] = OpConstant [[int]] 6
- ; CHECK: OpPtrAccessChain [[ptr_array]] [[var]] [[int6]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_3
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest,
- PtrAccessChainFromPtrAccessCombineNonElementIndex) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int3:%\w+]] = OpConstant [[int]] 3
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: OpPtrAccessChain [[ptr_int]] [[var]] [[int3]] [[int3]] [[int3]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %uint_array_4_array_4 = OpTypeArray %uint_array_4 %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Function_uint = OpTypePointer Function %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %ptr_Workgroup_uint_array_4_array_4 = OpTypePointer Workgroup %uint_array_4_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_3 %uint_0
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %uint_3 %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest,
- AccessChainFromPtrAccessChainOnlyElementOperand) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int3:%\w+]] = OpConstant [[int]] 3
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: OpPtrAccessChain [[ptr_int]] [[var]] [[int3]] [[int3]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_3
- %gep = OpAccessChain %ptr_Workgroup_uint %ptr_gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, AccessChainFromPtrAccessChainAppend) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int1:%\w+]] = OpConstant [[int]] 1
- ; CHECK: [[int2:%\w+]] = OpConstant [[int]] 2
- ; CHECK: [[int3:%\w+]] = OpConstant [[int]] 3
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: OpPtrAccessChain [[ptr_int]] [[var]] [[int1]] [[int2]] [[int3]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %uint_array_4_array_4 = OpTypeArray %uint_array_4 %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %ptr_Workgroup_uint_array_4_array_4 = OpTypePointer Workgroup %uint_array_4_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_1 %uint_2
- %gep = OpAccessChain %ptr_Workgroup_uint %ptr_gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, AccessChainFromAccessChainAppend) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int1:%\w+]] = OpConstant [[int]] 1
- ; CHECK: [[int2:%\w+]] = OpConstant [[int]] 2
- ; CHECK: [[ptr_int:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: OpAccessChain [[ptr_int]] [[var]] [[int1]] [[int2]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %uint_array_4_array_4 = OpTypeArray %uint_array_4 %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %ptr_Workgroup_uint_array_4_array_4 = OpTypePointer Workgroup %uint_array_4_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %ptr_gep = OpAccessChain %ptr_Workgroup_uint_array_4 %var %uint_1
- %gep = OpAccessChain %ptr_Workgroup_uint %ptr_gep %uint_2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, NonConstantStructSlide) {
- const std::string text = R"(
- ; CHECK: [[int0:%\w+]] = OpConstant {{%\w+}} 0
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[ld:%\w+]] = OpLoad
- ; CHECK: OpPtrAccessChain {{%\w+}} [[var]] [[ld]] [[int0]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %struct = OpTypeStruct %uint %uint
- %ptr_Workgroup_struct = OpTypePointer Workgroup %struct
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Function_uint = OpTypePointer Function %uint
- %wg_var = OpVariable %ptr_Workgroup_struct Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %1 = OpLabel
- %func_var = OpVariable %ptr_Function_uint Function
- %ld = OpLoad %uint %func_var
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_struct %wg_var %ld
- %gep = OpAccessChain %ptr_Workgroup_uint %ptr_gep %uint_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, DontCombineNonConstantStructSlide) {
- const std::string text = R"(
- ; CHECK: [[int0:%\w+]] = OpConstant {{%\w+}} 0
- ; CHECK: [[ld:%\w+]] = OpLoad
- ; CHECK: [[gep:%\w+]] = OpAccessChain
- ; CHECK: OpPtrAccessChain {{%\w+}} [[gep]] [[ld]] [[int0]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_4 = OpConstant %uint 4
- %struct = OpTypeStruct %uint %uint
- %struct_array_4 = OpTypeArray %struct %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Function_uint = OpTypePointer Function %uint
- %ptr_Workgroup_struct = OpTypePointer Workgroup %struct
- %ptr_Workgroup_struct_array_4 = OpTypePointer Workgroup %struct_array_4
- %wg_var = OpVariable %ptr_Workgroup_struct_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %1 = OpLabel
- %func_var = OpVariable %ptr_Function_uint Function
- %ld = OpLoad %uint %func_var
- %gep = OpAccessChain %ptr_Workgroup_struct %wg_var %uint_0
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %ld %uint_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, CombineNonConstantStructSlideElement) {
- const std::string text = R"(
- ; CHECK: [[int0:%\w+]] = OpConstant {{%\w+}} 0
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[ld:%\w+]] = OpLoad
- ; CHECK: [[add:%\w+]] = OpIAdd {{%\w+}} [[ld]] [[ld]]
- ; CHECK: OpPtrAccessChain {{%\w+}} [[var]] [[add]] [[int0]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_4 = OpConstant %uint 4
- %struct = OpTypeStruct %uint %uint
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Function_uint = OpTypePointer Function %uint
- %ptr_Workgroup_struct = OpTypePointer Workgroup %struct
- %wg_var = OpVariable %ptr_Workgroup_struct Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %1 = OpLabel
- %func_var = OpVariable %ptr_Function_uint Function
- %ld = OpLoad %uint %func_var
- %gep = OpPtrAccessChain %ptr_Workgroup_struct %wg_var %ld
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint %gep %ld %uint_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, PtrAccessChainFromInBoundsPtrAccessChain) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int4:%\w+]] = OpConstant [[int]] 4
- ; CHECK: [[array:%\w+]] = OpTypeArray [[int]] [[int4]]
- ; CHECK: [[ptr_array:%\w+]] = OpTypePointer Workgroup [[array]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[int6:%\w+]] = OpConstant [[int]] 6
- ; CHECK: OpPtrAccessChain [[ptr_array]] [[var]] [[int6]]
- OpCapability Shader
- OpCapability VariablePointers
- OpCapability Addresses
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpInBoundsPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_3
- %ptr_gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, InBoundsPtrAccessChainFromPtrAccessChain) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int4:%\w+]] = OpConstant [[int]] 4
- ; CHECK: [[array:%\w+]] = OpTypeArray [[int]] [[int4]]
- ; CHECK: [[ptr_array:%\w+]] = OpTypePointer Workgroup [[array]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[int6:%\w+]] = OpConstant [[int]] 6
- ; CHECK: OpPtrAccessChain [[ptr_array]] [[var]] [[int6]]
- OpCapability Shader
- OpCapability VariablePointers
- OpCapability Addresses
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_3
- %ptr_gep = OpInBoundsPtrAccessChain %ptr_Workgroup_uint_array_4 %gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest,
- InBoundsPtrAccessChainFromInBoundsPtrAccessChain) {
- const std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[int4:%\w+]] = OpConstant [[int]] 4
- ; CHECK: [[array:%\w+]] = OpTypeArray [[int]] [[int4]]
- ; CHECK: [[ptr_array:%\w+]] = OpTypePointer Workgroup [[array]]
- ; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Workgroup
- ; CHECK: [[int6:%\w+]] = OpConstant [[int]] 6
- ; CHECK: OpInBoundsPtrAccessChain [[ptr_array]] [[var]] [[int6]]
- OpCapability Shader
- OpCapability VariablePointers
- OpCapability Addresses
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %uint_4 = OpConstant %uint 4
- %uint_array_4 = OpTypeArray %uint %uint_4
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %ptr_Workgroup_uint_array_4 = OpTypePointer Workgroup %uint_array_4
- %var = OpVariable %ptr_Workgroup_uint_array_4 Workgroup
- %void_func = OpTypeFunction %void
- %main = OpFunction %void None %void_func
- %main_lab = OpLabel
- %gep = OpInBoundsPtrAccessChain %ptr_Workgroup_uint_array_4 %var %uint_3
- %ptr_gep = OpInBoundsPtrAccessChain %ptr_Workgroup_uint_array_4 %gep %uint_3
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, NoIndexAccessChains) {
- const std::string text = R"(
- ; CHECK: [[var:%\w+]] = OpVariable
- ; CHECK-NOT: OpConstant
- ; CHECK: [[gep:%\w+]] = OpAccessChain {{%\w+}} [[var]]
- ; CHECK: OpAccessChain {{%\w+}} [[var]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %func "func"
- OpExecutionMode %func OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %var = OpVariable %ptr_Workgroup_uint Workgroup
- %void_func = OpTypeFunction %void
- %func = OpFunction %void None %void_func
- %1 = OpLabel
- %gep1 = OpAccessChain %ptr_Workgroup_uint %var
- %gep2 = OpAccessChain %ptr_Workgroup_uint %gep1
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, NoIndexPtrAccessChains) {
- const std::string text = R"(
- ; CHECK: [[int0:%\w+]] = OpConstant {{%\w+}} 0
- ; CHECK: [[var:%\w+]] = OpVariable
- ; CHECK: [[gep:%\w+]] = OpPtrAccessChain {{%\w+}} [[var]] [[int0]]
- ; CHECK: OpCopyObject {{%\w+}} [[gep]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %func "func"
- OpExecutionMode %func OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %var = OpVariable %ptr_Workgroup_uint Workgroup
- %void_func = OpTypeFunction %void
- %func = OpFunction %void None %void_func
- %1 = OpLabel
- %gep1 = OpPtrAccessChain %ptr_Workgroup_uint %var %uint_0
- %gep2 = OpAccessChain %ptr_Workgroup_uint %gep1
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, NoIndexPtrAccessChains2) {
- const std::string text = R"(
- ; CHECK: [[int0:%\w+]] = OpConstant {{%\w+}} 0
- ; CHECK: [[var:%\w+]] = OpVariable
- ; CHECK: OpPtrAccessChain {{%\w+}} [[var]] [[int0]]
- OpCapability Shader
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %func "func"
- OpExecutionMode %func OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %var = OpVariable %ptr_Workgroup_uint Workgroup
- %void_func = OpTypeFunction %void
- %func = OpFunction %void None %void_func
- %1 = OpLabel
- %gep1 = OpAccessChain %ptr_Workgroup_uint %var
- %gep2 = OpPtrAccessChain %ptr_Workgroup_uint %gep1 %uint_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- TEST_F(CombineAccessChainsTest, CombineMixedSign) {
- const std::string text = R"(
- ; CHECK: [[uint:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[var:%\w+]] = OpVariable
- ; CHECK: [[uint2:%\w+]] = OpConstant [[uint]] 2
- ; CHECK: OpInBoundsPtrAccessChain {{%\w+}} [[var]] [[uint2]]
- OpCapability Shader
- OpCapability VariablePointers
- OpCapability Addresses
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %func "func"
- OpExecutionMode %func OriginUpperLeft
- %void = OpTypeVoid
- %uint = OpTypeInt 32 0
- %int = OpTypeInt 32 1
- %uint_1 = OpConstant %uint 1
- %int_1 = OpConstant %int 1
- %ptr_Workgroup_uint = OpTypePointer Workgroup %uint
- %var = OpVariable %ptr_Workgroup_uint Workgroup
- %void_func = OpTypeFunction %void
- %func = OpFunction %void None %void_func
- %1 = OpLabel
- %gep1 = OpInBoundsPtrAccessChain %ptr_Workgroup_uint %var %uint_1
- %gep2 = OpInBoundsPtrAccessChain %ptr_Workgroup_uint %gep1 %int_1
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<CombineAccessChains>(text, true);
- }
- } // namespace
- } // namespace opt
- } // namespace spvtools
|