X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FMachineCopyPropagation.cpp;h=e41d3eee216a7c54901cf627bf1265213733f390;hb=34fa5640b805e6bc7a8259e181eed64051c09b4e;hp=4f48e2cd9720a96d3ada07f5fec611ba3174e22f;hpb=62c320a755ac27ac2b7f64e927892249e0f486e0;p=oota-llvm.git diff --git a/lib/CodeGen/MachineCopyPropagation.cpp b/lib/CodeGen/MachineCopyPropagation.cpp index 4f48e2cd972..e41d3eee216 100644 --- a/lib/CodeGen/MachineCopyPropagation.cpp +++ b/lib/CodeGen/MachineCopyPropagation.cpp @@ -127,13 +127,10 @@ static bool isNopCopy(MachineInstr *CopyMI, unsigned Def, unsigned Src, } // Remove MI from the function because it has been determined it is dead. -// Turn it into a noop KILL instruction if it has super-register liveness -// adjustments. +// Turn it into a noop KILL instruction as opposed to removing it to +// maintain imp-use/imp-def chains. void MachineCopyPropagation::removeCopy(MachineInstr *MI) { - if (MI->getNumOperands() == 2) - MI->eraseFromParent(); - else - MI->setDesc(TII->get(TargetOpcode::KILL)); + MI->setDesc(TII->get(TargetOpcode::KILL)); } bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { @@ -142,6 +139,8 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { DenseMap CopyMap; // Def -> copies map SourceMap SrcMap; // Src -> Def map + DEBUG(dbgs() << "MCP: CopyPropagateBlock " << MBB.getName() << "\n"); + bool Changed = false; for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ) { MachineInstr *MI = &*I; @@ -176,6 +175,8 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { // CALL // %RAX = COPY %RSP + DEBUG(dbgs() << "MCP: copy is a NOP, removing: "; MI->dump()); + // Clear any kills of Def between CopyMI and MI. This extends the // live range. for (MachineBasicBlock::iterator I = CopyMI, E = MI; I != E; ++I) @@ -191,10 +192,14 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { // If Src is defined by a previous copy, it cannot be eliminated. for (MCRegAliasIterator AI(Src, TRI, true); AI.isValid(); ++AI) { CI = CopyMap.find(*AI); - if (CI != CopyMap.end()) + if (CI != CopyMap.end()) { + DEBUG(dbgs() << "MCP: Copy is no longer dead: "; CI->second->dump()); MaybeDeadCopies.remove(CI->second); + } } + DEBUG(dbgs() << "MCP: Copy is a deletion candidate: "; MI->dump()); + // Copy is now a candidate for deletion. MaybeDeadCopies.insert(MI); @@ -255,8 +260,10 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { // for elimination. for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) { DenseMap::iterator CI = CopyMap.find(*AI); - if (CI != CopyMap.end()) + if (CI != CopyMap.end()) { + DEBUG(dbgs() << "MCP: Copy is used - not dead: "; CI->second->dump()); MaybeDeadCopies.remove(CI->second); + } } } @@ -273,6 +280,8 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { unsigned Reg = (*DI)->getOperand(0).getReg(); if (MRI->isReserved(Reg) || !MaskMO.clobbersPhysReg(Reg)) continue; + DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: "; + (*DI)->dump()); removeCopy(*DI); Changed = true; ++NumDeletes;