[llvm-commits] [llvm] r66617 - in /llvm/branches/Apple/Dib: include/llvm/CodeGen/LiveInterval.h lib/CodeGen/LiveInterval.cpp lib/CodeGen/SimpleRegisterCoalescing.cpp test/CodeGen/X86/2009-03-10-CoalescerBug.ll

Bill Wendling isanbard at gmail.com
Tue Mar 10 17:17:29 PDT 2009


Author: void
Date: Tue Mar 10 19:17:29 2009
New Revision: 66617

URL: http://llvm.org/viewvc/llvm-project?rev=66617&view=rev
Log:
--- Merging (from foreign repository) r66610 into '.':
A    test/CodeGen/X86/2009-03-10-CoalescerBug.ll
U    include/llvm/CodeGen/LiveInterval.h
U    lib/CodeGen/LiveInterval.cpp
U    lib/CodeGen/SimpleRegisterCoalescing.cpp

Two coalescer fixes in one:

1. Use the same value# to represent unknown values being merged into
   sub-registers.
2. When coalescer commute an instruction and the destination is a physical
   register, update its sub-registers by merging in the extended ranges.

Added:
    llvm/branches/Apple/Dib/test/CodeGen/X86/2009-03-10-CoalescerBug.ll
Modified:
    llvm/branches/Apple/Dib/include/llvm/CodeGen/LiveInterval.h
    llvm/branches/Apple/Dib/lib/CodeGen/LiveInterval.cpp
    llvm/branches/Apple/Dib/lib/CodeGen/SimpleRegisterCoalescing.cpp

Modified: llvm/branches/Apple/Dib/include/llvm/CodeGen/LiveInterval.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/CodeGen/LiveInterval.h?rev=66617&r1=66616&r2=66617&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/include/llvm/CodeGen/LiveInterval.h (original)
+++ llvm/branches/Apple/Dib/include/llvm/CodeGen/LiveInterval.h Tue Mar 10 19:17:29 2009
@@ -212,6 +212,10 @@
       return VNI;
     }
 
+    /// getUnknownValNo - Find a value# for unknown values, if there isn't one
+    /// create a new one.
+    VNInfo *getUnknownValNo(BumpPtrAllocator &VNInfoAllocator);
+
     /// addKill - Add a kill instruction index to the specified value
     /// number.
     static void addKill(VNInfo *VNI, unsigned KillIdx) {
@@ -296,6 +300,11 @@
     void MergeInClobberRanges(const LiveInterval &Clobbers,
                               BumpPtrAllocator &VNInfoAllocator);
 
+    /// MergeInClobberRange - Same as MergeInClobberRanges except it merge in a
+    /// single LiveRange only.
+    void MergeInClobberRange(unsigned Start, unsigned End,
+                             BumpPtrAllocator &VNInfoAllocator);
+
     /// MergeValueInAsValue - Merge all of the live ranges of a specific val#
     /// in RHS into this live interval as the specified value number.
     /// The LiveRanges in RHS are allowed to overlap with LiveRanges in the

Modified: llvm/branches/Apple/Dib/lib/CodeGen/LiveInterval.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/LiveInterval.cpp?rev=66617&r1=66616&r2=66617&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/LiveInterval.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/LiveInterval.cpp Tue Mar 10 19:17:29 2009
@@ -551,6 +551,20 @@
   }
 }
 
+VNInfo *LiveInterval::getUnknownValNo(BumpPtrAllocator &VNInfoAllocator) {
+  unsigned i = getNumValNums();
+  if (i) {
+    do {
+      --i;
+      VNInfo *VNI = getValNumInfo(i);
+      if (VNI->def == ~0U && !VNI->copy &&
+          !VNI->hasPHIKill && !VNI->redefByEC && VNI->kills.empty())
+        return VNI;
+    } while (i != 0);
+  }
+  return getNextValue(~0U, 0, VNInfoAllocator);
+}
+
 
 /// MergeInClobberRanges - For any live ranges that are not defined in the
 /// current interval, but are defined in the Clobbers interval, mark them
@@ -561,8 +575,7 @@
   
   // Find a value # to use for the clobber ranges.  If there is already a value#
   // for unknown values, use it.
-  // FIXME: Use a single sentinal number for these!
-  VNInfo *ClobberValNo = getNextValue(~0U, 0, VNInfoAllocator);
+  VNInfo *ClobberValNo = getUnknownValNo(VNInfoAllocator);
   
   iterator IP = begin();
   for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
@@ -587,6 +600,32 @@
   }
 }
 
+void LiveInterval::MergeInClobberRange(unsigned Start, unsigned End,
+                                       BumpPtrAllocator &VNInfoAllocator) {
+  // Find a value # to use for the clobber ranges.  If there is already a value#
+  // for unknown values, use it.
+  VNInfo *ClobberValNo = getUnknownValNo(VNInfoAllocator);
+  
+  iterator IP = begin();
+  IP = std::upper_bound(IP, end(), Start);
+    
+  // If the start of this range overlaps with an existing liverange, trim it.
+  if (IP != begin() && IP[-1].end > Start) {
+    Start = IP[-1].end;
+    // Trimmed away the whole range?
+    if (Start >= End) return;
+  }
+  // If the end of this range overlaps with an existing liverange, trim it.
+  if (IP != end() && End > IP->start) {
+    End = IP->start;
+    // If this trimmed away the whole range, ignore it.
+    if (Start == End) return;
+  }
+    
+  // Insert the clobber interval.
+  addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
+}
+
 /// MergeValueNumberInto - This method is called when two value nubmers
 /// are found to be equivalent.  This eliminates V1, replacing all
 /// LiveRanges with the V1 value number with the V2 value number.  This can

