Fixes https://crbug.com/1395415

* Block merging needed to invalid structured cfg analysis
This commit is contained in:
alan-baker 2022-12-12 10:49:59 -05:00 коммит произвёл GitHub
Родитель 9c6a925c87
Коммит 235182cfee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 38 добавлений и 0 удалений

Просмотреть файл

@ -171,6 +171,11 @@ void MergeWithSuccessor(IRContext* context, Function* func,
// sbi must follow bi in func's ordering.
assert(sbi != func->end());
if (sbi->tail()->opcode() == spv::Op::OpSwitch &&
sbi->MergeBlockIdIfAny() != 0) {
context->InvalidateAnalyses(IRContext::Analysis::kAnalysisStructuredCFG);
}
// Update the inst-to-block mapping for the instructions in sbi.
for (auto& inst : *sbi) {
context->set_instr_block(&inst, &*bi);

Просмотреть файл

@ -1287,6 +1287,39 @@ OpFunctionEnd
EXPECT_EQ(opt::Pass::Status::SuccessWithoutChange, std::get<1>(result));
}
TEST_F(BlockMergeTest, RebuildStructuredCFG) {
const std::string text = R"(
; CHECK: = OpFunction
; CHECK-NEXT: [[entry:%\w+]] = OpLabel
; CHECK-NEXT: OpSelectionMerge [[merge:%\w+]] None
; CHECK-NEXT: OpSwitch {{%\w+}} [[merge]] 0 [[other:%\w+]]
; CHECK [[other]] = OpLabel
; CHECK: OpBranch [[merge]]
; CHECK [[merge]] = OpLabel
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
%void = OpTypeVoid
%int = OpTypeInt 32 0
%int_1 = OpConstant %int 1
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
OpBranch %switch
%switch = OpLabel
OpSelectionMerge %merge None
OpSwitch %int_1 %merge 0 %other
%other = OpLabel
OpBranch %merge
%merge = OpLabel
OpReturn
OpFunctionEnd
)";
SinglePassRunAndMatch<BlockMergePass>(text, true);
}
// TODO(greg-lunarg): Add tests to verify handling of these cases:
//
// More complex control flow