[MemCpyOpt] Preserve MemorySSA.
authorFlorian Hahn <flo@fhahn.com>
Fri, 4 Sep 2020 07:44:57 +0000 (08:44 +0100)
committerFlorian Hahn <flo@fhahn.com>
Fri, 4 Sep 2020 08:05:33 +0000 (09:05 +0100)
commite2fc6a31d347dc96c2dec6acb72045150f525630
tree015bf04e7754eab47389459b5c18a1262007ce7e
parentaec9e20a3e9a4f25a5b1e07816c95f970300d918
[MemCpyOpt] Preserve MemorySSA.

This patch updates MemCpyOpt to preserve MemorySSA. It uses the
MemoryDef at the insertion point of the builder and inserts the new def
after that def.

In some cases, we just modify a memory instruction. In that case, get
the defining access, then remove the memory access and add a new one.
If the defining access is in a different block, insert a new def at the
beginning of the current block, otherwise after the defining access.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D86651
llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll [new file with mode: 0644]