From 0211e66f65522caa1f6855b937ae4fc18af0c937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Sun, 2 Apr 2023 22:11:25 +0200 Subject: [PATCH] aco: Don't remove exec writes that also write other registers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't eliminate an instruction that writes registers other than exec and scc. It is possible that this is eg. an s_and_saveexec and the saved value is used by a later branch. Fixes: bc130497472cb4ec4ec60695ed99b169d6681118 Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_ssa_elimination.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/amd/compiler/aco_ssa_elimination.cpp b/src/amd/compiler/aco_ssa_elimination.cpp index c90c29bb2c9..39c33cc19d5 100644 --- a/src/amd/compiler/aco_ssa_elimination.cpp +++ b/src/amd/compiler/aco_ssa_elimination.cpp @@ -596,7 +596,15 @@ eliminate_useless_exec_writes_in_block(ssa_elimination_ctx& ctx, Block& block) /* See if we found an unused exec write. */ if (writes_exec && !exec_write_used) { - instr.reset(); + /* Don't eliminate an instruction that writes registers other than exec and scc. + * It is possible that this is eg. an s_and_saveexec and the saved value is + * used by a later branch. + */ + bool writes_other = std::any_of(instr->definitions.begin(), instr->definitions.end(), + [](const Definition& def) -> bool + { return def.physReg() != exec && def.physReg() != scc; }); + if (!writes_other) + instr.reset(); continue; }