[llvm-commits] [llvm] r159746 - /llvm/trunk/lib/CodeGen/LiveInterval.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Jul 5 09:49:43 PDT 2012


On Jul 5, 2012, at 8:36 AM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:

> 
> On Jul 5, 2012, at 5:40 AM, Chandler Carruth <chandlerc at gmail.com> wrote:
> 
>> Author: chandlerc
>> Date: Thu Jul  5 07:40:45 2012
>> New Revision: 159746
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=159746&view=rev
>> Log:
>> Optimize extendIntervalEndTo a tiny bit by saving one call through the
>> vector erase. No functionality changed.
> 
> This function is very hot when called from LiveInterval::extendInBlock(), and in that case it is known that the new live range doesn't overlap any existing live ranges.
> 
> You may be able to squeeze out a bit more performance by inlining a simpler extendIntervalEndTo() into extendInBlock(). The for-loop and std::max conditional are not needed in that case.

I wasn't able to measure a performance difference with this patch:

diff --git a/lib/CodeGen/LiveInterval.cpp b/lib/CodeGen/LiveInterval.cpp
index 3d34c08..fc09c02 100644
--- a/lib/CodeGen/LiveInterval.cpp
+++ b/lib/CodeGen/LiveInterval.cpp
@@ -305,8 +305,20 @@ VNInfo *LiveInterval::extendInBlock(SlotIndex StartIdx, SlotIndex Kill) {
   --I;
   if (I->end <= StartIdx)
     return 0;
-  if (I->end < Kill)
-    extendIntervalEndTo(I, Kill);
+  if (I->end >= Kill)
+    return I->valno;
+
+  // I needs to be extended up to Kill.
+  // Check if it would merge with the next segment.
+  iterator Next = llvm::next(I);
+  if (Next == end() || Next->start != Kill || Next->valno != I->valno) {
+    I->end = Kill;
+    return I->valno;
+  }
+
+  // Merge Next into I.
+  I->end = Next->end;
+  ranges.erase(Next);
   return I->valno;
 }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120705/bbd4f686/attachment.html>


More information about the llvm-commits mailing list