aco: Fix invalidated reference in branching sequence optimization.

Inserting in the instructions vector may invalidate the exec_val reference,
so do that last.

Fixes: baab6f18c9 ("aco: Optimize branching sequence during SSA elimination.")
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18049>
This commit is contained in:
Timur Kristóf
2022-08-14 15:15:18 +02:00
committed by Marge Bot
parent 2e9044766e
commit d88b2e4ab5
+13 -10
View File
@@ -411,16 +411,6 @@ try_optimize_branching_sequence(ssa_elimination_ctx& ctx, Block& block, const in
exec_copy->operands[0] = Operand(exec, ctx.program->lane_mask);
}
if (save_original_exec) {
/* Insert a new instruction that saves the original exec before it is overwritten. */
const auto it = std::next(block.instructions.begin(), save_original_exec_idx);
aco_ptr<Instruction> copy(
create_instruction<Pseudo_instruction>(aco_opcode::p_parallelcopy, Format::PSEUDO, 1, 1));
copy->definitions[0] = exec_copy_def;
copy->operands[0] = Operand(exec, ctx.program->lane_mask);
block.instructions.insert(it, std::move(copy));
}
if (exec_val->opcode == aco_opcode::p_parallelcopy && exec_val->operands[0].isConstant() &&
exec_val->operands[0].constantValue()) {
/* Remove the branch instruction when exec is constant non-zero. */
@@ -428,6 +418,19 @@ try_optimize_branching_sequence(ssa_elimination_ctx& ctx, Block& block, const in
if (branch->isBranch() && branch->operands.size() && branch->operands[0].physReg() == exec)
block.instructions.back().reset();
}
if (save_original_exec) {
/* Insert a new instruction that saves the original exec before it is overwritten.
* Do this last, because inserting in the instructions vector may invalidate the exec_val
* reference.
*/
const auto it = std::next(block.instructions.begin(), save_original_exec_idx);
aco_ptr<Instruction> copy(
create_instruction<Pseudo_instruction>(aco_opcode::p_parallelcopy, Format::PSEUDO, 1, 1));
copy->definitions[0] = exec_copy_def;
copy->operands[0] = Operand(exec, ctx.program->lane_mask);
block.instructions.insert(it, std::move(copy));
}
}
void