Modified: llvm/branches/Apple/Dib/lib/CodeGen/SimpleRegisterCoalescing.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/SimpleRegisterCoalescing.cpp?rev=66617&r1=66616&r2=66617&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/SimpleRegisterCoalescing.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/SimpleRegisterCoalescing.cpp Tue Mar 10 19:17:29 2009
@@ -193,13 +193,12 @@
   IntB.addRange(LiveRange(FillerStart, FillerEnd, BValNo));
 
   // If the IntB live range is assigned to a physical register, and if that
-  // physreg has aliases, 
+  // physreg has sub-registers, update their live intervals as well. 
   if (TargetRegisterInfo::isPhysicalRegister(IntB.reg)) {
-    // Update the liveintervals of sub-registers.
-    for (const unsigned *AS = tri_->getSubRegisters(IntB.reg); *AS; ++AS) {
-      LiveInterval &AliasLI = li_->getInterval(*AS);
-      AliasLI.addRange(LiveRange(FillerStart, FillerEnd,
-              AliasLI.getNextValue(FillerStart, 0, li_->getVNInfoAllocator())));
+    for (const unsigned *SR = tri_->getSubRegisters(IntB.reg); *SR; ++SR) {
+      LiveInterval &SRLI = li_->getInterval(*SR);
+      SRLI.addRange(LiveRange(FillerStart, FillerEnd,
+                 SRLI.getNextValue(FillerStart, 0, li_->getVNInfoAllocator())));
     }
   }
 
@@ -367,6 +366,9 @@
     BExtend[ALR->end] = BLR->end;
 
   // Update uses of IntA of the specific Val# with IntB.
+  bool BHasSubRegs = false;
+  if (TargetRegisterInfo::isPhysicalRegister(IntB.reg))
+    BHasSubRegs = *tri_->getSubRegisters(IntB.reg);
   for (MachineRegisterInfo::use_iterator UI = mri_->use_begin(IntA.reg),
          UE = mri_->use_end(); UI != UE;) {
     MachineOperand &UseMO = UI.getOperand();
@@ -398,6 +400,9 @@
       const LiveRange *DLR = IntB.getLiveRangeContaining(DefIdx);
       BHasPHIKill |= DLR->valno->hasPHIKill;
       assert(DLR->valno->def == DefIdx);
+      if (BHasSubRegs)
+        // Don't know how to update sub-register live intervals.
+        return false;
       BDeadValNos.push_back(DLR->valno);
       BExtend[DLR->start] = DLR->end;
       JoinedCopies.insert(UseMI);
@@ -435,6 +440,15 @@
     if (EI != BExtend.end())
       End = EI->second;
     IntB.addRange(LiveRange(AI->start, End, ValNo));
+
+    // If the IntB live range is assigned to a physical register, and if that
+    // physreg has sub-registers, update their live intervals as well. 
+    if (TargetRegisterInfo::isPhysicalRegister(IntB.reg)) {
+      for (const unsigned *SR = tri_->getSubRegisters(IntB.reg); *SR; ++SR) {
+        LiveInterval &SRLI = li_->getInterval(*SR);
+        SRLI.MergeInClobberRange(AI->start, End, li_->getVNInfoAllocator());
+      }
+    }
   }
   IntB.addKills(ValNo, BKills);
   ValNo->hasPHIKill = BHasPHIKill;

Added: llvm/branches/Apple/Dib/test/CodeGen/X86/2009-03-10-CoalescerBug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/X86/2009-03-10-CoalescerBug.ll?rev=66617&view=auto

==============================================================================
--- llvm/branches/Apple/Dib/test/CodeGen/X86/2009-03-10-CoalescerBug.ll (added)
+++ llvm/branches/Apple/Dib/test/CodeGen/X86/2009-03-10-CoalescerBug.ll Tue Mar 10 19:17:29 2009
@@ -0,0 +1,28 @@
+; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin
+; rdar://r6661945
+
+	%struct.WINDOW = type { i16, i16, i16, i16, i16, i16, i16, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, %struct.ldat*, i16, i16, i32, i32, %struct.WINDOW*, %struct.pdat, i16, %struct.cchar_t }
+	%struct.cchar_t = type { i32, [5 x i32] }
+	%struct.ldat = type { %struct.cchar_t*, i16, i16, i16 }
+	%struct.pdat = type { i16, i16, i16, i16, i16, i16 }
+
+define i32 @pnoutrefresh(%struct.WINDOW* %win, i32 %pminrow, i32 %pmincol, i32 %sminrow, i32 %smincol, i32 %smaxrow, i32 %smaxcol) nounwind optsize ssp {
+entry:
+	%0 = load i16* null, align 4		; <i16> [#uses=2]
+	%1 = icmp sgt i16 0, %0		; <i1> [#uses=1]
+	br i1 %1, label %bb12, label %bb13
+
+bb12:		; preds = %entry
+	%2 = sext i16 %0 to i32		; <i32> [#uses=1]
+	%3 = sub i32 %2, 0		; <i32> [#uses=1]
+	%4 = add i32 %3, %smaxrow		; <i32> [#uses=2]
+	%5 = trunc i32 %4 to i16		; <i16> [#uses=1]
+	%6 = add i16 0, %5		; <i16> [#uses=1]
+	br label %bb13
+
+bb13:		; preds = %bb12, %entry
+	%pmaxrow.0 = phi i16 [ %6, %bb12 ], [ 0, %entry ]		; <i16> [#uses=0]
+	%smaxrow_addr.0 = phi i32 [ %4, %bb12 ], [ %smaxrow, %entry ]		; <i32> [#uses=1]
+	%7 = trunc i32 %smaxrow_addr.0 to i16		; <i16> [#uses=0]
+	ret i32 0
+}





More information about the llvm-commits mailing list