Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MemCpyOpt] Failure to eliminate memcpy #85560

Closed
DianQK opened this issue Mar 17, 2024 · 0 comments · Fixed by #87190
Closed

[MemCpyOpt] Failure to eliminate memcpy #85560

DianQK opened this issue Mar 17, 2024 · 0 comments · Fixed by #87190

Comments

@DianQK
Copy link
Member

DianQK commented Mar 17, 2024

I tried the following code:

%0 = type { i8, [753 x i8] }

define void @src(ptr nocapture noundef %arg) local_unnamed_addr {
bb:
  %i = alloca %0, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(754) %i, ptr noundef nonnull align 1 dereferenceable(754) %arg, i64 754, i1 false)
  %i1 = getelementptr inbounds i8, ptr %i, i64 1
  store i8 1, ptr %arg, align 1
  %i2 = getelementptr inbounds i8, ptr %arg, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(753) %i2, ptr noundef nonnull align 1 dereferenceable(753) %i1, i64 753, i1 false)
  ret void
}

define void @tgt(ptr nocapture noundef %arg) local_unnamed_addr {
bb:
  store i8 1, ptr %arg, align 1
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

We can eliminate all memcpy.

alive2: https://alive2.llvm.org/ce/z/hCPePV
From: rust-lang/rust#122610 (comment).

@DianQK DianQK self-assigned this Mar 17, 2024
@DianQK DianQK changed the title [MemCpyOpt] Failed to eliminate memcpy [MemCpyOpt] Failure to eliminate memcpy Mar 17, 2024
@DianQK DianQK changed the title [MemCpyOpt] Failure to eliminate memcpy [MemCpyOpt?] Failure to eliminate memcpy Mar 17, 2024
@DianQK DianQK changed the title [MemCpyOpt?] Failure to eliminate memcpy [MemCpyOpt] Failure to eliminate memcpy Mar 28, 2024
@DianQK DianQK closed this as completed in fa24213 Jul 12, 2024
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this issue Jul 14, 2024
…n. (llvm#87190)

Fixes llvm#85560.

We can forward `memcpy` as long as the actual memory location being
copied have not been altered.

alive2: https://alive2.llvm.org/ce/z/q9JaHV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants