Skip to content

Commit 799cfed

Browse files
committed
Remove manual recomputation of live intervals, use the LIS methods
This fails in some complex use cases, and it is not clear whether it is meaningfully faster that just letting the LIS object recompute it from scratch. Also removed stale comment in isTriviallyRematerilizable: we can now remat MIs with virtual register uses.
1 parent 1fca0f9 commit 799cfed

File tree

1 file changed

+3
-40
lines changed

1 file changed

+3
-40
lines changed

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,6 @@ void PreRARematStage::rematerialize() {
20652065
// Collect regions whose RP changes in unpredictable way; we will have to
20662066
// fully recompute their RP after all rematerailizations.
20672067
DenseSet<unsigned> RecomputeRP;
2068-
SlotIndexes *Slots = DAG.LIS->getSlotIndexes();
20692068

20702069
// Rematerialize all instructions.
20712070
for (auto &[DefMI, Remat] : Rematerializations) {
@@ -2147,41 +2146,10 @@ void PreRARematStage::rematerialize() {
21472146
ImpactedRegions.insert({DefRegion, DAG.Pressure[DefRegion]});
21482147
RecomputeRP.insert(DefRegion);
21492148

2150-
// Update the register's live interval manually. This is aligned with the
2151-
// instruction collection phase in that it assumes a single def and use
2152-
// (possibly subreg).
2153-
SlotIndex NewDef = Slots->getInstructionIndex(*Remat.RematMI).getRegSlot();
2154-
SlotIndex NewKill = Slots->getInstructionIndex(*Remat.UseMI).getRegSlot();
2155-
2156-
// Update the live range to reflect the register's rematerialization. We
2157-
// will have a single segment (we only remat regs with one use) and at most
2158-
// a single value number (we only remat virtual regs with a single def).
2159-
auto UpdateLiveRange = [&](LiveRange &LR) -> void {
2160-
assert(LR.segments.size() && "expected at least one segment");
2161-
assert(LR.valnos.size() < 2 && "expected at most one value number");
2162-
2163-
// Fix up the first segment and remove the others which have become
2164-
// unnecessary by construction.
2165-
LR.segments.truncate(1);
2166-
LiveRange::Segment &Seg = LR.segments.front();
2167-
Seg.start = NewDef;
2168-
Seg.end = NewKill;
2169-
LR.valnos.clear();
2170-
if (Seg.valno) {
2171-
// If present, update the segment's value number as well.
2172-
Seg.valno->def = NewDef;
2173-
LR.valnos.push_back(Seg.valno);
2174-
}
2175-
};
2176-
2149+
// Recompute live interval to reflect the register's rematerialization.
21772150
Register RematReg = Remat.RematMI->getOperand(0).getReg();
2178-
LiveInterval &RegLI = DAG.LIS->getInterval(RematReg);
2179-
UpdateLiveRange(RegLI);
2180-
if (RegLI.hasSubRanges()) {
2181-
LiveInterval::SubRange &SubRange = *RegLI.subrange_begin();
2182-
assert(!SubRange.Next && "expected at most one subrange");
2183-
UpdateLiveRange(SubRange);
2184-
}
2151+
DAG.LIS->removeInterval(RematReg);
2152+
DAG.LIS->createAndComputeVirtRegInterval(RematReg);
21852153
}
21862154

21872155
// All regions impacted by at least one rematerialization must be rescheduled.
@@ -2221,11 +2189,6 @@ bool PreRARematStage::isTriviallyReMaterializable(const MachineInstr &MI) {
22212189
if (!DAG.TII->isTriviallyReMaterializable(MI))
22222190
return false;
22232191

2224-
// Even though TargetInstrInfo::isReallyTriviallyReMaterializable already
2225-
// ensures that the instruction has no virtual register uses,
2226-
// SIInstrInfo::isReallyTriviallyReMaterializable may consider an instruction
2227-
// rematerializable and return before calling its parent's method, so we need
2228-
// to double-check here.
22292192
for (const MachineOperand &MO : MI.all_uses()) {
22302193
// We can't remat physreg uses, unless it is a constant or an ignorable
22312194
// use (e.g. implicit exec use on VALU instructions)

0 commit comments

Comments
 (0)