Index: llvm/trunk/include/llvm/CodeGen/LivePhysRegs.h =================================================================== --- llvm/trunk/include/llvm/CodeGen/LivePhysRegs.h +++ llvm/trunk/include/llvm/CodeGen/LivePhysRegs.h @@ -122,9 +122,9 @@ void addLiveIns(const MachineBasicBlock *MBB, bool AddPristines = false); /// \brief Adds all live-out registers of basic block @p MBB; After prologue/ - /// epilogue insertion \p AddPristines should be set to true to insert the - /// pristine registers. - void addLiveOuts(const MachineBasicBlock *MBB, bool AddPristines = false); + /// epilogue insertion \p AddPristinesAndCSRs should be set to true. + void addLiveOuts(const MachineBasicBlock *MBB, + bool AddPristinesAndCSRs = false); typedef SparseSet::const_iterator const_iterator; const_iterator begin() const { return LiveRegs.begin(); } Index: llvm/trunk/lib/CodeGen/LivePhysRegs.cpp =================================================================== --- llvm/trunk/lib/CodeGen/LivePhysRegs.cpp +++ llvm/trunk/lib/CodeGen/LivePhysRegs.cpp @@ -147,11 +147,19 @@ } void LivePhysRegs::addLiveOuts(const MachineBasicBlock *MBB, - bool AddPristines) { - if (AddPristines) { + bool AddPristinesAndCSRs) { + if (AddPristinesAndCSRs) { const MachineFunction &MF = *MBB->getParent(); addPristines(*this, MF, *TRI); + if (!MBB->isReturnBlock()) { + // The return block has no successors whose live-ins we could merge + // below. So instead we add the callee saved registers manually. + for (const MCPhysReg *I = TRI->getCalleeSavedRegs(&MF); *I; ++I) + addReg(*I); + } } + + // To get the live-outs we simply merge the live-ins of all successors. for (const MachineBasicBlock *Succ : MBB->successors()) ::addLiveIns(*this, *Succ); }