[llvm] 0b4f8c9 - (NFC)[MemCpyOpt] add a test to avoid crash for last memory use

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 04:23:53 PDT 2023


Author: khei4
Date: 2023-08-15T20:20:57+09:00
New Revision: 0b4f8c9fc40afaa300fe4248bb5fb70dfb2cf1b4

URL: https://github.com/llvm/llvm-project/commit/0b4f8c9fc40afaa300fe4248bb5fb70dfb2cf1b4
DIFF: https://github.com/llvm/llvm-project/commit/0b4f8c9fc40afaa300fe4248bb5fb70dfb2cf1b4.diff

LOG: (NFC)[MemCpyOpt] add a test to avoid crash for last memory use

Added: 
    

Modified: 
    llvm/test/Transforms/MemCpyOpt/stack-move.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/MemCpyOpt/stack-move.ll b/llvm/test/Transforms/MemCpyOpt/stack-move.ll
index 1dded1b1783d63..62f47a8b7c7692 100644
--- a/llvm/test/Transforms/MemCpyOpt/stack-move.ll
+++ b/llvm/test/Transforms/MemCpyOpt/stack-move.ll
@@ -412,6 +412,28 @@ define void @src_mod_dest_mod_after_copy() {
   ret void
 }
 
+; TODO: not crash on this.
+define void @avoid_memory_use_last_user_crash() {
+; CHECK-LABEL: define void @avoid_memory_use_last_user_crash() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [[STRUCT_FOO:%.*]], align 4
+; CHECK-NEXT:    [[DEST:%.*]] = alloca [[STRUCT_FOO]], align 4
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 12, ptr nocapture [[SRC]])
+; CHECK-NEXT:    store [[STRUCT_FOO]] { i32 10, i32 20, i32 30 }, ptr [[SRC]], align 4
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[DEST]], ptr align 4 [[SRC]], i64 12, i1 false)
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 12, ptr nocapture [[SRC]])
+; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[DEST]], align 4
+; CHECK-NEXT:    ret void
+;
+  %src = alloca %struct.Foo, align 4
+  %dest = alloca %struct.Foo, align 4
+  call void @llvm.lifetime.start.p0(i64 12, ptr nocapture %src)
+  store %struct.Foo { i32 10, i32 20, i32 30 }, ptr %src
+  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dest, ptr align 4 %src, i64 12, i1 false)
+  call void @llvm.lifetime.end.p0(i64 12, ptr nocapture %src)
+  %v = load i32, ptr %dest
+  ret void
+}
+
 ; TODO: if the last user is terminator, we won't insert lifetime.end.
 ; For multi-bb patch, we will insert it for next immediate post dominator block.
 define void @terminator_lastuse() personality i32 0 {


        


More information about the llvm-commits mailing list