Avoid comparing invalid slot indexes, and assert that it doesn't happen.

The SlotIndex created by the default construction does not represent a position
in the function, and it doesn't make sense to compare it to other indexes.

llvm-svn: 126924
This commit is contained in:
Jakob Stoklund Olesen 2011-03-03 05:18:19 +00:00
parent db13110e4d
commit 67a84d08ce
3 changed files with 5 additions and 6 deletions

View File

@ -135,6 +135,7 @@ namespace llvm {
} }
IndexListEntry& entry() const { IndexListEntry& entry() const {
assert(isValid() && "Attempt to compare reserved index.");
return *lie.getPointer(); return *lie.getPointer();
} }
@ -530,7 +531,7 @@ namespace llvm {
/// Returns the instruction for the given index, or null if the given /// Returns the instruction for the given index, or null if the given
/// index has no instruction associated with it. /// index has no instruction associated with it.
MachineInstr* getInstructionFromIndex(SlotIndex index) const { MachineInstr* getInstructionFromIndex(SlotIndex index) const {
return index.entry().getInstr(); return index.isValid() ? index.entry().getInstr() : 0;
} }
/// Returns the next non-null index. /// Returns the next non-null index.

View File

@ -458,7 +458,7 @@ unsigned RALinScan::attemptTrivialCoalescing(LiveInterval &cur, unsigned Reg) {
const LiveRange &range = cur.ranges.front(); const LiveRange &range = cur.ranges.front();
VNInfo *vni = range.valno; VNInfo *vni = range.valno;
if (vni->isUnused()) if (vni->isUnused() || !vni->def.isValid())
return Reg; return Reg;
unsigned CandReg; unsigned CandReg;
@ -993,7 +993,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur) {
// one, e.g. X86::mov32to32_. These move instructions are not coalescable. // one, e.g. X86::mov32to32_. These move instructions are not coalescable.
if (!vrm_->getRegAllocPref(cur->reg) && cur->hasAtLeastOneValue()) { if (!vrm_->getRegAllocPref(cur->reg) && cur->hasAtLeastOneValue()) {
VNInfo *vni = cur->begin()->valno; VNInfo *vni = cur->begin()->valno;
if (!vni->isUnused()) { if (!vni->isUnused() && vni->def.isValid()) {
MachineInstr *CopyMI = li_->getInstructionFromIndex(vni->def); MachineInstr *CopyMI = li_->getInstructionFromIndex(vni->def);
if (CopyMI && CopyMI->isCopy()) { if (CopyMI && CopyMI->isCopy()) {
unsigned DstSubReg = CopyMI->getOperand(0).getSubReg(); unsigned DstSubReg = CopyMI->getOperand(0).getSubReg();

View File

@ -1568,9 +1568,7 @@ SimpleRegisterCoalescing::lastRegisterUse(SlotIndex Start,
if (UseMI->isIdentityCopy()) if (UseMI->isIdentityCopy())
continue; continue;
SlotIndex Idx = li_->getInstructionIndex(UseMI); SlotIndex Idx = li_->getInstructionIndex(UseMI);
// FIXME: Should this be Idx != UseIdx? SlotIndex() will return something if (Idx >= Start && Idx < End && (!UseIdx.isValid() || Idx >= UseIdx)) {
// that compares higher than any other interval.
if (Idx >= Start && Idx < End && Idx >= UseIdx) {
LastUse = &Use; LastUse = &Use;
UseIdx = Idx.getUseIndex(); UseIdx = Idx.getUseIndex();
} }