[llvm-commits] CVS: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Jul 24 22:45:28 PDT 2004



Changes in directory llvm/lib/CodeGen:

LiveIntervalAnalysis.cpp updated: 1.112 -> 1.113

---
Log message:

Fix a bug where we incorrectly value numbered the first PHI definition the
same as the PHI use.  This is not correct as the PHI use value is different
depending on which branch is taken.  This fixes espresso with aggressive
coallescing, and perhaps others.


---
Diffs of the changes:  (+26 -3)

Index: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp
diff -u llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.112 llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.113
--- llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.112	Sat Jul 24 22:24:11 2004
+++ llvm/lib/CodeGen/LiveIntervalAnalysis.cpp	Sun Jul 25 00:45:18 2004
@@ -393,9 +393,32 @@
          DEBUG(std::cerr << "RESULT: " << interval);
 
        } else {
-         // Otherwise, this must be because of phi elimination.  In this case, 
-         // the defined value will be live until the end of the basic block it
-         // is defined in.
+         // Otherwise, this must be because of phi elimination.  If this is the
+         // first redefinition of the vreg that we have seen, go back and change
+         // the live range in the PHI block to be a different value number.
+         if (interval.containsOneValue()) {
+           assert(vi.Kills.size() == 1 &&
+                  "PHI elimination vreg should have one kill, the PHI itself!");
+
+           // Remove the old range that we now know has an incorrect number.
+           MachineInstr *Killer = vi.Kills[0];
+           unsigned Start = getInstructionIndex(Killer->getParent()->begin());
+           unsigned End = getUseIndex(getInstructionIndex(Killer))+1;
+           DEBUG(std::cerr << "Removing [" << Start << "," << End << "] from: "
+                 << interval << "\n");
+           interval.removeRange(Start, End);
+           DEBUG(std::cerr << "RESULT: " << interval);
+
+           // Replace the interval with one of a NEW value number.
+           LiveRange LR(Start, End, interval.getNextValue());
+           DEBUG(std::cerr << " replace range with " << LR);
+           interval.addRange(LR);
+           DEBUG(std::cerr << "RESULT: " << interval);
+         }
+
+         // In the case of PHI elimination, each variable definition is only
+         // live until the end of the block.  We've already taken care of the
+         // rest of the live range.
          unsigned defIndex = getDefIndex(getInstructionIndex(mi));
          LiveRange LR(defIndex, 
                       getInstructionIndex(&mbb->back()) + InstrSlots::NUM,





More information about the llvm-commits mailing list