aco: fix consecutive exec writes when finding exec_copy instruction

This can happen with transitions to exact:
 s2: %0:exec = p_parallelcopy %622:s[0-1]
 s2: %625:s[0-1],  s1: %624:scc,  s2: %0:exec = s_and_saveexec_b64 %141:vcc, %0:exec
 s2: %626:s[12-13] = p_cbranch_z %0:exec BB2, BB1

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Fixes: 410eff4d2f ("aco: Fix optimizing branching sequence with s_and_saveexec.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18077>
This commit is contained in:
Rhys Perry 2022-08-15 17:46:50 +01:00 committed by Marge Bot
parent c50493974e
commit e493aab3c3

View file

@ -551,6 +551,7 @@ eliminate_useless_exec_writes_in_block(ssa_elimination_ctx& ctx, Block& block)
bool logical_end_found = false;
bool branch_reads_exec = false;
bool branch_exec_val_found = false;
int branch_exec_val_idx = -1;
int branch_exec_copy_idx = -1;
unsigned branch_exec_tempid = 0;
@ -581,13 +582,15 @@ eliminate_useless_exec_writes_in_block(ssa_elimination_ctx& ctx, Block& block)
/* For a newly encountered exec write, clear the used flag. */
if (writes_exec) {
if (!logical_end_found && branch_reads_exec && instr->operands.size()) {
if (!logical_end_found && branch_reads_exec && instr->operands.size() &&
!branch_exec_val_found) {
/* We are in a branch that jumps according to exec.
* We just found the instruction that copies to exec before the branch.
*/
assert(branch_exec_copy_idx == -1);
branch_exec_copy_idx = i;
branch_exec_tempid = instr->operands[0].tempId();
branch_exec_val_found = true;
} else if (branch_exec_val_idx == -1) {
/* The current instruction overwrites exec before branch_exec_val_idx was
* found, therefore we can't optimize the branching sequence.