[llvm] [MemCpyOpt] Require writable object during call slot optimization (PR #71542)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 01:13:49 PST 2023


================
@@ -6,7 +6,7 @@ declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture readonly, i64,
 declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1) nounwind
 
 ; all bytes of %dst that are touch by the memset are dereferenceable
-define void @must_remove_memcpy(ptr noalias nocapture dereferenceable(4096) %dst) nofree nosync {
+define void @must_remove_memcpy(ptr noalias nocapture writable dereferenceable(4096) %dst) nofree nosync {
----------------
nikic wrote:

In this particular case it is redundant, yes (and also wasn't needed before this change). But in the general case it is still needed. E.g. if we have
```llvm
define void @test(ptr writable dereferenceable(128) %dst) {
  %src = alloca [128 x i8], align 4
  call void @accept_ptr(ptr nocapture %src) nounwind
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dst, ptr %src, i64 128, i1 false)
  ret void
}
```
then we can't perform the transform because `@accept_ptr` could modify `%dst`. It depends on whether there are any ways to indirectly modify `%dst`.

https://github.com/llvm/llvm-project/pull/71542


More information about the llvm-commits mailing list