diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-02-19 02:09:37 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-02-19 02:09:37 +0000 |
commit | 3266ff9a6f4bd5b5c69fbff6cc41fa7bbd513ce5 (patch) | |
tree | 3a35c5cf293167a2188aaaebe2104b9f27cda8d2 /llvm/lib/CodeGen/BranchFolding.cpp | |
parent | 3b56f506e728a96b8ed6bd2d05251b76f683c3a4 (diff) | |
download | bcm5719-llvm-3266ff9a6f4bd5b5c69fbff6cc41fa7bbd513ce5.tar.gz bcm5719-llvm-3266ff9a6f4bd5b5c69fbff6cc41fa7bbd513ce5.zip |
PR1909: Tail merging pass ran wild. It makes no sense to merge blocks in order to save a single instruction since a branch will be inserted for each BB.
llvm-svn: 47301
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | llvm/lib/CodeGen/BranchFolding.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index dc67593c339..2d7836f4f3b 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -451,7 +451,10 @@ static bool MergeCompare(const std::pair<unsigned,MachineBasicBlock*> &p, bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB, MachineBasicBlock* PredBB) { - unsigned minCommonTailLength = (SuccBB ? 1 : 2); + // It doesn't make sense to save a single instruction since tail merging + // will add a jump. + // FIXME: Ask the target to provide the threshold? + unsigned minCommonTailLength = (SuccBB ? 1 : 2) + 1; MadeChange = false; // Sort by hash value so that blocks with identical end sequences sort @@ -476,9 +479,9 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB, // Look through all the pairs of blocks that have the same hash as this // one, and find the pair that has the largest number of instructions in // common. - // Since instructions may get combined later (e.g. single stores into + // Since instructions may get combined later (e.g. single stores into // store multiple) this measure is not particularly accurate. - MachineBasicBlock::iterator BBI1, BBI2; + MachineBasicBlock::iterator BBI1, BBI2; unsigned FoundI = ~0U, FoundJ = ~0U; unsigned maxCommonTailLength = 0U; @@ -541,6 +544,12 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB, continue; } + MachineBasicBlock::iterator TrialBBI1, TrialBBI2; + unsigned CommonTailLen = ComputeCommonTailLength(CurMBB, MBB2, + TrialBBI1, TrialBBI2); + if (CommonTailLen < minCommonTailLength) + continue; + // Decide whether we want to split CurMBB or MBB2. if (ShouldSplitFirstBlock(CurMBB, BBI1, MBB2, BBI2, PredBB)) { CurMBB = SplitMBBAt(*CurMBB, BBI1); |