Possible bug in LiveIntervalAnalysis?

Hi,

In the LiveIntervalAnalysis::runOnMachineFunction, there is a code to
compute the MBB2IdxMap, by remembering for each MBB its start and end
instruction numbers:

  unsigned MIIndex = 0;
  for (MachineFunction::iterator MBB = mf_->begin(), E = mf_->end();
       MBB != E; ++MBB) {
    unsigned StartIdx = MIIndex;

    for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
         I != E; ++I) {
      bool inserted = mi2iMap_.insert(std::make_pair(I,
MIIndex)).second;
      assert(inserted && "multiple MachineInstr -> index mappings");
      i2miMap_.push_back(I);
      MIIndex += InstrSlots::NUM;
    }

    // Set the MBB2IdxMap entry for this MBB.
    MBB2IdxMap[MBB->getNumber()] = std::make_pair(StartIdx, MIIndex -
1);

For empty MBBs, the last line would create a pair, where the end
element is smaller than the start element, which is a bit
counter-intuitive. This may lead to some assertion failures in other
parts of the code generator, if they use MBB2IdxMap for checking is an
instruction belongs to a given MBB.

Question: Is this way of handling empty MBBs in the
LiveIntervalAnalysis a bug or a feature? Any special reason, why the
pair for an empty block does not look e.g. like (start, start)?

-Roman

That's a bug. I'll fix it.

Thanks.

Evan

Hi

I'm seeing something probably related to this. I'm getting an assert
from the lower_bound in LiveIntervals::findLiveinMBBs (from a checking
std:: VS2005 implementation). Idx2MBBMap has two elements in it, both
of which have a .first of 0. (I believe because of an empty MBB in the
function below, so StartIndex doesn't advance).

scott

Can you file a bug so I don't forget? I'm a little occupied right now. But I'll take care of this soon.

Evan

http://llvm.org/bugs/show_bug.cgi?id=2232