Skip to content

Commit

Permalink
[LiveIntervals] Find better anchoring end points when repairing ranges
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jayfoad committed Jul 18, 2022
1 parent c444f03 commit dbed432
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/LiveIntervals.cpp
Expand Up @@ -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;
Expand Down
11 changes: 1 addition & 10 deletions llvm/lib/CodeGen/SlotIndexes.cpp
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/Hexagon/mulhs.ll
@@ -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
Expand Down
21 changes: 21 additions & 0 deletions llvm/unittests/MI/LiveIntervalTest.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit dbed432

Please sign in to comment.