callslot_deref.ll 1.5 KB

123456789101112131415161718192021222324252627282930
  1. ; RUN: opt < %s -S -basicaa -memcpyopt | FileCheck %s
  2. target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
  3. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) unnamed_addr nounwind
  4. declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
  5. ; all bytes of %dst that are touch by the memset are dereferenceable
  6. define void @must_remove_memcpy(i8* noalias nocapture dereferenceable(4096) %dst) {
  7. ; CHECK-LABEL: @must_remove_memcpy(
  8. ; CHECK: call void @llvm.memset.p0i8.i64
  9. ; CHECK-NOT: call void @llvm.memcpy.p0i8.p0i8.i64
  10. %src = alloca [4096 x i8], align 1
  11. %p = getelementptr inbounds [4096 x i8], [4096 x i8]* %src, i64 0, i64 0
  12. call void @llvm.memset.p0i8.i64(i8* %p, i8 0, i64 4096, i32 1, i1 false)
  13. call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %p, i64 4096, i32 1, i1 false) #2
  14. ret void
  15. }
  16. ; memset touch more bytes than those guaranteed to be dereferenceable
  17. ; We can't remove the memcpy, but we can turn it into an independent memset.
  18. define void @must_not_remove_memcpy(i8* noalias nocapture dereferenceable(1024) %dst) {
  19. ; CHECK-LABEL: @must_not_remove_memcpy(
  20. ; CHECK: call void @llvm.memset.p0i8.i64
  21. ; CHECK: call void @llvm.memset.p0i8.i64
  22. %src = alloca [4096 x i8], align 1
  23. %p = getelementptr inbounds [4096 x i8], [4096 x i8]* %src, i64 0, i64 0
  24. call void @llvm.memset.p0i8.i64(i8* %p, i8 0, i64 4096, i32 1, i1 false)
  25. call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %p, i64 4096, i32 1, i1 false) #2
  26. ret void
  27. }