[ShrinkWrap] Take into account landing pad
When scanning the function for CSRs uses and defs, also check if
the basic block are landing pads.
Consider that landing pads needs the CSRs to be properly set.
That way we force the prologue/epilogue to always be pushed out
of the problematic "throw" region. The "throw" region is
problematic because the jumps are not properly modeled.
Fixes PR36513
llvm-svn: 327942
diff --git a/llvm/lib/CodeGen/ShrinkWrap.cpp b/llvm/lib/CodeGen/ShrinkWrap.cpp
index 85117775..2d854d6 100644
--- a/llvm/lib/CodeGen/ShrinkWrap.cpp
+++ b/llvm/lib/CodeGen/ShrinkWrap.cpp
@@ -447,6 +447,22 @@
return false;
}
+ if (MBB.isEHPad()) {
+ // Push the prologue and epilogue outside of
+ // the region that may throw by making sure
+ // that all the landing pads are at least at the
+ // boundary of the save and restore points.
+ // The problem with exceptions is that the throw
+ // is not properly modeled and in particular, a
+ // basic block can jump out from the middle.
+ updateSaveRestorePoints(MBB, RS.get());
+ if (!ArePointsInteresting()) {
+ DEBUG(dbgs() << "EHPad prevents shrink-wrapping\n");
+ return false;
+ }
+ continue;
+ }
+
for (const MachineInstr &MI : MBB) {
if (!useOrDefCSROrFI(MI, RS.get()))
continue;