Register allocator assert

Hello,
I'm getting an assertion in register allocator, specifically in
LiveIntervalAnalysis.h, method LiveIntervals::getInstructionIndex:

unsigned getInstructionIndex(MachineInstr* instr) const {
      Mi2IndexMap::const_iterator it = mi2iMap_.find(instr);
      assert(it != mi2iMap_.end() && "Invalid instruction!");
      return it->second;
    }

The crash happens when the function is called from LiveIntervalAnalysis.cpp,
360:

  for (unsigned i = 0, e = vi.Kills.size(); i != e; ++i) {
      MachineInstr *Kill = vi.Kills[i];
      LiveRange LR(getInstructionIndex(Kill->getParent()->begin()),
                   getUseIndex(getInstructionIndex(Kill))+1, ValNum);
      interval.addRange(LR);
      DEBUG(std::cerr << " +" << LR);

When I add

      assert(mi2iMap_.count(Kill));

in that block, it fires. I have modified the LiveVariables class so that in
the end of runOnFunction method, it prints all the instructions which are in
Kill sets, but are not in the original functions. (Presumably, those are
spill instructions). Here's what I get:

Extra instruction 0x8061318
Extra instruction 0x80613d8
Extra instruction 0x8061218
Extra instruction 0x8061418

Program received signal SIGABRT, Aborted.
.......
    at ../../lib/CodeGen/LiveIntervalAnalysis.cpp:354
354 assert(mi2iMap_.count(Kill));
(gdb) p Kill
$1 = (llvm::MachineInstr *) 0x8061318

So, mi2iMap_ seems to be indexes with an address of a spill instruction, which
is not present in that map. I see that the map is originally initialized with
instructions in function and then only modified at
LiveIntervalAnalysis.cpp:219, but that code is only executed when
MRegisterInfo::foldMemoryOperand returns something, and I did not define that
method for my backend.

Any ideas how I can debug this? I attach the dumps of machine code which cause
the problems, but I'm afraid that won't be enough to reproduce the problem.

Thanks in advance,
Volodya

log.llc (9.5 KB)

Hello Vladimir,

Can you checkout the latest RegAllocLinearScan and RegAllocIterativeScan
versions and retry? I've checked a fix for something I commited last
night which was giving me the same assertion failure.

Thank you,

Hi Alkis,