MergeValueInto is too smart: it might choose to do the merge the opposite direction.
authorOwen Anderson <resistor@mac.com>
Mon, 2 Feb 2009 22:42:01 +0000 (22:42 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 2 Feb 2009 22:42:01 +0000 (22:42 +0000)
Live interval reconstruction needs to account for this, and scour its maps to
prevent dangling references.

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

include/llvm/CodeGen/LiveInterval.h
lib/CodeGen/LiveInterval.cpp
lib/CodeGen/PreAllocSplitting.cpp

index 7bcc4c7cb88f754813ba0e0dad45a94d6623874e..fb7448635711fb6308ec7f4dd5d733c7c51bb241 100644 (file)
@@ -276,7 +276,7 @@ namespace llvm {
     /// are found to be equivalent.  This eliminates V1, replacing all
     /// LiveRanges with the V1 value number with the V2 value number.  This can
     /// cause merging of V1/V2 values numbers and compaction of the value space.
-    void MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
+    VNInfo* MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
 
     /// MergeInClobberRanges - For any live ranges that are not defined in the
     /// current interval, but are defined in the Clobbers interval, mark them
index 6341b9cd5071b44cbd212e80cb2d6af4069dbf11..40f8cd4388d89bc65bc89358e06d8d74e4b481e0 100644 (file)
@@ -591,7 +591,7 @@ void LiveInterval::MergeInClobberRanges(const LiveInterval &Clobbers,
 /// are found to be equivalent.  This eliminates V1, replacing all
 /// LiveRanges with the V1 value number with the V2 value number.  This can
 /// cause merging of V1/V2 values numbers and compaction of the value space.
-void LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
+VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
   assert(V1 != V2 && "Identical value#'s are always equivalent!");
 
   // This code actually merges the (numerically) larger value number into the
@@ -652,6 +652,8 @@ void LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
   } else {
     V1->def = ~1U;
   }
+  
+  return V2;
 }
 
 void LiveInterval::Copy(const LiveInterval &RHS,
index a538db8be086ed0bc9bda8f119e5def9c2b8d5fa..99fdb840cc74136e263a130c922bf3e8738314d6 100644 (file)
@@ -654,8 +654,24 @@ PreAllocSplitting::PerformPHIConstructionFallBack(MachineBasicBlock::iterator Us
   }
     
   if (MBB->pred_size() == 1 && !RetVNI->hasPHIKill) {
-    LI->MergeValueNumberInto(RetVNI, IncomingVNs.begin()->second);
-    Phis[MBB] = RetVNI = IncomingVNs.begin()->second;
+    VNInfo* OldVN = RetVNI;
+    VNInfo* NewVN = IncomingVNs.begin()->second;
+    VNInfo* MergedVN = LI->MergeValueNumberInto(OldVN, NewVN);
+    if (MergedVN == OldVN) std::swap(OldVN, NewVN);
+    
+    for (DenseMap<MachineBasicBlock*, VNInfo*>::iterator LOI = LiveOut.begin(),
+         LOE = LiveOut.end(); LOI != LOE; ++LOI)
+      if (LOI->second == OldVN)
+        LOI->second = MergedVN;
+    for (DenseMap<MachineInstr*, VNInfo*>::iterator NVI = NewVNs.begin(),
+         NVE = NewVNs.end(); NVI != NVE; ++NVI)
+      if (NVI->second == OldVN)
+        NVI->second = MergedVN;
+    for (DenseMap<MachineBasicBlock*, VNInfo*>::iterator PI = Phis.begin(),
+         PE = Phis.end(); PI != PE; ++PI)
+      if (PI->second == OldVN)
+        PI->second = MergedVN;
+    RetVNI = MergedVN;
   } else {
     // Otherwise, merge the incoming VNInfos with a phi join.  Create a new
     // VNInfo to represent the joined value.