@@ -963,30 +963,32 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,
963963 continue ;
964964 }
965965
966- // If one of the blocks is the entire common tail (and not the entry
967- // block, which we can't jump to), we can treat all blocks with this same
968- // tail at once. Use PredBB if that is one of the possibilities, as that
969- // will not introduce any extra branches.
966+ // If one of the blocks is the entire common tail (and is not the entry
967+ // block/an EH pad , which we can't jump to), we can treat all blocks with
968+ // this same tail at once. Use PredBB if that is one of the possibilities,
969+ // as that will not introduce any extra branches.
970970 MachineBasicBlock *EntryBB =
971971 &MergePotentials.front ().getBlock ()->getParent ()->front ();
972972 unsigned commonTailIndex = SameTails.size ();
973973 // If there are two blocks, check to see if one can be made to fall through
974974 // into the other.
975975 if (SameTails.size () == 2 &&
976976 SameTails[0 ].getBlock ()->isLayoutSuccessor (SameTails[1 ].getBlock ()) &&
977- SameTails[1 ].tailIsWholeBlock ())
977+ SameTails[1 ].tailIsWholeBlock () && !SameTails[ 1 ]. getBlock ()-> isEHPad () )
978978 commonTailIndex = 1 ;
979979 else if (SameTails.size () == 2 &&
980980 SameTails[1 ].getBlock ()->isLayoutSuccessor (
981- SameTails[0 ].getBlock ()) &&
982- SameTails[0 ].tailIsWholeBlock ())
981+ SameTails[0 ].getBlock ()) &&
982+ SameTails[0 ].tailIsWholeBlock () &&
983+ !SameTails[0 ].getBlock ()->isEHPad ())
983984 commonTailIndex = 0 ;
984985 else {
985986 // Otherwise just pick one, favoring the fall-through predecessor if
986987 // there is one.
987988 for (unsigned i = 0 , e = SameTails.size (); i != e; ++i) {
988989 MachineBasicBlock *MBB = SameTails[i].getBlock ();
989- if (MBB == EntryBB && SameTails[i].tailIsWholeBlock ())
990+ if ((MBB == EntryBB || MBB->isEHPad ()) &&
991+ SameTails[i].tailIsWholeBlock ())
990992 continue ;
991993 if (MBB == PredBB) {
992994 commonTailIndex = i;
0 commit comments