forked from OSchip/llvm-project
[MemCpyOpt] Optimize MemoryDef insertion
When converting a store into a memset, we currently insert the new MemoryDef after the store MemoryDef, which requires all uses to be renamed to the new def using a whole block scan. Instead, we can insert the new MemoryDef before the store and not rename uses, because we know that the location is immediately overwritten, so all uses should still refer to the old MemoryDef. Those uses will get renamed when the old MemoryDef is actually dropped, which is efficient. I expect something similar can be done for some of the other MSSA updates in MemCpyOpt. This is an alternative to D107513, at least for this particular case. Differential Revision: https://reviews.llvm.org/D107702
This commit is contained in:
parent
2f946eaa9d
commit
17db125b48
|
@ -799,11 +799,12 @@ bool MemCpyOptPass::processStore(StoreInst *SI, BasicBlock::iterator &BBI) {
|
|||
|
||||
LLVM_DEBUG(dbgs() << "Promoting " << *SI << " to " << *M << "\n");
|
||||
|
||||
assert(isa<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(SI)));
|
||||
auto *LastDef =
|
||||
cast<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(SI));
|
||||
auto *NewAccess = MSSAU->createMemoryAccessAfter(M, LastDef, LastDef);
|
||||
MSSAU->insertDef(cast<MemoryDef>(NewAccess), /*RenameUses=*/true);
|
||||
// The newly inserted memset is immediately overwritten by the original
|
||||
// store, so we do not need to rename uses.
|
||||
auto *StoreDef = cast<MemoryDef>(MSSA->getMemoryAccess(SI));
|
||||
auto *NewAccess = MSSAU->createMemoryAccessBefore(
|
||||
M, StoreDef->getDefiningAccess(), StoreDef);
|
||||
MSSAU->insertDef(cast<MemoryDef>(NewAccess), /*RenameUses=*/false);
|
||||
|
||||
eraseInstruction(SI);
|
||||
NumMemSetInfer++;
|
||||
|
|
Loading…
Reference in New Issue