Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array copy propagation #4890

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/opt/copy_prop_arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ bool CopyPropagateArrays::HasNoStores(Instruction* ptr_inst) {
return false;
} else if (use->opcode() == SpvOpImageTexelPointer) {
return true;
} else if (use->opcode() == SpvOpEntryPoint) {
return true;
}
// Some other instruction. Be conservative.
return false;
Expand Down
2 changes: 1 addition & 1 deletion source/opt/copy_prop_arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class CopyPropagateArrays : public MemPass {
// Return true if |type_id| is a pointer type whose pointee type is an array.
bool IsPointerToArrayType(uint32_t type_id);

// Returns true of there are not stores using |ptr_inst| or something derived
// Returns true if there are not stores using |ptr_inst| or something derived
// from it.
bool HasNoStores(Instruction* ptr_inst);

Expand Down
75 changes: 75 additions & 0 deletions test/opt/copy_prop_array_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,81 @@ OpFunctionEnd

SinglePassRunAndCheck<CopyPropagateArrays>(text, text, false);
}

TEST_F(CopyPropArrayPassTest, EntryPointUser) {
cassiebeckley marked this conversation as resolved.
Show resolved Hide resolved
const std::string before = R"(OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %g_rwTexture3d
OpExecutionMode %main LocalSize 256 1 1
OpSource HLSL 660
OpName %type_3d_image "type.3d.image"
OpName %g_rwTexture3d "g_rwTexture3d"
OpName %main "main"
OpDecorate %g_rwTexture3d DescriptorSet 0
OpDecorate %g_rwTexture3d Binding 0
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_3 = OpConstant %uint 3
%v3uint = OpTypeVector %uint 3
%10 = OpConstantComposite %v3uint %uint_1 %uint_2 %uint_3
%type_3d_image = OpTypeImage %uint 3D 2 0 0 2 R32ui
%_ptr_UniformConstant_type_3d_image = OpTypePointer UniformConstant %type_3d_image
%void = OpTypeVoid
%13 = OpTypeFunction %void
%_ptr_Function_type_3d_image = OpTypePointer Function %type_3d_image
%_ptr_Image_uint = OpTypePointer Image %uint
%g_rwTexture3d = OpVariable %_ptr_UniformConstant_type_3d_image UniformConstant
%main = OpFunction %void None %13
%16 = OpLabel
%17 = OpVariable %_ptr_Function_type_3d_image Function
%18 = OpLoad %type_3d_image %g_rwTexture3d
OpStore %17 %18
%19 = OpImageTexelPointer %_ptr_Image_uint %17 %10 %uint_0
%20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1
OpReturn
OpFunctionEnd
)";

const std::string after = R"(OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %g_rwTexture3d
OpExecutionMode %main LocalSize 256 1 1
OpSource HLSL 660
OpName %type_3d_image "type.3d.image"
OpName %g_rwTexture3d "g_rwTexture3d"
OpName %main "main"
OpDecorate %g_rwTexture3d DescriptorSet 0
OpDecorate %g_rwTexture3d Binding 0
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_3 = OpConstant %uint 3
%v3uint = OpTypeVector %uint 3
%10 = OpConstantComposite %v3uint %uint_1 %uint_2 %uint_3
%type_3d_image = OpTypeImage %uint 3D 2 0 0 2 R32ui
%_ptr_UniformConstant_type_3d_image = OpTypePointer UniformConstant %type_3d_image
%void = OpTypeVoid
%13 = OpTypeFunction %void
%_ptr_Function_type_3d_image = OpTypePointer Function %type_3d_image
%_ptr_Image_uint = OpTypePointer Image %uint
%g_rwTexture3d = OpVariable %_ptr_UniformConstant_type_3d_image UniformConstant
%main = OpFunction %void None %13
%16 = OpLabel
%17 = OpVariable %_ptr_Function_type_3d_image Function
%18 = OpLoad %type_3d_image %g_rwTexture3d
OpStore %17 %18
%19 = OpImageTexelPointer %_ptr_Image_uint %g_rwTexture3d %10 %uint_0
%20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1
OpReturn
OpFunctionEnd
)";

SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
cassiebeckley marked this conversation as resolved.
Show resolved Hide resolved
SinglePassRunAndCheck<CopyPropagateArrays>(before, after, false);
}
} // namespace
} // namespace opt
} // namespace spvtools