diff options
author | Dale Johannesen <dalej@apple.com> | 2007-05-10 23:59:23 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2007-05-10 23:59:23 +0000 |
commit | 54f4a6780a33043031af97571dfffdac5a4aa35c (patch) | |
tree | e71af9378e7341cef7f54ec58d811450a0ba5ae2 /lib/CodeGen/BranchFolding.cpp | |
parent | 432a7faf033b2d23162efd892b723f9b8481941a (diff) |
Do not generate branches to entry block. This fixes several test suite
failures on PPC (can happen only when prologue code is null)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36979 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index baaa81d92a..5fe0486eb1 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -338,6 +338,14 @@ static bool ShouldSplitFirstBlock(MachineBasicBlock *MBB1, MachineBasicBlock::iterator MBB2I, const TargetInstrInfo *TII, MachineBasicBlock *PredBB) { + // If one block is the entry block, split the other one; we can't generate + // a branch to the entry block, as its label is not emitted. + MachineBasicBlock *Entry = MBB1->getParent()->begin(); + if (MBB1 == Entry) + return false; + if (MBB2 == Entry) + return true; + // If one block falls through into the common successor, choose that // one to split; it is one instruction less to do that. if (PredBB) { @@ -456,8 +464,14 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB, MachineBasicBlock *MBB2 = (MergePotentials.end()-2)->second; // If neither block is the entire common tail, split the tail of one block - // to make it redundant with the other tail. - if (CurMBB->begin() != BBI1 && MBB2->begin() != BBI2) { + // to make it redundant with the other tail. Also, we cannot jump to the + // entry block, so if one block is the entry block, split the other one. + MachineBasicBlock *Entry = CurMBB->getParent()->begin(); + if (CurMBB->begin() == BBI1 && CurMBB != Entry) + ; // CurMBB is common tail + else if (MBB2->begin() == BBI2 && MBB2 != Entry) + ; // MBB2 is common tail + else { if (0) { // Enable this to disable partial tail merges. MergePotentials.pop_back(); continue; @@ -475,13 +489,14 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB, } } - if (MBB2->begin() == BBI2) { + if (MBB2->begin() == BBI2 && MBB2 != Entry) { // Hack the end off CurMBB, making it jump to MBBI@ instead. ReplaceTailWithBranchTo(BBI1, MBB2); // This modifies CurMBB, so remove it from the worklist. MergePotentials.pop_back(); } else { - assert(CurMBB->begin() == BBI1 && "Didn't split block correctly?"); + assert(CurMBB->begin() == BBI1 && CurMBB != Entry && + "Didn't split block correctly?"); // Hack the end off MBB2, making it jump to CurMBB instead. ReplaceTailWithBranchTo(BBI2, CurMBB); // This modifies MBB2, so remove it from the worklist. |