[LiveIntervals] Find better anchoring end points when repairing ranges

r175673 changed repairIntervalsInRange to find anchoring end points for
ranges automatically, but the calculation of Begin included the first
instruction found that already had an index. This patch changes it to
exclude that instruction:

1. For symmetry, so that the half open range [Begin,End) only includes
   instructions that do not already have indexes.
2. As a possible performance improvement, since repairOldRegInRange
   will scan fewer instructions.
3. Because repairOldRegInRange hits assertion failures in some cases
   when it sees a def that already has a live interval.

(3) fixes about ten tests in the CodeGen lit test suite when
-early-live-intervals is forced on.

Differential Revision: https://reviews.llvm.org/D110182
This commit is contained in:
Jay Foad 2022-07-18 15:20:06 +01:00
parent c444f03787
commit dbed4326dd
4 changed files with 24 additions and 11 deletions

View File

@ -1662,7 +1662,7 @@ LiveIntervals::repairIntervalsInRange(MachineBasicBlock *MBB,
ArrayRef<Register> OrigRegs) {
// Find anchor points, which are at the beginning/end of blocks or at
// instructions that already have indexes.
while (Begin != MBB->begin() && !Indexes->hasIndex(*Begin))
while (Begin != MBB->begin() && !Indexes->hasIndex(*std::prev(Begin)))
--Begin;
while (End != MBB->end() && !Indexes->hasIndex(*End))
++End;

View File

@ -179,21 +179,12 @@ void SlotIndexes::renumberIndexes(IndexList::iterator curItr) {
void SlotIndexes::repairIndexesInRange(MachineBasicBlock *MBB,
MachineBasicBlock::iterator Begin,
MachineBasicBlock::iterator End) {
// FIXME: Is this really necessary? The only caller repairIntervalsForRange()
// does the same thing.
// Find anchor points, which are at the beginning/end of blocks or at
// instructions that already have indexes.
while (Begin != MBB->begin() && !hasIndex(*Begin))
--Begin;
while (End != MBB->end() && !hasIndex(*End))
++End;
bool includeStart = (Begin == MBB->begin());
SlotIndex startIdx;
if (includeStart)
startIdx = getMBBStartIdx(MBB);
else
startIdx = getInstructionIndex(*Begin);
startIdx = getInstructionIndex(*--Begin);
SlotIndex endIdx;
if (End == MBB->end())

View File

@ -1,4 +1,5 @@
; RUN: llc -march=hexagon < %s | FileCheck %s
; RUN: llc -march=hexagon -early-live-intervals -verify-machineinstrs < %s | FileCheck %s
; CHECK: mpy
; CHECK-NOT: call

View File

@ -662,6 +662,27 @@ TEST(LiveIntervalTest, SplitAtMultiInstruction) {
});
}
TEST(LiveIntervalTest, RepairIntervals) {
liveIntervalTest(R"MIR(
%1:sgpr_32 = IMPLICIT_DEF
dead %2:sgpr_32 = COPY undef %3.sub0:sgpr_128
undef %4.sub2:sgpr_128 = COPY %1:sgpr_32
%5:sgpr_32 = COPY %4.sub2:sgpr_128
)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
MachineInstr &Instr1 = getMI(MF, 1, 0);
MachineInstr &Instr2 = getMI(MF, 2, 0);
MachineInstr &Instr3 = getMI(MF, 3, 0);
LIS.RemoveMachineInstrFromMaps(Instr2);
MachineBasicBlock *MBB = Instr1.getParent();
SmallVector<Register> OrigRegs{
Instr1.getOperand(0).getReg(),
Instr2.getOperand(0).getReg(),
Instr2.getOperand(1).getReg(),
};
LIS.repairIntervalsInRange(MBB, Instr2, Instr3, OrigRegs);
});
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
initLLVM();