[MemCpyOpt] Handle read from lifetime.start with offset
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 13 Mar 2021 19:28:53 +0000 (20:28 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 13 Mar 2021 19:38:09 +0000 (20:38 +0100)
commit55566609711f284581d822576705354444e6a7f0
tree1d6a8abc626d64647f85117881369f6ad9a84d47
parenta10bf5572d2ab11f5965e8a940343734b8802797
[MemCpyOpt] Handle read from lifetime.start with offset

This fixes a regression from the MemDep-based implementation:
MemDep completely ignores lifetime.start intrinsics that aren't
MustAlias -- this is probably unsound, but it does mean that the
MemDep based implementation successfully eliminated memcpy's from
lifetime.start if the memcpy happens at an offset, rather than
the base address of the alloca.

Add a special case for the case where the lifetime.start spans the
whole alloca (which is pretty much the only kind of lifetime.start
that frontends ever emit), as we don't need to figure out our exact
aliasing relationship in that case, the whole alloca is dead prior
to the call.

If this doesn't cover all practically relevant cases, then it
would be possible to make use of the recently added PartialAlias
clobber offsets to make this more precise.
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/test/Transforms/MemCpyOpt/memcpy-undef.ll