Disable physical register coalescing when the number of live ranges for the
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Tue, 9 Mar 2010 00:59:48 +0000 (00:59 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Tue, 9 Mar 2010 00:59:48 +0000 (00:59 +0000)
physreg becomes ridiculously high.

std::upper_bound may be log(N), but for sufficiently large live intervals, it
becomes log(N)*cachemiss = a long long time.

This patch improves coalescer time by 4500x for a function with 20000
function calls. The generated code is different, but not significantly worse -
the allocator hints are almost as good as physreg coalescing anyway.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98023 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SimpleRegisterCoalescing.cpp

index ce72b2fc1488026e29322f37ca9f5f1fc45d8f4c..d25df1d2ad8c3f031c3b02a7330cf6d8a08d0057 100644 (file)
@@ -1671,8 +1671,20 @@ bool SimpleRegisterCoalescing::JoinCopy(CopyRec &TheCopy, bool &Again) {
         // density, do not join them, instead mark the physical register as its
         // allocation preference.
         LiveInterval &JoinVInt = SrcIsPhys ? DstInt : SrcInt;
+        LiveInterval &JoinPInt = SrcIsPhys ? SrcInt : DstInt;
         unsigned JoinVReg = SrcIsPhys ? DstReg : SrcReg;
         unsigned JoinPReg = SrcIsPhys ? SrcReg : DstReg;
+
+        // Don't join with physregs that have a ridiculous number of live
+        // ranges. The data structure performance is really bad when that
+        // happens.
+        if (JoinPInt.ranges.size() > 1000) {
+          mri_->setRegAllocationHint(JoinVInt.reg, 0, JoinPReg);
+          ++numAborts;
+          DEBUG(dbgs() << "\tPhysical register too complicated, abort!\n");
+          return false;
+        }
+
         const TargetRegisterClass *RC = mri_->getRegClass(JoinVReg);
         unsigned Threshold = allocatableRCRegs_[RC].count() * 2;
         unsigned Length = li_->getApproximateInstructionCount(JoinVInt);