aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-05-29 23:47:50 +0000
committerDale Johannesen <dalej@apple.com>2007-05-29 23:47:50 +0000
commit95ef406e0f2da0197f8b46849319c07e9bea1e55 (patch)
tree6c66b4250c7dc8a556dfd45916ccf643e2f65b51 /lib/CodeGen/BranchFolding.cpp
parent58fbb9f5babf00bd0a0e5b0f39bb718275972ec6 (diff)
Make stable_sort in tail merging actually be stable (it never was, but didn't
matter until my last change). Reenable tail merging by default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37354 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r--lib/CodeGen/BranchFolding.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp
index 1fe2962a36..c34aeebe0e 100644
--- a/lib/CodeGen/BranchFolding.cpp
+++ b/lib/CodeGen/BranchFolding.cpp
@@ -420,6 +420,21 @@ static void FixTail(MachineBasicBlock* CurMBB, MachineBasicBlock *SuccBB,
TII->InsertBranch(*CurMBB, SuccBB, NULL, std::vector<MachineOperand>());
}
+static bool MergeCompare(std::pair<unsigned,MachineBasicBlock*> p,
+ std::pair<unsigned,MachineBasicBlock*> q) {
+
+ if (p.first < q.first)
+ return true;
+ else if (p.first > q.first)
+ return false;
+ else if (p.second->getNumber() < q.second->getNumber())
+ return true;
+ else if (p.second->getNumber() > q.second->getNumber())
+ return false;
+ else
+ assert(0 && "Predecessor appears twice");
+}
+
// See if any of the blocks in MergePotentials (which all have a common single
// successor, or all have no successor) can be tail-merged. If there is a
// successor, any blocks in MergePotentials that are not tail-merged and
@@ -435,7 +450,7 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB,
// Sort by hash value so that blocks with identical end sequences sort
// together.
- std::stable_sort(MergePotentials.begin(), MergePotentials.end());
+ std::stable_sort(MergePotentials.begin(), MergePotentials.end(), MergeCompare);
// Walk through equivalence sets looking for actual exact matches.
while (MergePotentials.size() > 1) {