From 898fd9227a7e4d5bf2a6ff5c3cce17dc7d0fc964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 14 Mar 2024 15:16:02 +0100 Subject: [PATCH] aco/spill: keep loop variables spilled during nested loops Totals from 36 (0.05% of 79395) affected shaders: (GFX11) Instrs: 2775993 -> 2781480 (+0.20%); split: -0.01%, +0.20% CodeSize: 14184524 -> 14231956 (+0.33%); split: -0.01%, +0.34% SpillSGPRs: 1441 -> 1207 (-16.24%) SpillVGPRs: 477 -> 421 (-11.74%) Scratch: 35840 -> 35072 (-2.14%) Latency: 15559241 -> 15606047 (+0.30%); split: -0.01%, +0.31% InvThroughput: 3787994 -> 3803749 (+0.42%); split: -0.02%, +0.44% VClause: 76422 -> 76411 (-0.01%) SClause: 55717 -> 55671 (-0.08%); split: -0.10%, +0.01% Copies: 214877 -> 215185 (+0.14%); split: -0.04%, +0.18% Branches: 93158 -> 93129 (-0.03%); split: -0.03%, +0.00% VALU: 1520556 -> 1525425 (+0.32%); split: -0.00%, +0.32% SALU: 341104 -> 341408 (+0.09%); split: -0.02%, +0.11% VMEM: 119673 -> 119617 (-0.05%) Part-of: --- src/amd/compiler/aco_spill.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/amd/compiler/aco_spill.cpp b/src/amd/compiler/aco_spill.cpp index dfcedaf6520..92304dfacaf 100644 --- a/src/amd/compiler/aco_spill.cpp +++ b/src/amd/compiler/aco_spill.cpp @@ -144,8 +144,8 @@ struct spill_ctx { const uint32_t spill_id = allocate_spill_id(to_spill.regClass()); for (auto pair : spills) add_interference(spill_id, pair.second); - for (loop_info info : loop) { - for (auto pair : info.spills) + if (!loop.empty()) { + for (auto pair : loop.back().spills) add_interference(spill_id, pair.second); } @@ -542,6 +542,17 @@ init_live_in_vars(spill_ctx& ctx, Block* block, unsigned block_idx) spilled_registers += spilled.first; loop_demand -= spilled.first; } + if (!ctx.loop.empty()) { + /* If this is a nested loop, keep variables from the outer loop spilled. */ + for (auto spilled : ctx.loop.back().spills) { + assert(next_use_distances.count(spilled.first)); + + if (ctx.spills_entry[block_idx].insert(spilled).second) { + spilled_registers += spilled.first; + loop_demand -= spilled.first; + } + } + } /* select more live-through variables and constants */ RegType type = RegType::vgpr;