@@ -921,30 +921,32 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,
921921 continue ;
922922 }
923923
924- // If one of the blocks is the entire common tail (and not the entry
925- // block, which we can't jump to), we can treat all blocks with this same
926- // tail at once. Use PredBB if that is one of the possibilities, as that
927- // will not introduce any extra branches.
924+ // If one of the blocks is the entire common tail (and is not the entry
925+ // block/an EH pad , which we can't jump to), we can treat all blocks with
926+ // this same tail at once. Use PredBB if that is one of the possibilities,
927+ // as that will not introduce any extra branches.
928928 MachineBasicBlock *EntryBB =
929929 &MergePotentials.front ().getBlock ()->getParent ()->front ();
930930 unsigned commonTailIndex = SameTails.size ();
931931 // If there are two blocks, check to see if one can be made to fall through
932932 // into the other.
933933 if (SameTails.size () == 2 &&
934934 SameTails[0 ].getBlock ()->isLayoutSuccessor (SameTails[1 ].getBlock ()) &&
935- SameTails[1 ].tailIsWholeBlock ())
935+ SameTails[1 ].tailIsWholeBlock () && !SameTails[ 1 ]. getBlock ()-> isEHPad () )
936936 commonTailIndex = 1 ;
937937 else if (SameTails.size () == 2 &&
938938 SameTails[1 ].getBlock ()->isLayoutSuccessor (
939- SameTails[0 ].getBlock ()) &&
940- SameTails[0 ].tailIsWholeBlock ())
939+ SameTails[0 ].getBlock ()) &&
940+ SameTails[0 ].tailIsWholeBlock () &&
941+ !SameTails[0 ].getBlock ()->isEHPad ())
941942 commonTailIndex = 0 ;
942943 else {
943944 // Otherwise just pick one, favoring the fall-through predecessor if
944945 // there is one.
945946 for (unsigned i = 0 , e = SameTails.size (); i != e; ++i) {
946947 MachineBasicBlock *MBB = SameTails[i].getBlock ();
947- if (MBB == EntryBB && SameTails[i].tailIsWholeBlock ())
948+ if ((MBB == EntryBB || MBB->isEHPad ()) &&
949+ SameTails[i].tailIsWholeBlock ())
948950 continue ;
949951 if (MBB == PredBB) {
950952 commonTailIndex = i;
0 commit comments