[llvm-commits] [llvm] r58255 - /llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp

David Greene greened at obbligato.org
Mon Oct 27 10:39:00 PDT 2008


Author: greened
Date: Mon Oct 27 12:38:59 2008
New Revision: 58255

URL: http://llvm.org/viewvc/llvm-project?rev=58255&view=rev
Log:

Fix PR2634.  Create new virtual registers from spills early so that we
can give it the same stack slot as the spilled interval if it is folded.
This prevents the fold/unfold code from pointing to the wrong register.

Modified:
    llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp

Modified: llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp?rev=58255&r1=58254&r2=58255&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp Mon Oct 27 12:38:59 2008
@@ -1231,6 +1231,17 @@
       if (!TrySplit)
       SSWeight += Weight;
 
+    // Create a new virtual register for the spill interval.
+    // Create the new register now so we can map the fold instruction
+    // to the new register so when it is unfolded we get the correct
+    // answer.
+    bool CreatedNewVReg = false;
+    if (NewVReg == 0) {
+      NewVReg = mri_->createVirtualRegister(rc);
+      vrm.grow();
+      CreatedNewVReg = true;
+    }
+
     if (!TryFold)
       CanFold = false;
     else {
@@ -1238,9 +1249,16 @@
       // optimal point to insert a load / store later.
       if (!TrySplit) {
         if (tryFoldMemoryOperand(MI, vrm, ReMatDefMI, index,
-                                 Ops, FoldSS, FoldSlot, Reg)) {
+                                 Ops, FoldSS, FoldSlot, NewVReg)) {
           // Folding the load/store can completely change the instruction in
           // unpredictable ways, rescan it from the beginning.
+
+          if (FoldSS) {
+            // We need to give the new vreg the same stack slot as the
+            // spilled interval.
+            vrm.assignVirt2StackSlot(NewVReg, FoldSlot);
+          }
+
           HasUse = false;
           HasDef = false;
           CanFold = false;
@@ -1256,13 +1274,6 @@
       }
     }
 
-    // Create a new virtual register for the spill interval.
-    bool CreatedNewVReg = false;
-    if (NewVReg == 0) {
-      NewVReg = mri_->createVirtualRegister(rc);
-      vrm.grow();
-      CreatedNewVReg = true;
-    }
     mop.setReg(NewVReg);
     if (mop.isImplicit())
       rewriteImplicitOps(li, MI, NewVReg, vrm);





More information about the llvm-commits mailing list