This patch aims to remove memcpy on immutable arguments from attributes.
We can safely remove src-to-dest memcpy dest is used as only the call parameter if following conditions are satisfied
This is called on memcpy dest pointer arguments attributed as immutable
during call. Try to use memcpy source directly if all of the following
conditions are satisfied.
- The memcpy dst is neither modified during the call nor captured by the call. (if readonly, noalias, nocapture attributes on call-site.)
- The memcpy dst is an alloca with known alignment & size.
- The memcpy length == the alloca size which ensures that the new pointer is dereferenceable for the required range
- The src pointer has alignment >= the alloca alignment or can be enforced so.
- The memcpy dst and src is not modified between the memcpy and the call. (if MSSA clobber check is safe.)
- The memcpy src is not modified during the call. (ModRef check shows no Mod.)
(from https://reviews.llvm.org/D150967#4359222 and https://reviews.llvm.org/D150967#4365466 )
precommit tests: https://reviews.llvm.org/D150967
Motivated to resolve https://github.com/rust-lang/rust/issues/107436
<= should be >= here?