Index: lib/CodeGen/MachineBasicBlock.cpp =================================================================== --- lib/CodeGen/MachineBasicBlock.cpp +++ lib/CodeGen/MachineBasicBlock.cpp @@ -16,6 +16,7 @@ #include "llvm/CodeGen/LiveIntervals.h" #include "llvm/CodeGen/LiveVariables.h" #include "llvm/CodeGen/MachineDominators.h" +#include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineLoopInfo.h" @@ -1400,6 +1401,23 @@ // If we reached the end, it is safe to clobber Reg at the end of a block of // no successor has it live in. if (I == end()) { + if (isReturnBlock()) { + const MachineFunction &MF = *getParent(); + const MachineRegisterInfo &MRI = MF.getRegInfo(); + for (const MCPhysReg *CSR = MRI.getCalleeSavedRegs(); CSR && *CSR; ++CSR) { + if (*CSR == Reg) + return LQR_Live; + } + + const MachineFrameInfo &MFI = MF.getFrameInfo(); + if (MFI.isCalleeSavedInfoValid()) { + for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) { + if (Info.isRestored() && Info.getReg() == Reg) + return LQR_Live; + } + } + } + for (MachineBasicBlock *S : successors()) { for (MCSubRegIterator SubReg(Reg, TRI, /*IncludeSelf*/true); SubReg.isValid(); ++SubReg) {