Index: include/llvm/CodeGen/SlotIndexes.h =================================================================== --- include/llvm/CodeGen/SlotIndexes.h +++ include/llvm/CodeGen/SlotIndexes.h @@ -414,7 +414,12 @@ SlotIndex getInstructionIndex(const MachineInstr &MI) const { // Instructions inside a bundle have the same number as the bundle itself. const MachineInstr &BundleStart = *getBundleStart(MI.getIterator()); - Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleStart); + // Skip debug instructions. + const MachineInstr &BundleNonDebug = *skipDebugInstructionsForward( + BundleStart.getIterator(), MI.getIterator()); + assert(!BundleNonDebug.isDebugInstr() && + "There is no non-debug instruction in the bundle."); + Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleNonDebug); assert(itr != mi2iMap.end() && "Instruction not found in maps."); return itr->second; } Index: lib/CodeGen/LiveDebugVariables.cpp =================================================================== --- lib/CodeGen/LiveDebugVariables.cpp +++ lib/CodeGen/LiveDebugVariables.cpp @@ -583,10 +583,16 @@ continue; } // DBG_VALUE has no slot index, use the previous instruction instead. - SlotIndex Idx = - MBBI == MBB->begin() - ? LIS->getMBBStartIdx(MBB) - : LIS->getInstructionIndex(*std::prev(MBBI)).getRegSlot(); + SlotIndex Idx; + if (MBBI == MBB->begin()) { + Idx = LIS->getMBBStartIdx(MBB); + } else { + const MachineInstr &PrevMI = *std::prev(MBBI); + if (PrevMI.isDebugInstr()) + Idx = LIS->getMBBStartIdx(MBB); + else + Idx = LIS->getInstructionIndex(PrevMI).getRegSlot(); + } // Handle consecutive DBG_VALUE instructions with the same slot index. do { if (handleDebugValue(*MBBI, Idx)) {