From 08d2e4e09adc53aa93c08c8327d2f5f2814acb74 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 5 Jun 2003 17:15:04 +0000 Subject: [PATCH] Fix bug: Jello/2003-06-04-bzip2-bug.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6624 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/PHIElimination.cpp | 44 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/CodeGen/PHIElimination.cpp b/lib/CodeGen/PHIElimination.cpp index 2149f9044ea..e221bd74ab1 100644 --- a/lib/CodeGen/PHIElimination.cpp +++ b/lib/CodeGen/PHIElimination.cpp @@ -193,14 +193,16 @@ bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) { // 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 & SuccInfo = LV->getBasicBlockInfo(*SI); @@ -219,32 +221,28 @@ bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) { 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 Range - = LV->killed_range(InRegVI.Kills[i].second); - LV->removeVirtualRegistersKilled(Range.first, Range.second); - break; - } - + if (!ValueIsLive) LV->addVirtualRegisterKilled(SrcReg, &opBlock, *(I-1)); - } } } }