diff options
author | Dan Gohman <gohman@apple.com> | 2009-08-18 15:18:18 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-08-18 15:18:18 +0000 |
commit | da65822cfc938594f8fb7840947c1eb77e057a48 (patch) | |
tree | 825ce41886300ad659c1105bd376e0663c276488 /lib/CodeGen/BranchFolding.cpp | |
parent | 6874a2ae033b7b5e1d0c10714e01d9c87480956a (diff) |
Make tail merging handle blocks with repeated predecessors correctly, and
remove RemoveDuplicateSuccessor, as it is no longer necessary, and because
it breaks assumptions made in
MachineBasicBlock::isOnlyReachableByFallthrough.
Convert test/CodeGen/X86/omit-label.ll to FileCheck and add a testcase
for PR4732.
test/CodeGen/Thumb2/thumb2-ifcvt2.ll sees a diff with this commit due to
it being bugpoint-reduced to the point where it doesn't matter what the
condition for the branch is.
Add some more interesting code to
test/CodeGen/X86/2009-08-06-branchfolder-crash.ll, which is the testcase
that originally motivated the RemoveDuplicateSuccessor code, to help
verify that the original problem isn't being re-broken.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79338 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index 1ab3df2857..1ce83f81af 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -700,6 +700,7 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) { for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) { if (I->pred_size() >= 2 && I->pred_size() < TailMergeThreshold) { + SmallPtrSet<MachineBasicBlock *, 8> UniquePreds; MachineBasicBlock *IBB = I; MachineBasicBlock *PredBB = prior(I); MergePotentials.clear(); @@ -710,6 +711,9 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) { // Skip blocks that loop to themselves, can't tail merge these. if (PBB==IBB) continue; + // Visit each predecessor only once. + if (!UniquePreds.insert(PBB)) + continue; MachineBasicBlock *TBB = 0, *FBB = 0; SmallVector<MachineOperand, 4> Cond; if (!TII->AnalyzeBranch(*PBB, TBB, FBB, Cond, true)) { @@ -850,27 +854,6 @@ bool BranchFolder::CanFallThrough(MachineBasicBlock *CurBB) { return CanFallThrough(CurBB, CurUnAnalyzable, TBB, FBB, Cond); } -/// RemoveDuplicateSuccessor - make sure block Pred has at most one -/// successor edge leading to Succ. This is only called in one place, -/// but Chris prefers that it be a separate function. -static void RemoveDuplicateSuccessor(MachineBasicBlock *Pred, - MachineBasicBlock *Succ) { - MachineBasicBlock::succ_iterator SI = Pred->succ_begin(); - bool found = false; - while (SI != Pred->succ_end()) { - if (*SI == Succ) { - if (!found) { - found = true; - ++SI; - } else { - SI = Pred->removeSuccessor(SI); - } - } else { - ++SI; - } - } -} - /// IsBetterFallthrough - Return true if it would be clearly better to /// fall-through to MBB1 than to fall through into MBB2. This has to return /// a strict ordering, returning true for both (MBB1,MBB2) and (MBB2,MBB1) will @@ -914,10 +897,6 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { while (!MBB->pred_empty()) { MachineBasicBlock *Pred = *(MBB->pred_end()-1); Pred->ReplaceUsesOfBlockWith(MBB, FallThrough); - // If this resulted in a predecessor with true and false edges - // both going to the fallthrough block, clean up; - // BranchFolding doesn't like this. - RemoveDuplicateSuccessor(Pred, FallThrough); } // If MBB was the target of a jump table, update jump tables to go to the // fallthrough instead. |