Fix removal of dependent non-semantic instructions (#5122)

Fixes #5121

* If the non-semantic info instructions depended on other moved
  instructions the def/use manager would get corrupted.
This commit is contained in:
alan-baker 2023-02-23 20:10:35 -05:00 committed by GitHub
parent 4183faa2ec
commit 5d2bc6f064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -37,7 +37,9 @@ Module::iterator EliminateFunction(IRContext* context,
assert(inst->IsNonSemanticInstruction()); assert(inst->IsNonSemanticInstruction());
if (to_kill.find(inst) != to_kill.end()) return; if (to_kill.find(inst) != to_kill.end()) return;
std::unique_ptr<Instruction> clone(inst->Clone(context)); std::unique_ptr<Instruction> clone(inst->Clone(context));
context->ForgetUses(inst); // Clear uses of "inst" to in case this moves a dependent chain of
// instructions.
context->get_def_use_mgr()->ClearInst(inst);
context->AnalyzeDefUse(clone.get()); context->AnalyzeDefUse(clone.get());
if (first_func) { if (first_func) {
context->AddGlobalValue(std::move(clone)); context->AddGlobalValue(std::move(clone));

View File

@ -517,6 +517,39 @@ OpFunctionEnd
SinglePassRunAndMatch<EliminateDeadFunctionsPass>(text, true); SinglePassRunAndMatch<EliminateDeadFunctionsPass>(text, true);
} }
TEST_F(EliminateDeadFunctionsBasicTest, DependentNonSemanticChain) {
const std::string text = R"(
; CHECK: OpEntryPoint GLCompute [[main:%\w+]]
; CHECK: [[main]] = OpFunction
; CHECK-NOT: = OpFunction
; CHECK: [[ext1:%\w+]] = OpExtInst %void {{%\w+}} 1 [[main]]
; CHECK: [[ext2:%\w+]] = OpExtInst %void {{%\w+}} 2 [[ext1]]
; CHECK: [[ext3:%\w+]] = OpExtInst %void {{%\w+}} 3 [[ext1]] [[ext2]]
OpCapability Shader
OpExtension "SPV_KHR_non_semantic_info"
%1 = OpExtInstImport "NonSemantic.Test"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
%void = OpTypeVoid
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%main_entry = OpLabel
OpReturn
OpFunctionEnd
%dead = OpFunction %void None %void_fn
%dead_entry = OpLabel
OpReturn
OpFunctionEnd
%2 = OpExtInst %void %1 1 %main
%3 = OpExtInst %void %1 2 %2
%4 = OpExtInst %void %1 3 %2 %3
)";
SetTargetEnv(SPV_ENV_VULKAN_1_0);
SinglePassRunAndMatch<EliminateDeadFunctionsPass>(text, true);
}
} // namespace } // namespace
} // namespace opt } // namespace opt
} // namespace spvtools } // namespace spvtools