Skip to content

Commit 0b464e4

Browse files
committedJan 16, 2018
[LiveDebugValues] recognize spilled reg killed in instruction after spill
Current condition for spill instruction recognition in LiveDebugValues does not recognize case when register is spilled and killed in next instruction. Patch by Nikola Prica. Differential Revision: https://reviews.llvm.org/D41226 llvm-svn: 322554
1 parent 85e6139 commit 0b464e4

File tree

2 files changed

+417
-7
lines changed

2 files changed

+417
-7
lines changed
 

‎llvm/lib/CodeGen/LiveDebugValues.cpp

+30-7
Original file line numberDiff line numberDiff line change
@@ -426,16 +426,39 @@ bool LiveDebugValues::isSpillInstruction(const MachineInstr &MI,
426426
FrameInfo.isSpillSlotObjectIndex(FI)))
427427
return false;
428428

429-
// In a spill instruction generated by the InlineSpiller the spilled register
430-
// has its kill flag set. Return false if we don't find such a register.
431-
Reg = 0;
429+
auto isKilledReg = [&](const MachineOperand MO, unsigned &Reg) {
430+
if (!MO.isReg() || !MO.isUse()) {
431+
Reg = 0;
432+
return false;
433+
}
434+
Reg = MO.getReg();
435+
return MO.isKill();
436+
};
437+
432438
for (const MachineOperand &MO : MI.operands()) {
433-
if (MO.isReg() && MO.isUse() && MO.isKill()) {
434-
Reg = MO.getReg();
435-
break;
439+
// In a spill instruction generated by the InlineSpiller the spilled
440+
// register has its kill flag set.
441+
if (isKilledReg(MO, Reg))
442+
return true;
443+
if (Reg != 0) {
444+
// Check whether next instruction kills the spilled register.
445+
// FIXME: Current solution does not cover search for killed register in
446+
// bundles and instructions further down the chain.
447+
auto NextI = std::next(MI.getIterator());
448+
// Skip next instruction that points to basic block end iterator.
449+
if (MI.getParent()->end() == NextI)
450+
continue;
451+
unsigned RegNext;
452+
for (const MachineOperand &MONext : NextI->operands()) {
453+
// Return true if we came across the register from the
454+
// previous spill instruction that is killed in NextI.
455+
if (isKilledReg(MONext, RegNext) && RegNext == Reg)
456+
return true;
457+
}
436458
}
437459
}
438-
return Reg != 0;
460+
// Return false if we didn't find spilled register.
461+
return false;
439462
}
440463

441464
/// A spilled register may indicate that we have to end the current range of

0 commit comments

Comments
 (0)
Please sign in to comment.