[llvm-commits] [llvm] r58309 - in /llvm/trunk: lib/CodeGen/PreAllocSplitting.cpp test/CodeGen/X86/pre-split8.ll test/CodeGen/X86/pre-split9.ll

Evan Cheng evan.cheng at apple.com
Mon Oct 27 17:47:50 PDT 2008


Author: evancheng
Date: Mon Oct 27 19:47:49 2008
New Revision: 58309

URL: http://llvm.org/viewvc/llvm-project?rev=58309&view=rev
Log:
Avoid putting a split past the end of the live range; always shrink wrap live interval in the barrier mbb.

Added:
    llvm/trunk/test/CodeGen/X86/pre-split8.ll
    llvm/trunk/test/CodeGen/X86/pre-split9.ll
Modified:
    llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp

Modified: llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp?rev=58309&r1=58308&r2=58309&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp (original)
+++ llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp Mon Oct 27 19:47:49 2008
@@ -109,7 +109,7 @@
                      SmallPtrSet<MachineInstr*, 4>&, unsigned&);
 
     MachineBasicBlock::iterator
-      findRestorePoint(MachineBasicBlock*, MachineInstr*,
+      findRestorePoint(MachineBasicBlock*, MachineInstr*, unsigned,
                      SmallPtrSet<MachineInstr*, 4>&, unsigned&);
 
     void RecordSplit(unsigned, unsigned, unsigned, int);
@@ -203,12 +203,15 @@
 /// found.
 MachineBasicBlock::iterator
 PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI,
+                                    unsigned LastIdx,
                                     SmallPtrSet<MachineInstr*, 4> &RefsInMBB,
                                     unsigned &RestoreIndex) {
   MachineBasicBlock::iterator Pt = MBB->end();
+  unsigned EndIdx = LIs->getMBBEndIdx(MBB);
 
-  // Go bottom up if RefsInMBB is empty.
-  if (RefsInMBB.empty()) {
+  // Go bottom up if RefsInMBB is empty and the end of the mbb isn't beyond
+  // the last index in the live range.
+  if (RefsInMBB.empty() && LastIdx >= EndIdx) {
     MachineBasicBlock::iterator MII = MBB->end();
     MachineBasicBlock::iterator EndPt = MI;
     do {
@@ -224,8 +227,12 @@
   } else {
     MachineBasicBlock::iterator MII = MI;
     MII = ++MII;
+    // FIXME: Limit the number of instructions to examine to reduce
+    // compile time?
     while (MII != MBB->end()) {
       unsigned Index = LIs->getInstructionIndex(MII);
+      if (Index > LastIdx)
+        break;
       unsigned Gap = LIs->findGapBeforeInstr(Index);
       if (Gap) {
         Pt = MII;
@@ -438,13 +445,15 @@
   // If live interval is live in another successor path, then we can't process
   // this block. But we may able to do so after all the successors have been
   // processed.
-  for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(),
-         SE = MBB->succ_end(); SI != SE; ++SI) {
-    MachineBasicBlock *SMBB = *SI;
-    if (SMBB == SuccMBB)
-      continue;
-    if (CurrLI->liveAt(LIs->getMBBStartIdx(SMBB)))
-      return;
+  if (MBB != BarrierMBB) {
+    for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(),
+           SE = MBB->succ_end(); SI != SE; ++SI) {
+      MachineBasicBlock *SMBB = *SI;
+      if (SMBB == SuccMBB)
+        continue;
+      if (CurrLI->liveAt(LIs->getMBBStartIdx(SMBB)))
+        return;
+    }
   }
 
   Visited.insert(MBB);
@@ -536,7 +545,7 @@
   // Find a point to restore the value after the barrier.
   unsigned RestoreIndex;
   MachineBasicBlock::iterator RestorePt =
-    findRestorePoint(BarrierMBB, Barrier, RefsInMBB, RestoreIndex);
+    findRestorePoint(BarrierMBB, Barrier, LR->end, RefsInMBB, RestoreIndex);
   if (RestorePt == BarrierMBB->end())
     return false;
 

Added: llvm/trunk/test/CodeGen/X86/pre-split8.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pre-split8.ll?rev=58309&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/pre-split8.ll (added)
+++ llvm/trunk/test/CodeGen/X86/pre-split8.ll Mon Oct 27 19:47:49 2008
@@ -0,0 +1,35 @@
+; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 -pre-alloc-split -stats |& \
+; RUN:   grep {pre-alloc-split} | grep {Number of intervals split} | grep 1
+
+ at current_surfaces.b = external global i1		; <i1*> [#uses=1]
+
+declare double @asin(double) nounwind readonly
+
+declare double @tan(double) nounwind readonly
+
+define fastcc void @trace_line(i32 %line) nounwind {
+entry:
+	%.b3 = load i1* @current_surfaces.b		; <i1> [#uses=1]
+	br i1 %.b3, label %bb, label %return
+
+bb:		; preds = %bb9.i, %entry
+	%.rle4 = phi double [ %7, %bb9.i ], [ 0.000000e+00, %entry ]		; <double> [#uses=1]
+	%0 = load double* null, align 8		; <double> [#uses=3]
+	%1 = fcmp une double %0, 0.000000e+00		; <i1> [#uses=1]
+	br i1 %1, label %bb9.i, label %bb13.i
+
+bb9.i:		; preds = %bb
+	%2 = sub double %.rle4, %0		; <double> [#uses=0]
+	%3 = tail call double @asin(double 0.000000e+00) nounwind readonly		; <double> [#uses=0]
+	%4 = mul double 0.000000e+00, %0		; <double> [#uses=1]
+	%5 = tail call double @tan(double 0.000000e+00) nounwind readonly		; <double> [#uses=0]
+	%6 = mul double %4, 0.000000e+00		; <double> [#uses=1]
+	%7 = add double %6, 0.000000e+00		; <double> [#uses=1]
+	br i1 false, label %return, label %bb
+
+bb13.i:		; preds = %bb
+	unreachable
+
+return:		; preds = %bb9.i, %entry
+	ret void
+}

Added: llvm/trunk/test/CodeGen/X86/pre-split9.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pre-split9.ll?rev=58309&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/pre-split9.ll (added)
+++ llvm/trunk/test/CodeGen/X86/pre-split9.ll Mon Oct 27 19:47:49 2008
@@ -0,0 +1,38 @@
+; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 -pre-alloc-split -stats |& \
+; RUN:   grep {pre-alloc-split} | grep {Number of intervals split} | grep 1
+
+ at current_surfaces.b = external global i1		; <i1*> [#uses=1]
+
+declare double @sin(double) nounwind readonly
+
+declare double @asin(double) nounwind readonly
+
+declare double @tan(double) nounwind readonly
+
+define fastcc void @trace_line(i32 %line) nounwind {
+entry:
+	%.b3 = load i1* @current_surfaces.b		; <i1> [#uses=1]
+	br i1 %.b3, label %bb, label %return
+
+bb:		; preds = %bb9.i, %entry
+	%.rle4 = phi double [ %8, %bb9.i ], [ 0.000000e+00, %entry ]		; <double> [#uses=1]
+	%0 = load double* null, align 8		; <double> [#uses=3]
+	%1 = fcmp une double %0, 0.000000e+00		; <i1> [#uses=1]
+	br i1 %1, label %bb9.i, label %bb13.i
+
+bb9.i:		; preds = %bb
+	%2 = sub double %.rle4, %0		; <double> [#uses=0]
+	%3 = tail call double @asin(double 0.000000e+00) nounwind readonly		; <double> [#uses=0]
+	%4 = tail call double @sin(double 0.000000e+00) nounwind readonly		; <double> [#uses=1]
+	%5 = mul double %4, %0		; <double> [#uses=1]
+	%6 = tail call double @tan(double 0.000000e+00) nounwind readonly		; <double> [#uses=0]
+	%7 = mul double %5, 0.000000e+00		; <double> [#uses=1]
+	%8 = add double %7, 0.000000e+00		; <double> [#uses=1]
+	br i1 false, label %return, label %bb
+
+bb13.i:		; preds = %bb
+	unreachable
+
+return:		; preds = %bb9.i, %entry
+	ret void
+}





More information about the llvm-commits mailing list