From 26667abbd3aa1fef521976bfeb16f5c933f973a1 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 1 Dec 2009 03:03:00 +0000 Subject: [PATCH] Use CFG connectedness as a secondary sort key when deciding the order of copy coalescing. This means that well connected blocks are copy coalesced before the less connected blocks. Connected blocks are more difficult to coalesce because intervals are more complicated, so handling them first gives a greater chance of success. llvm-svn: 90194 --- llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp | 16 +++++++++++++--- .../X86/2009-09-19-SchedCustomLoweringBug.ll | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp b/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp index 7847f8ec20e5..58763718f9b5 100644 --- a/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp +++ b/llvm/lib/CodeGen/SimpleRegisterCoalescing.cpp @@ -2371,9 +2371,19 @@ namespace { struct DepthMBBCompare { typedef std::pair DepthMBBPair; bool operator()(const DepthMBBPair &LHS, const DepthMBBPair &RHS) const { - if (LHS.first > RHS.first) return true; // Deeper loops first - return LHS.first == RHS.first && - LHS.second->getNumber() < RHS.second->getNumber(); + // Deeper loops first + if (LHS.first != RHS.first) + return LHS.first > RHS.first; + + // Prefer blocks that are more connected in the CFG. This takes care of + // the most difficult copies first while intervals are short. + unsigned cl = LHS.second->pred_size() + LHS.second->succ_size(); + unsigned cr = RHS.second->pred_size() + RHS.second->succ_size(); + if (cl != cr) + return cl > cr; + + // As a last resort, sort by block number. + return LHS.second->getNumber() < RHS.second->getNumber(); } }; } diff --git a/llvm/test/CodeGen/X86/2009-09-19-SchedCustomLoweringBug.ll b/llvm/test/CodeGen/X86/2009-09-19-SchedCustomLoweringBug.ll index f3cf1d5e7019..d372da336769 100644 --- a/llvm/test/CodeGen/X86/2009-09-19-SchedCustomLoweringBug.ll +++ b/llvm/test/CodeGen/X86/2009-09-19-SchedCustomLoweringBug.ll @@ -10,6 +10,7 @@ entry: bb: ; preds = %bb1, %entry ; CHECK: addl $1 +; CHECK-NEXT: movl %e ; CHECK-NEXT: adcl $0 %i.0 = phi i64 [ 0, %entry ], [ %0, %bb1 ] ; [#uses=1] %0 = add nsw i64 %i.0, 1 ; [#uses=2]