diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-05-23 20:21:06 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-05-23 20:21:06 +0000 |
commit | e3b548219ff47b1384aa7325ebbe21c795c19974 (patch) | |
tree | be2ad173cce5c9060b331bcfdcea6e315780bad8 /lib/CodeGen/RegisterCoalescer.cpp | |
parent | 4c8657a9578e171f198adda8d5910b78dbb7bdc6 (diff) | |
download | llvm-e3b548219ff47b1384aa7325ebbe21c795c19974.tar.gz llvm-e3b548219ff47b1384aa7325ebbe21c795c19974.tar.bz2 llvm-e3b548219ff47b1384aa7325ebbe21c795c19974.tar.xz |
Correctly deal with identity copies in RegisterCoalescer.
Now that the coalescer keeps live intervals and machine code in sync at
all times, it needs to deal with identity copies differently.
When merging two virtual registers, all identity copies are removed
right away. This means that other identity copies must come from
somewhere else, and they are going to have a value number.
Deal with such copies by merging the value numbers before erasing the
copy instruction. Otherwise, we leave dangling value numbers in the live
interval.
This fixes PR12927.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157340 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/RegisterCoalescer.cpp')
-rw-r--r-- | lib/CodeGen/RegisterCoalescer.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/CodeGen/RegisterCoalescer.cpp b/lib/CodeGen/RegisterCoalescer.cpp index 30997c24ba..db117ed1a0 100644 --- a/lib/CodeGen/RegisterCoalescer.cpp +++ b/lib/CodeGen/RegisterCoalescer.cpp @@ -988,20 +988,31 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) { return true; } - // If they are already joined we continue. - if (CP.getSrcReg() == CP.getDstReg()) { - DEBUG(dbgs() << "\tCopy already coalesced.\n"); + // Eliminate undefs. + if (!CP.isPhys() && eliminateUndefCopy(CopyMI, CP)) { + DEBUG(dbgs() << "\tEliminated copy of <undef> value.\n"); LIS->RemoveMachineInstrFromMaps(CopyMI); CopyMI->eraseFromParent(); return false; // Not coalescable. } - // Eliminate undefs. - if (!CP.isPhys() && eliminateUndefCopy(CopyMI, CP)) { - DEBUG(dbgs() << "\tEliminated copy of <undef> value.\n"); + // Coalesced copies are normally removed immediately, but transformations + // like removeCopyByCommutingDef() can inadvertently create identity copies. + // When that happens, just join the values and remove the copy. + if (CP.getSrcReg() == CP.getDstReg()) { + LiveInterval &LI = LIS->getInterval(CP.getSrcReg()); + DEBUG(dbgs() << "\tCopy already coalesced: " << LI << '\n'); + LiveRangeQuery LRQ(LI, LIS->getInstructionIndex(CopyMI)); + if (VNInfo *DefVNI = LRQ.valueDefined()) { + VNInfo *ReadVNI = LRQ.valueIn(); + assert(ReadVNI && "No value before copy and no <undef> flag."); + assert(ReadVNI != DefVNI && "Cannot read and define the same value."); + LI.MergeValueNumberInto(DefVNI, ReadVNI); + DEBUG(dbgs() << "\tMerged values: " << LI << '\n'); + } LIS->RemoveMachineInstrFromMaps(CopyMI); CopyMI->eraseFromParent(); - return false; // Not coalescable. + return true; } // Enforce policies. |