Mesa (master): aco/spill: don't count phis as variable access

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 13 18:55:19 UTC 2021


Module: Mesa
Branch: master
Commit: dfb10e4f4b7a69474bf29a61c7758204dad7db69
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=dfb10e4f4b7a69474bf29a61c7758204dad7db69

Author: Daniel Schürmann <daniel at schuermann.dev>
Date:   Mon Feb 22 14:57:28 2021 +0100

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 <pendingchaos02 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9196>

---

 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<uint32_t>&
       aco_ptr<Instruction>& 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<uint32_t, uint32_t> 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<uint32_t, uint32_t>{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());



More information about the mesa-commit mailing list