Have replace load size handle extact with no index. (#2261)

Fixes https://crbug.com/917774
This commit is contained in:
Steven Perron 2019-01-03 13:02:10 -05:00 committed by GitHub
parent 9f36c8bb72
commit 241644a5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -139,7 +139,8 @@ bool ReduceLoadSize::ShouldReplaceExtract(Instruction* inst) {
all_elements_used =
!def_use_mgr->WhileEachUser(op_inst, [&elements_used](Instruction* use) {
if (use->opcode() != SpvOpCompositeExtract) {
if (use->opcode() != SpvOpCompositeExtract ||
use->NumInOperands() == 1) {
return false;
}
elements_used.insert(use->GetSingleWordInOperand(1));

View File

@ -321,6 +321,34 @@ OpFunctionEnd
SinglePassRunAndCheck<ReduceLoadSize>(test, test, true, false);
}
TEST_F(ReduceLoadSizeTest, extract_with_no_index) {
const std::string test =
R"(
OpCapability ImageGatherExtended
OpExtension ""
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "P<EFBFBD>Ma'" %12 %17
OpExecutionMode %4 OriginUpperLeft
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%_struct_7 = OpTypeStruct %float %float
%_ptr_Input__struct_7 = OpTypePointer Input %_struct_7
%_ptr_Output__struct_7 = OpTypePointer Output %_struct_7
%12 = OpVariable %_ptr_Input__struct_7 Input
%17 = OpVariable %_ptr_Output__struct_7 Output
%4 = OpFunction %void DontInline|Pure|Const %3
%245 = OpLabel
%13 = OpLoad %_struct_7 %12
%33 = OpCompositeExtract %_struct_7 %13
OpReturn
OpFunctionEnd
)";
auto result = SinglePassRunAndDisassemble<ReduceLoadSize>(test, true, true);
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
}
} // namespace
} // namespace opt
} // namespace spvtools