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 */