Index: lib/CodeGen/ShrinkWrap.cpp =================================================================== --- lib/CodeGen/ShrinkWrap.cpp +++ lib/CodeGen/ShrinkWrap.cpp @@ -307,6 +307,12 @@ return; } + if (Save == Restore && Save != &MBB) + if (auto L = MLI->getLoopFor(Save)) + if (L->getHeader() == Save) + // Bail out. + Save = nullptr; + // Make sure Save and Restore are suitable for shrink-wrapping: // 1. all path from Save needs to lead to Restore before exiting. // 2. all path to Restore needs to go through Save from Entry.