Index: lib/CodeGen/LiveDebugValues.cpp =================================================================== --- lib/CodeGen/LiveDebugValues.cpp +++ lib/CodeGen/LiveDebugValues.cpp @@ -672,9 +672,23 @@ /*transferSpills=*/true); // Add any DBG_VALUE instructions necessitated by spills. - for (auto &SP : Spills) - MBB->insertAfter(MachineBasicBlock::iterator(*SP.SpillInst), - SP.DebugInst); + for (auto &SP : Spills){ + MachineInstr *InsertPoint = SP.SpillInst; + MachineInstr *DebugInst = SP.DebugInst; + MBB->insertAfter(MachineBasicBlock::iterator(*InsertPoint), + DebugInst); + // If the spill is part of an instruction bundle, we need to make sure + // that the newly inserted DBG_VALUE instruction also has the bundle + // flags set. Otherwise we might end up with incorrect sequences like: + // + // MI1 [BundledSucc=true, BundledPred=false] + // DBG_VALUE MI [BundledSucc=false, BundledPred=false] + // MI2 [BundledSucc=false, BundledPred=true] + if (InsertPoint->isBundledWithSucc()){ + DebugInst->setFlag(MachineInstr::BundledSucc); + DebugInst->setFlag(MachineInstr::BundledPred); + } + } Spills.clear(); DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,