Mesa (master): aco: Keep live-though variables and constants spilled.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 11 12:35:23 UTC 2021


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

Author: Timur Kristóf <timur.kristof at gmail.com>
Date:   Wed Nov 25 19:57:05 2020 +0100

aco: Keep live-though variables and constants spilled.

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 <daniel at schuermann.dev>
Signed-off-by: Timur Kristóf <timur.kristof at gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8026>

---

 src/amd/compiler/aco_spill.cpp | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 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<Temp, std::pair<uint32_t, uint32_t>> pair : ctx.next_use_distances_end[block_idx - 1]) {
-         if (pair.second.first < loop_end)
-            continue;
+      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);
 
-         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())
+         /* variable is not even live at the predecessor: probably from a phi */
+         if (it == map.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 */



More information about the mesa-commit mailing list