Avoid comparing invalid slot indexes, and assert that it doesn't happen.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Thu, 3 Mar 2011 05:18:19 +0000 (05:18 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Thu, 3 Mar 2011 05:18:19 +0000 (05:18 +0000)
The SlotIndex created by the default construction does not represent a position
in the function, and it doesn't make sense to compare it to other indexes.

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

include/llvm/CodeGen/SlotIndexes.h
lib/CodeGen/RegAllocLinearScan.cpp
lib/CodeGen/SimpleRegisterCoalescing.cpp

index 8d3b1c09335ffd99543464e3d9084249d3f6d6b5..153e520a4771052aa8e26bf606c15fda39b03cca 100644 (file)
@@ -135,6 +135,7 @@ namespace llvm {
     }
 
     IndexListEntry& entry() const {
+      assert(isValid() && "Attempt to compare reserved index.");
       return *lie.getPointer();
     }
 
@@ -530,7 +531,7 @@ namespace llvm {
     /// Returns the instruction for the given index, or null if the given
     /// index has no instruction associated with it.
     MachineInstr* getInstructionFromIndex(SlotIndex index) const {
-      return index.entry().getInstr();
+      return index.isValid() ? index.entry().getInstr() : 0;
     }
 
     /// Returns the next non-null index.
index b959878bcdbacfe62678588e5878589ff234f4e2..a24fc80cf5eab17cb9cc53fae9684a675fb6a868 100644 (file)
@@ -458,7 +458,7 @@ unsigned RALinScan::attemptTrivialCoalescing(LiveInterval &cur, unsigned Reg) {
   const LiveRange &range = cur.ranges.front();
 
   VNInfo *vni = range.valno;
-  if (vni->isUnused())
+  if (vni->isUnused() || !vni->def.isValid())
     return Reg;
 
   unsigned CandReg;
@@ -993,7 +993,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur) {
   // one, e.g. X86::mov32to32_. These move instructions are not coalescable.
   if (!vrm_->getRegAllocPref(cur->reg) && cur->hasAtLeastOneValue()) {
     VNInfo *vni = cur->begin()->valno;
-    if (!vni->isUnused()) {
+    if (!vni->isUnused() && vni->def.isValid()) {
       MachineInstr *CopyMI = li_->getInstructionFromIndex(vni->def);
       if (CopyMI && CopyMI->isCopy()) {
         unsigned DstSubReg = CopyMI->getOperand(0).getSubReg();
index 2843c1a5b6d8b2b530bb7309fd5a2a4303edd7ee..74898c210a4f854d633ef308496714d0eae35ed1 100644 (file)
@@ -1568,9 +1568,7 @@ SimpleRegisterCoalescing::lastRegisterUse(SlotIndex Start,
       if (UseMI->isIdentityCopy())
         continue;
       SlotIndex Idx = li_->getInstructionIndex(UseMI);
-      // FIXME: Should this be Idx != UseIdx? SlotIndex() will return something
-      // that compares higher than any other interval.
-      if (Idx >= Start && Idx < End && Idx >= UseIdx) {
+      if (Idx >= Start && Idx < End && (!UseIdx.isValid() || Idx >= UseIdx)) {
         LastUse = &Use;
         UseIdx = Idx.getUseIndex();
       }