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

Chris Lattner lattner at cs.uiuc.edu
Thu Jun 5 12:16:01 PDT 2003


Changes in directory llvm/lib/CodeGen:

PHIElimination.cpp updated: 1.9 -> 1.10

---
Log message:

Fix bug: Jello/2003-06-04-bzip2-bug.ll


---
Diffs of the changes:

Index: llvm/lib/CodeGen/PHIElimination.cpp
diff -u llvm/lib/CodeGen/PHIElimination.cpp:1.9 llvm/lib/CodeGen/PHIElimination.cpp:1.10
--- llvm/lib/CodeGen/PHIElimination.cpp:1.9	Mon May 26 19:05:17 2003
+++ llvm/lib/CodeGen/PHIElimination.cpp	Thu Jun  5 12:15:04 2003
@@ -193,14 +193,16 @@
           //
           LiveVariables::VarInfo &InRegVI = LV->getVarInfo(SrcReg);
 
-          // Loop over all of the successors of the basic block, checking to
-          // see if the value is either live in the block, or if it is killed
-          // in the block.
+          // Loop over all of the successors of the basic block, checking to see
+          // if the value is either live in the block, or if it is killed in the
+          // block.  Also check to see if this register is in use by another PHI
+          // node which has not yet been eliminated.  If so, it will be killed
+          // at an appropriate point later.
           //
           bool ValueIsLive = false;
           BasicBlock *BB = opBlock.getBasicBlock();
           for (succ_iterator SI = succ_begin(BB), E = succ_end(BB);
-               SI != E; ++SI) {
+               SI != E && !ValueIsLive; ++SI) {
             const std::pair<MachineBasicBlock*, unsigned> &
               SuccInfo = LV->getBasicBlockInfo(*SI);
             
@@ -219,32 +221,28 @@
                 ValueIsLive = true;
                 break;
               }
+
+            // Is it used by any PHI instructions in this block?
+            if (ValueIsLive) break;
+
+            // Loop over all of the PHIs in this successor, checking to see if
+            // the register is being used...
+            for (MachineBasicBlock::iterator BBI = MBB->begin(), E=MBB->end();
+                 BBI != E && (*BBI)->getOpcode() == TargetInstrInfo::PHI;
+                 ++BBI)
+              for (unsigned i = 1, e = (*BBI)->getNumOperands(); i < e; i += 2)
+                if ((*BBI)->getOperand(i).getReg() == SrcReg) {
+                  ValueIsLive = true;
+                  break;
+                }
           }
           
           // Okay, if we now know that the value is not live out of the block,
           // we can add a kill marker to the copy we inserted saying that it
           // kills the incoming value!
           //
-          if (!ValueIsLive) {
-            // One more complication to worry about.  There may actually be
-            // multiple PHI nodes using this value on this branch.  If we aren't
-            // careful, the first PHI node will end up killing the value, not
-            // letting it get the to the copy for the final PHI node in the
-            // block.  Therefore we have to check to see if there is already a
-            // kill in this block, and if so, extend the lifetime to our new
-            // copy.
-            //
-            for (unsigned i = 0, e = InRegVI.Kills.size(); i != e; ++i)
-              if (InRegVI.Kills[i].first == &opBlock) {
-                std::pair<LiveVariables::killed_iterator,
-                          LiveVariables::killed_iterator> Range
-                  = LV->killed_range(InRegVI.Kills[i].second);
-                LV->removeVirtualRegistersKilled(Range.first, Range.second);
-                break;
-              }
-
+          if (!ValueIsLive)
             LV->addVirtualRegisterKilled(SrcReg, &opBlock, *(I-1));
-          }
         }
       }
     }





More information about the llvm-commits mailing list