Recompute kill flags from live intervals after coalescing instead of trying to

update them. Computing kill flags is notoriously difficult, and the coalescer
would get it wrong sometimes, and it would completely skip physical registers.

Now we simply remove kill flags based on the live intervals after coalescing.
This is a few percent slower, but now we get correct kill flags for physical
registers after coalescing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen 2010-04-28 18:28:39 +00:00
parent 7261fb2a6f
commit 0fd109963a
2 changed files with 21 additions and 49 deletions

View File

@ -236,7 +236,7 @@ bool SimpleRegisterCoalescing::AdjustCopiesBackFrom(LiveInterval &IntA,
// If the copy instruction was killing the destination register before the
// merge, find the last use and trim the live range. That will also add the
// isKill marker.
if (CopyMI->killsRegister(IntA.reg))
if (ALR->valno->isKill(CopyIdx))
TrimLiveIntervalToLastUse(CopyUseIdx, CopyMI->getParent(), IntA, ALR);
++numExtends;
@ -709,7 +709,7 @@ bool SimpleRegisterCoalescing::ReMaterializeTrivialDef(LiveInterval &SrcInt,
// kill.
bool checkForDeadDef = false;
MachineBasicBlock *MBB = CopyMI->getParent();
if (CopyMI->killsRegister(SrcInt.reg))
if (SrcLR->valno->isKill(DefIdx))
if (!TrimLiveIntervalToLastUse(CopyIdx, MBB, SrcInt, SrcLR)) {
checkForDeadDef = true;
}
@ -837,9 +837,6 @@ SimpleRegisterCoalescing::UpdateRegDefsUses(unsigned SrcReg, unsigned DstReg,
assert(OldSubIdx < SubIdx && "Conflicting sub-register index!");
else if (SubIdx)
O.setSubReg(SubIdx);
// Remove would-be duplicated kill marker.
if (O.isKill() && UseMI->killsRegister(DstReg))
O.setIsKill(false);
O.setReg(DstReg);
// After updating the operand, check if the machine instruction has
@ -866,38 +863,6 @@ SimpleRegisterCoalescing::UpdateRegDefsUses(unsigned SrcReg, unsigned DstReg,
}
}
/// RemoveUnnecessaryKills - Remove kill markers that are no longer accurate
/// due to live range lengthening as the result of coalescing.
void SimpleRegisterCoalescing::RemoveUnnecessaryKills(unsigned Reg,
LiveInterval &LI) {
for (MachineRegisterInfo::use_iterator UI = mri_->use_begin(Reg),
UE = mri_->use_end(); UI != UE; ++UI) {
MachineOperand &UseMO = UI.getOperand();
if (!UseMO.isKill())
continue;
MachineInstr *UseMI = UseMO.getParent();
SlotIndex UseIdx =
li_->getInstructionIndex(UseMI).getUseIndex();
const LiveRange *LR = LI.getLiveRangeContaining(UseIdx);
if (!LR ||
(!LR->valno->isKill(UseIdx.getDefIndex()) &&
LR->valno->def != UseIdx.getDefIndex())) {
// Interesting problem. After coalescing reg1027's def and kill are both
// at the same point: %reg1027,0.000000e+00 = [56,814:0) 0@70-(814)
//
// bb5:
// 60 %reg1027<def> = t2MOVr %reg1027, 14, %reg0, %reg0
// 68 %reg1027<def> = t2LDRi12 %reg1027<kill>, 8, 14, %reg0
// 76 t2CMPzri %reg1038<kill,undef>, 0, 14, %reg0, %CPSR<imp-def>
// 84 %reg1027<def> = t2MOVr %reg1027, 14, %reg0, %reg0
// 96 t2Bcc mbb<bb5,0x2030910>, 1, %CPSR<kill>
//
// Do not remove the kill marker on t2LDRi12.
UseMO.setIsKill(false);
}
}
}
/// removeIntervalIfEmpty - Check if the live interval of a physical register
/// is empty, if so remove it and also remove the empty intervals of its
/// sub-registers. Return true if live interval is removed.
@ -1811,12 +1776,6 @@ bool SimpleRegisterCoalescing::JoinCopy(CopyRec &TheCopy, bool &Again) {
// Remember to delete the copy instruction.
JoinedCopies.insert(CopyMI);
// Some live range has been lengthened due to colaescing, eliminate the
// unnecessary kills.
RemoveUnnecessaryKills(SrcReg, *ResDstInt);
if (TargetRegisterInfo::isVirtualRegister(DstReg))
RemoveUnnecessaryKills(DstReg, *ResDstInt);
UpdateRegDefsUses(SrcReg, DstReg, SubIdx);
// If we have extended the live range of a physical register, make sure we
@ -2825,8 +2784,25 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) {
li_->RemoveMachineInstrFromMaps(MI);
mii = mbbi->erase(mii);
++numPeep;
} else {
++mii;
continue;
}
++mii;
// Check for now unnecessary kill flags.
if (li_->isNotInMIMap(MI)) continue;
SlotIndex UseIdx = li_->getInstructionIndex(MI).getUseIndex();
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI->getOperand(i);
if (!MO.isReg() || !MO.isKill()) continue;
unsigned reg = MO.getReg();
if (!reg || !li_->hasInterval(reg)) continue;
LiveInterval &LI = li_->getInterval(reg);
const LiveRange *LR = LI.getLiveRangeContaining(UseIdx);
if (!LR ||
(!LR->valno->isKill(UseIdx.getDefIndex()) &&
LR->valno->def != UseIdx.getDefIndex()))
MO.setIsKill(false);
}
}
}

View File

@ -223,10 +223,6 @@ namespace llvm {
/// subregister.
void UpdateRegDefsUses(unsigned SrcReg, unsigned DstReg, unsigned SubIdx);
/// RemoveUnnecessaryKills - Remove kill markers that are no longer accurate
/// due to live range lengthening as the result of coalescing.
void RemoveUnnecessaryKills(unsigned Reg, LiveInterval &LI);
/// ShortenDeadCopyLiveRange - Shorten a live range defined by a dead copy.
/// Return true if live interval is removed.
bool ShortenDeadCopyLiveRange(LiveInterval &li, MachineInstr *CopyMI);