[llvm-commits] [llvm] r66677 - /llvm/branches/Apple/Dib/lib/CodeGen/PostRASchedulerList.cpp

Dan Gohman gohman at apple.com
Wed Mar 11 11:10:51 PDT 2009


Author: djg
Date: Wed Mar 11 13:10:51 2009
New Revision: 66677

URL: http://llvm.org/viewvc/llvm-project?rev=66677&view=rev
Log:
Merge from trunk:

r66558 | djg | 2009-03-10 11:10:43 -0700 (Tue, 10 Mar 2009) | 10 lines

Fix a post-RA scheduling liveness bug. When a basic block is being
scheduled in multiple regions, liveness data used by the
anti-dependence breaker is carried from one region to the next, however
the information reflects the state of the instructions before scheduling.
After scheduling, there may be new live range overlaps. Handle this by
pessimizing the liveness data carried between regions to the point where
it will be conservatively correct now matter how the earlier region is
scheduled. This fixes a miscompilation in 176.gcc with the post-RA
scheduler enabled.


Modified:
    llvm/branches/Apple/Dib/lib/CodeGen/PostRASchedulerList.cpp

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

==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/PostRASchedulerList.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/PostRASchedulerList.cpp Wed Mar 11 13:10:51 2009
@@ -258,22 +258,19 @@
     for (MachineBasicBlock::iterator I = Current; I != MBB->begin(); ) {
       MachineInstr *MI = prior(I);
       if (isSchedulingBoundary(MI, Fn)) {
-        if (I != Current) {
-          Scheduler.Run(MBB, I, Current, CurrentCount);
-          Scheduler.EmitSchedule();
-        }
-        Scheduler.Observe(MI, Count);
+        Scheduler.Run(MBB, I, Current, CurrentCount);
+        Scheduler.EmitSchedule();
         Current = MI;
         CurrentCount = Count - 1;
+        Scheduler.Observe(MI, CurrentCount);
       }
       I = MI;
       --Count;
     }
     assert(Count == 0 && "Instruction count mismatch!");
-    if (MBB->begin() != Current) {
-      assert(CurrentCount != 0 && "Instruction count mismatch!");
-      Scheduler.Run(MBB, MBB->begin(), Current, CurrentCount);
-    }
+    assert(MBB->begin() == Current || CurrentCount != 0 &&
+           "Instruction count mismatch!");
+    Scheduler.Run(MBB, MBB->begin(), Current, CurrentCount);
     Scheduler.EmitSchedule();
 
     // Clean up register live-range state.
@@ -392,6 +389,22 @@
 /// instruction, which will not be scheduled.
 ///
 void SchedulePostRATDList::Observe(MachineInstr *MI, unsigned Count) {
+  assert(Count < InsertPosIndex && "Instruction index out of expected range!");
+
+  // Any register which was defined within the previous scheduling region
+  // may have been rescheduled and its lifetime may overlap with registers
+  // in ways not reflected in our current liveness state. For each such
+  // register, adjust the liveness state to be conservatively correct.
+  for (unsigned Reg = 0; Reg != TargetRegisterInfo::FirstVirtualRegister; ++Reg)
+    if (DefIndices[Reg] < InsertPosIndex && DefIndices[Reg] >= Count) {
+      assert(KillIndices[Reg] == ~0u && "Clobbered register is live!");
+      // Mark this register to be non-renamable.
+      Classes[Reg] = reinterpret_cast<TargetRegisterClass *>(-1);
+      // Move the def index to the end of the previous region, to reflect
+      // that the def could theoretically have been scheduled at the end.
+      DefIndices[Reg] = InsertPosIndex;
+    }
+
   PrescanInstruction(MI);
   ScanInstruction(MI, Count);
 }





More information about the llvm-commits mailing list