From dfb10e4f4b7a69474bf29a61c7758204dad7db69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 22 Feb 2021 14:57:28 +0100 Subject: [PATCH] aco/spill: don't count phis as variable access This increases the chance of evicting phis if these have longer next-use distances. Totals from 6 (0.00% of 146267) affected shaders (Navi10): CodeSize: 476992 -> 464388 (-2.64%) Instrs: 81785 -> 79952 (-2.24%) VClause: 2380 -> 2374 (-0.25%) Copies: 26836 -> 25131 (-6.35%) Branches: 2494 -> 2492 (-0.08%) Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_spill.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/amd/compiler/aco_spill.cpp b/src/amd/compiler/aco_spill.cpp index dbf259e85da..49f2b041615 100644 --- a/src/amd/compiler/aco_spill.cpp +++ b/src/amd/compiler/aco_spill.cpp @@ -184,15 +184,22 @@ void next_uses_per_block(spill_ctx& ctx, unsigned block_idx, std::set& aco_ptr& instr = block->instructions[idx]; assert(instr->opcode == aco_opcode::p_linear_phi || instr->opcode == aco_opcode::p_phi); + if (!instr->definitions[0].isTemp()) { + idx--; + continue; + } + + auto it = next_uses.find(instr->definitions[0].getTemp()); + std::pair distance = it == next_uses.end() ? std::make_pair(block_idx, 0u) : it->second; for (unsigned i = 0; i < instr->operands.size(); i++) { unsigned pred_idx = instr->opcode == aco_opcode::p_phi ? block->logical_preds[i] : block->linear_preds[i]; if (instr->operands[i].isTemp()) { if (ctx.next_use_distances_end[pred_idx].find(instr->operands[i].getTemp()) == ctx.next_use_distances_end[pred_idx].end() || - ctx.next_use_distances_end[pred_idx][instr->operands[i].getTemp()] != std::pair{block_idx, 0}) + ctx.next_use_distances_end[pred_idx][instr->operands[i].getTemp()] != distance) worklist.insert(pred_idx); - ctx.next_use_distances_end[pred_idx][instr->operands[i].getTemp()] = {block_idx, 0}; + ctx.next_use_distances_end[pred_idx][instr->operands[i].getTemp()] = distance; } } next_uses.erase(instr->definitions[0].getTemp());