diff options
author | Bill Wendling <isanbard@gmail.com> | 2006-08-21 07:33:33 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2006-08-21 07:33:33 +0000 |
commit | d36d03bf2daec79a364f32aba4f4a672c814c1bd (patch) | |
tree | fb79ec73a3da33131662a6b1c8352e02919b21b8 /lib/CodeGen/VirtRegMap.cpp | |
parent | 8ea5ecb0564b8822c70ad84202471f03e2690da7 (diff) |
Added a check so that if we have two machine instructions in this form
MOV R0, R1
MOV R1, R0
the second machine instruction is removed. Added a regression test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29792 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/VirtRegMap.cpp')
-rw-r--r-- | lib/CodeGen/VirtRegMap.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index bc56945bc8..7e6d09bc12 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -521,6 +521,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // Process all of the spilled uses and all non spilled reg references. for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { MachineOperand &MO = MI.getOperand(i); + if (!MO.isRegister() || MO.getReg() == 0) continue; // Ignore non-register operands. @@ -790,16 +791,37 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { } if (!OpTakenCareOf) { - // Check to see if this is a noop copy. If so, eliminate the - // instruction before considering the dest reg to be changed. unsigned Src, Dst; - if (TII->isMoveInstr(MI, Src, Dst) && Src == Dst) { - ++NumDCE; - DEBUG(std::cerr << "Removing now-noop copy: " << MI); - MBB.erase(&MI); - VRM.RemoveFromFoldedVirtMap(&MI); - goto ProcessNextInst; + if (TII->isMoveInstr(MI, Src, Dst)) { + if (Src == Dst) { + // Check to see if this is a noop copy. If so, eliminate + // the instruction before considering the dest reg to be + // changed. + ++NumDCE; + DEBUG(std::cerr << "Removing now-noop copy: " << MI); + MBB.erase(&MI); + VRM.RemoveFromFoldedVirtMap(&MI); + goto ProcessNextInst; + } else if (MII != MBB.begin()) { + // Check to see if this is a sequence of the form: + // mov R0, R1 + // mov R1, R0 + // Eliminate the second move if so. + MachineBasicBlock::iterator PrevMII = MII; --PrevMII; + MachineInstr& PrevMI = *PrevMII; + unsigned PrevSrc, PrevDst; + + if (TII->isMoveInstr(PrevMI, PrevSrc, PrevDst)) + if (PrevSrc == Dst && PrevDst == Src) { + ++NumDCE; + DEBUG(std::cerr << "Removing now-noop copy: " << MI); + MBB.erase(&MI); + VRM.RemoveFromFoldedVirtMap(&MI); + goto ProcessNextInst; + } + } } + Spills.ClobberPhysReg(VirtReg); continue; } @@ -861,8 +883,6 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { } } - - llvm::Spiller* llvm::createSpiller() { switch (SpillerOpt) { default: assert(0 && "Unreachable!"); |