[llvm-commits] CVS: llvm/lib/CodeGen/BranchFolding.cpp

Dale Johannesen dalej at apple.com
Tue May 29 18:48:12 CDT 2007



Changes in directory llvm/lib/CodeGen:

BranchFolding.cpp updated: 1.58 -> 1.59
---
Log message:

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.


---
Diffs of the changes:  (+16 -1)

 BranchFolding.cpp |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletion(-)


Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.58 llvm/lib/CodeGen/BranchFolding.cpp:1.59
--- llvm/lib/CodeGen/BranchFolding.cpp:1.58	Thu May 24 13:31:55 2007
+++ llvm/lib/CodeGen/BranchFolding.cpp	Tue May 29 18:47:50 2007
@@ -420,6 +420,21 @@
   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 @@
   
   // 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) {






More information about the llvm-commits mailing list