Index: lib/Target/ARM/ARMLoadStoreOptimizer.cpp =================================================================== --- lib/Target/ARM/ARMLoadStoreOptimizer.cpp +++ lib/Target/ARM/ARMLoadStoreOptimizer.cpp @@ -553,6 +553,17 @@ if (!LiveRegsValid) { LiveRegs.init(TRI); LiveRegs.addLiveOuts(&MBB, true); + auto MI = MBB.getLastNonDebugInstr(); + // For exiting BB, we need to initially mark callee saved regs as live-out + // because passes like shrink-wrap may move the reg restoring around. + if (MI != MBB.end() && + (MI->getOpcode() == ARM::BX_RET || MI->getOpcode() == ARM::tBX_RET || + MI->getOpcode() == ARM::MOVPCLR)) { + const MCPhysReg *CSRegs = TRI->getCalleeSavedRegs(MBB.getParent()); + while (*CSRegs) + LiveRegs.addReg(*CSRegs++); + } + LiveRegPos = MBB.end(); LiveRegsValid = true; }