@@ -1691,16 +1691,35 @@ static bool MIIsInTerminatorSequence(const MachineInstr &MI) {
1691
1691
// / terminator, but additionally the copies that move the vregs into the
1692
1692
// / physical registers.
1693
1693
static MachineBasicBlock::iterator
1694
- FindSplitPointForStackProtector (MachineBasicBlock *BB) {
1694
+ FindSplitPointForStackProtector (MachineBasicBlock *BB,
1695
+ const TargetInstrInfo &TII) {
1695
1696
MachineBasicBlock::iterator SplitPoint = BB->getFirstTerminator ();
1696
- //
1697
1697
if (SplitPoint == BB->begin ())
1698
1698
return SplitPoint;
1699
1699
1700
1700
MachineBasicBlock::iterator Start = BB->begin ();
1701
1701
MachineBasicBlock::iterator Previous = SplitPoint;
1702
1702
--Previous;
1703
1703
1704
+ if (TII.isTailCall (*SplitPoint) &&
1705
+ Previous->getOpcode () == TII.getCallFrameDestroyOpcode ()) {
1706
+ // Call frames cannot be nested, so if this frame is describing the tail
1707
+ // call itself then we must insert before the sequence even starts. On the
1708
+ // other hand, it could be an unrelated call in which case this tail call
1709
+ // has to register moves of its own and should be the split point.
1710
+ bool DifferentCall = false ;
1711
+ MachineBasicBlock::iterator I = Previous;
1712
+ do {
1713
+ --I;
1714
+ if (I->isCall ()) {
1715
+ DifferentCall = true ;
1716
+ break ;
1717
+ }
1718
+ } while (I->getOpcode () != TII.getCallFrameSetupOpcode ());
1719
+
1720
+ return DifferentCall ? SplitPoint : I;
1721
+ }
1722
+
1704
1723
while (MIIsInTerminatorSequence (*Previous)) {
1705
1724
SplitPoint = Previous;
1706
1725
if (Previous == Start)
@@ -1740,7 +1759,7 @@ SelectionDAGISel::FinishBasicBlock() {
1740
1759
// Add load and check to the basicblock.
1741
1760
FuncInfo->MBB = ParentMBB;
1742
1761
FuncInfo->InsertPt =
1743
- FindSplitPointForStackProtector (ParentMBB);
1762
+ FindSplitPointForStackProtector (ParentMBB, *TII );
1744
1763
SDB->visitSPDescriptorParent (SDB->SPDescriptor , ParentMBB);
1745
1764
CurDAG->setRoot (SDB->getRoot ());
1746
1765
SDB->clear ();
@@ -1759,7 +1778,7 @@ SelectionDAGISel::FinishBasicBlock() {
1759
1778
// register allocation issues caused by us splitting the parent mbb. The
1760
1779
// register allocator will clean up said virtual copies later on.
1761
1780
MachineBasicBlock::iterator SplitPoint =
1762
- FindSplitPointForStackProtector (ParentMBB);
1781
+ FindSplitPointForStackProtector (ParentMBB, *TII );
1763
1782
1764
1783
// Splice the terminator of ParentMBB into SuccessMBB.
1765
1784
SuccessMBB->splice (SuccessMBB->end (), ParentMBB,
0 commit comments