mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-26 23:29:22 +00:00
Fix inverted conflict test in -early-coalesce.
A non-identity copy cannot be coalesced when the phi join destination register is live at the copy site. Also verify the condition that the PHI join source register is only used in the PHI join. Otherwise the coalescing is invalid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86322 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
12d53dba36
commit
3de23e6f6c
@ -290,9 +290,10 @@ namespace llvm {
|
|||||||
/// computeIntervals - Compute live intervals.
|
/// computeIntervals - Compute live intervals.
|
||||||
void computeIntervals();
|
void computeIntervals();
|
||||||
|
|
||||||
bool isProfitableToCoalesce(LiveInterval &DstInt, LiveInterval &SrcInt,
|
bool isSafeAndProfitableToCoalesce(LiveInterval &DstInt,
|
||||||
SmallVector<MachineInstr*,16> &IdentCopies,
|
LiveInterval &SrcInt,
|
||||||
SmallVector<MachineInstr*,16> &OtherCopies);
|
SmallVector<MachineInstr*,16> &IdentCopies,
|
||||||
|
SmallVector<MachineInstr*,16> &OtherCopies);
|
||||||
|
|
||||||
void performEarlyCoalescing();
|
void performEarlyCoalescing();
|
||||||
|
|
||||||
|
@ -646,17 +646,17 @@ void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
|
|||||||
0, false, VNInfoAllocator);
|
0, false, VNInfoAllocator);
|
||||||
vni->setIsPHIDef(true);
|
vni->setIsPHIDef(true);
|
||||||
LiveRange LR(start, end, vni);
|
LiveRange LR(start, end, vni);
|
||||||
|
|
||||||
interval.addRange(LR);
|
interval.addRange(LR);
|
||||||
LR.valno->addKill(end);
|
LR.valno->addKill(end);
|
||||||
DEBUG(errs() << " +" << LR << '\n');
|
DEBUG(errs() << " +" << LR << '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool LiveIntervals::
|
||||||
LiveIntervals::isProfitableToCoalesce(LiveInterval &DstInt, LiveInterval &SrcInt,
|
isSafeAndProfitableToCoalesce(LiveInterval &DstInt,
|
||||||
SmallVector<MachineInstr*,16> &IdentCopies,
|
LiveInterval &SrcInt,
|
||||||
SmallVector<MachineInstr*,16> &OtherCopies) {
|
SmallVector<MachineInstr*,16> &IdentCopies,
|
||||||
bool HaveConflict = false;
|
SmallVector<MachineInstr*,16> &OtherCopies) {
|
||||||
unsigned NumIdent = 0;
|
unsigned NumIdent = 0;
|
||||||
for (MachineRegisterInfo::def_iterator ri = mri_->def_begin(SrcInt.reg),
|
for (MachineRegisterInfo::def_iterator ri = mri_->def_begin(SrcInt.reg),
|
||||||
re = mri_->def_end(); ri != re; ++ri) {
|
re = mri_->def_end(); ri != re; ++ri) {
|
||||||
@ -665,16 +665,16 @@ LiveIntervals::isProfitableToCoalesce(LiveInterval &DstInt, LiveInterval &SrcInt
|
|||||||
if (!tii_->isMoveInstr(*MI, SrcReg, DstReg, SrcSubReg, DstSubReg))
|
if (!tii_->isMoveInstr(*MI, SrcReg, DstReg, SrcSubReg, DstSubReg))
|
||||||
return false;
|
return false;
|
||||||
if (SrcReg != DstInt.reg) {
|
if (SrcReg != DstInt.reg) {
|
||||||
|
// Non-identity copy - we cannot handle overlapping intervals
|
||||||
|
if (DstInt.liveAt(getInstructionIndex(MI)))
|
||||||
|
return false;
|
||||||
OtherCopies.push_back(MI);
|
OtherCopies.push_back(MI);
|
||||||
HaveConflict |= DstInt.liveAt(getInstructionIndex(MI));
|
|
||||||
} else {
|
} else {
|
||||||
IdentCopies.push_back(MI);
|
IdentCopies.push_back(MI);
|
||||||
++NumIdent;
|
++NumIdent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HaveConflict)
|
|
||||||
return false; // Let coalescer handle it
|
|
||||||
return IdentCopies.size() > OtherCopies.size();
|
return IdentCopies.size() > OtherCopies.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -701,19 +701,21 @@ void LiveIntervals::performEarlyCoalescing() {
|
|||||||
LiveInterval &SrcInt = getInterval(PHISrc);
|
LiveInterval &SrcInt = getInterval(PHISrc);
|
||||||
SmallVector<MachineInstr*, 16> IdentCopies;
|
SmallVector<MachineInstr*, 16> IdentCopies;
|
||||||
SmallVector<MachineInstr*, 16> OtherCopies;
|
SmallVector<MachineInstr*, 16> OtherCopies;
|
||||||
if (!isProfitableToCoalesce(DstInt, SrcInt, IdentCopies, OtherCopies))
|
if (!isSafeAndProfitableToCoalesce(DstInt, SrcInt,
|
||||||
|
IdentCopies, OtherCopies))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DEBUG(errs() << "PHI Join: " << *Join);
|
DEBUG(errs() << "PHI Join: " << *Join);
|
||||||
assert(DstInt.containsOneValue() && "PHI join should have just one val#!");
|
assert(DstInt.containsOneValue() && "PHI join should have just one val#!");
|
||||||
|
assert(std::distance(mri_->use_begin(PHISrc), mri_->use_end()) == 1 &&
|
||||||
|
"PHI join src should not be used elsewhere");
|
||||||
VNInfo *VNI = DstInt.getValNumInfo(0);
|
VNInfo *VNI = DstInt.getValNumInfo(0);
|
||||||
|
|
||||||
// Change the non-identity copies to directly target the phi destination.
|
// Change the non-identity copies to directly target the phi destination.
|
||||||
for (unsigned i = 0, e = OtherCopies.size(); i != e; ++i) {
|
for (unsigned i = 0, e = OtherCopies.size(); i != e; ++i) {
|
||||||
MachineInstr *PHICopy = OtherCopies[i];
|
MachineInstr *PHICopy = OtherCopies[i];
|
||||||
DEBUG(errs() << "Moving: " << *PHICopy);
|
|
||||||
|
|
||||||
SlotIndex MIIndex = getInstructionIndex(PHICopy);
|
SlotIndex MIIndex = getInstructionIndex(PHICopy);
|
||||||
|
DEBUG(errs() << "Moving: " << MIIndex << ' ' << *PHICopy);
|
||||||
SlotIndex DefIndex = MIIndex.getDefIndex();
|
SlotIndex DefIndex = MIIndex.getDefIndex();
|
||||||
LiveRange *SLR = SrcInt.getLiveRangeContaining(DefIndex);
|
LiveRange *SLR = SrcInt.getLiveRangeContaining(DefIndex);
|
||||||
SlotIndex StartIndex = SLR->start;
|
SlotIndex StartIndex = SLR->start;
|
||||||
@ -724,8 +726,7 @@ void LiveIntervals::performEarlyCoalescing() {
|
|||||||
SrcInt.removeValNo(SLR->valno);
|
SrcInt.removeValNo(SLR->valno);
|
||||||
DEBUG(errs() << " added range [" << StartIndex << ','
|
DEBUG(errs() << " added range [" << StartIndex << ','
|
||||||
<< EndIndex << "] to reg" << DstInt.reg << '\n');
|
<< EndIndex << "] to reg" << DstInt.reg << '\n');
|
||||||
if (DstInt.liveAt(StartIndex))
|
assert (!DstInt.liveAt(StartIndex) && "Cannot coalesce when dst live!");
|
||||||
DstInt.removeRange(StartIndex, EndIndex);
|
|
||||||
VNInfo *NewVNI = DstInt.getNextValue(DefIndex, PHICopy, true,
|
VNInfo *NewVNI = DstInt.getNextValue(DefIndex, PHICopy, true,
|
||||||
VNInfoAllocator);
|
VNInfoAllocator);
|
||||||
NewVNI->setHasPHIKill(true);
|
NewVNI->setHasPHIKill(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user