This is takeover from @pcwalton 's https://reviews.llvm.org/D140089
New transformation unifies the two allocates on the same BB if the followings are satisfied
(1) The src is fully copied to dest by memcpy, memmove or store&load.
(2) src and dest are 1) static alloca, which is to avoid stacksave/stackrestore handling, 2) unescaped allocas.
(3) The dest has no Mod Ref except full-sized lifetime intrinsic and copy itself, from the alloca to the store.
(4) If the dest has no Mod => src has no Ref, dest has no Ref => src has no Mod from the store to the end of BB.
Roughly, the target structure on this patch is like the following.
{ unescaped static allocas of src/dest ↓ src/dest may have mod/ref. Practically it may be sufficient to bailout if dest has any ModRef, many case would be problem if the dest is replaced with src. full-size copy from src to dest, memcpy/memmove/load-store of the src value. ↓ src/dest may have mod/ref. There have to be no read(ref) with the other one's write(mod) end without capturing both of the alloca. }
For the dest modification before the copy, it could be ok to erase those mods, because of the unescaped allocas in this case.
For mod/ref condition after the full-size copy, the @pcwalton 's original patch did the BB-level liveness checks. Maybe this patch has a lot of room to improve. The inherent condition is that one of two ptr is unnecessary for any execution path.
It seems like there are almost no compile-time regressions. https://llvm-compile-time-tracker.com/compare.php?from=0f9f95146a7fc6fa4f9bc3c1aa2a23386f521dac&to=a6c40d12ea1c6a4b82e88ce1c7b2a723d199fb85&stat=instructions:u
pre-commit tests: https://reviews.llvm.org/D152277
pre-commit tests for user order crash https://reviews.llvm.org/D155179
pre-commit tests for terminator crash https://reviews.llvm.org/D155571
misaligned, clang-format please?