From 294be6b5d32e1fe44d0b36cd46b2931c5f0634c4 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Wed, 15 Jul 2020 17:26:37 -0700 Subject: [PATCH] [CalcSpillWeights] Propagate the fact that a live-interval is not spillable When we calculate the weight of a live-interval, add some code to check if the original live-interval was markied as not spillable and if so, progagate that information down to the new interval. Previously we would just recompute a weight for the new interval, thus, we could in theory just spill live-intervals marked as not spillable by just splitting them. That goes against the spirit of a non-spillable live-interval. E.g., previously we could do: v1 = // v1 must not be spilled ... = v1 Split: v1 = // v1 must not be spilled ... v2 = v1 // v2 can be spilled ... v3 = v2 // v3 can be spilled = v3 There's no test case for that one as we would need to split a non-spillable live-interval without using LiveRangeEdit to see this happening. RegAlloc inserts non-spillable intervals only as part of the spilling mechanism, thus at this point the intervals are not splittable anymore. On top of that, RegAlloc uses the LiveRangeEdit API, which already properly propagate that information. In other words, this could only happen if a target was to mark a live-interval as not spillable before register allocation and split it without using LRE, e.g., through LiveIntervals::splitSeparateComponent. --- llvm/lib/CodeGen/CalcSpillWeights.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp b/llvm/lib/CodeGen/CalcSpillWeights.cpp index 5d6ee09..2545036 100644 --- a/llvm/lib/CodeGen/CalcSpillWeights.cpp +++ b/llvm/lib/CodeGen/CalcSpillWeights.cpp @@ -161,6 +161,17 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &li, SlotIndex *start, std::pair TargetHint = mri.getRegAllocationHint(li.reg); + if (li.isSpillable() && VRM) { + Register Reg = li.reg; + Register Original = VRM->getOriginal(Reg); + const LiveInterval &OrigInt = LIS.getInterval(Original); + // li comes from a split of OrigInt. If OrigInt was marked + // as not spillable, make sure the new interval is marked + // as not spillable as well. + if (!OrigInt.isSpillable()) + li.markNotSpillable(); + } + // Don't recompute spill weight for an unspillable register. bool Spillable = li.isSpillable(); -- 2.7.4