Fix a latent bug that my spiller patch last week exposed: we were leaving
authorChris Lattner <sabre@nondot.org>
Mon, 1 May 2006 22:03:24 +0000 (22:03 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 1 May 2006 22:03:24 +0000 (22:03 +0000)
instructions in the virtregfolded map that were deleted.  Because they
were deleted, newly allocated instructions could end up at the same address,
magically finding themselves in the map.  The solution is to remove entries
from the map when we delete the instructions.

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

lib/CodeGen/VirtRegMap.cpp
lib/CodeGen/VirtRegMap.h

index fa5a6ac8e8074d12de155e6da597cb5b201e53cf..912359d13755ebaf5abf380ab06a81ad3f26eda5 100644 (file)
@@ -730,6 +730,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) {
           assert(VirtRegMap::isMod && "Can't be modref!");
           DEBUG(std::cerr << "Removed dead store:\t" << *MDSI->second);
           MBB.erase(MDSI->second);
+          VRM.RemoveFromFoldedVirtMap(MDSI->second);
           MaybeDeadStores.erase(MDSI);
           ++NumDSE;
         }
@@ -791,6 +792,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) {
               ++NumDCE;
               DEBUG(std::cerr << "Removing now-noop copy: " << MI);
               MBB.erase(&MI);
+              VRM.RemoveFromFoldedVirtMap(&MI);
               goto ProcessNextInst;
             }
             Spills.ClobberPhysReg(VirtReg);
@@ -825,6 +827,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) {
             ++NumDCE;
             DEBUG(std::cerr << "Removing now-noop copy: " << MI);
             MBB.erase(&MI);
+            VRM.RemoveFromFoldedVirtMap(&MI);
             goto ProcessNextInst;
           }
         }
@@ -835,6 +838,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) {
           DEBUG(std::cerr << "Removed dead store:\t" << *LastStore);
           ++NumDSE;
           MBB.erase(LastStore);
+          VRM.RemoveFromFoldedVirtMap(LastStore);
         }
         LastStore = next(MII);
 
index 898677e8f9295ec9e73d93461de3919a3ac93700..83d5aada473fac3121c5f3714f266c2d6d8c154d 100644 (file)
@@ -137,11 +137,10 @@ namespace llvm {
       return MI2VirtMap.equal_range(MI);
     }
     
-    /// RemoveFromFoldedVirtMap - Given a machine instruction in the folded
-    /// instruction map, remove the entry in the folded instruction map.
+    /// RemoveFromFoldedVirtMap - If the specified machine instruction is in
+    /// the folded instruction map, remove its entry from the map.
     void RemoveFromFoldedVirtMap(MachineInstr *MI) {
-      bool ErasedAny = MI2VirtMap.erase(MI);
-      assert(ErasedAny && "Machine instr not in folded vreg map!");
+      MI2VirtMap.erase(MI);
     }
 
     void print(std::ostream &OS) const;