From b03fbec4f1640a7e5eaae488249d88138d3338be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Wed, 25 Nov 2020 19:57:05 +0100 Subject: [PATCH] aco: Keep live-though variables and constants spilled. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This noticably reduces the amount of dead code emitted by our spiller, when eg. previously a constant was spilled then rematerialized before a loop, but then spilled again inside the loop. Fossil DB changes on Navi 10: Totals from 263 (0.19% of 139391) affected shaders: VGPRs: 30044 -> 30028 (-0.05%) SpillSGPRs: 8800 -> 4948 (-43.77%) CodeSize: 4496040 -> 4335448 (-3.57%); split: -3.57%, +0.00% Instrs: 843942 -> 819219 (-2.93%); split: -2.93%, +0.00% Cycles: 76485744 -> 73549080 (-3.84%); split: -4.04%, +0.20% VMEM: 38204 -> 38147 (-0.15%); split: +0.08%, -0.23% SMEM: 17872 -> 17959 (+0.49%) SClause: 24298 -> 24012 (-1.18%) Copies: 98023 -> 82960 (-15.37%); split: -15.38%, +0.01% Branches: 29074 -> 27632 (-4.96%) PreVGPRs: 25291 -> 25241 (-0.20%) Co-authored-by: Daniel Schürmann Signed-off-by: Timur Kristóf Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_spill.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/amd/compiler/aco_spill.cpp b/src/amd/compiler/aco_spill.cpp index 8560986086b..68af30c1016 100644 --- a/src/amd/compiler/aco_spill.cpp +++ b/src/amd/compiler/aco_spill.cpp @@ -384,18 +384,19 @@ RegisterDemand init_live_in_vars(spill_ctx& ctx, Block* block, unsigned block_id } unsigned loop_end = i; - /* keep live-through spilled */ - for (std::pair> pair : ctx.next_use_distances_end[block_idx - 1]) { - if (pair.second.first < loop_end) + for (auto spilled : ctx.spills_exit[block_idx - 1]) { + auto map = ctx.next_use_distances_end[block_idx - 1]; + auto it = map.find(spilled.first); + + /* variable is not even live at the predecessor: probably from a phi */ + if (it == map.end()) continue; - Temp to_spill = pair.first; - auto it = ctx.spills_exit[block_idx - 1].find(to_spill); - if (it == ctx.spills_exit[block_idx - 1].end()) - continue; - - ctx.spills_entry[block_idx][to_spill] = it->second; - spilled_registers += to_spill; + /* keep constants and live-through variables spilled */ + if (it->second.first >= loop_end || ctx.remat.count(spilled.first)) { + ctx.spills_entry[block_idx][spilled.first] = spilled.second; + spilled_registers += spilled.first; + } } /* select live-through vgpr variables */