diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index b2b27bf6a04..7ce48fff7ff 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -1915,6 +1915,32 @@ void get_regs_for_phis(ra_ctx& ctx, Block& block, RegisterFile& register_file, std::vector>& instructions, IDSet& live_in) { + /* assign phis with matching registers to that register */ + for (aco_ptr& phi : block.instructions) { + if (!is_phi(phi)) + break; + Definition& definition = phi->definitions[0]; + if (definition.isKill() || definition.isFixed()) + continue; + + if (!phi->operands[0].isTemp()) + continue; + + PhysReg reg = phi->operands[0].physReg(); + auto OpsSame = [=](const Operand& op) -> bool + { return op.isTemp() && (!op.isFixed() || op.physReg() == reg); }; + bool all_same = std::all_of(phi->operands.cbegin() + 1, phi->operands.cend(), OpsSame); + if (!all_same) + continue; + + if (!get_reg_specified(ctx, register_file, definition.regClass(), phi, reg)) + continue; + + definition.setFixed(reg); + register_file.fill(definition); + ctx.assignments[definition.tempId()].set(definition); + } + /* look up the affinities */ for (aco_ptr& phi : block.instructions) { if (!is_phi(phi)) @@ -1928,15 +1954,6 @@ get_regs_for_phis(ra_ctx& ctx, Block& block, RegisterFile& register_file, assignment& affinity = ctx.assignments[ctx.assignments[definition.tempId()].affinity]; assert(affinity.rc == definition.regClass()); PhysReg reg = affinity.reg; - if (reg == scc) { - /* only use scc if all operands are already placed there */ - bool use_scc = std::all_of(phi->operands.begin(), phi->operands.end(), - [](const Operand& op) { - return op.isTemp() && op.isFixed() && op.physReg() == scc; - }); - if (!use_scc) - continue; - } /* only assign if register is still free */ if (!register_file.test(reg, definition.bytes())) { @@ -1964,10 +1981,8 @@ get_regs_for_phis(ra_ctx& ctx, Block& block, RegisterFile& register_file, const Operand& op = phi->operands[i]; if (!op.isTemp() || !op.isFixed()) continue; + PhysReg reg = op.physReg(); - /* we tried this already on the previous loop */ - if (reg == scc) - continue; if (get_reg_specified(ctx, register_file, definition.regClass(), phi, reg)) { definition.setFixed(reg); break;