[llvm] f1c2331 - [MemCpyOpt] Add additional tests for earliest escape (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 27 07:58:48 PDT 2024
Author: Nikita Popov
Date: 2024-09-27T16:58:40+02:00
New Revision: f1c2331a646d28d5f528309b47cde9c13bc20542
URL: https://github.com/llvm/llvm-project/commit/f1c2331a646d28d5f528309b47cde9c13bc20542
DIFF: https://github.com/llvm/llvm-project/commit/f1c2331a646d28d5f528309b47cde9c13bc20542.diff
LOG: [MemCpyOpt] Add additional tests for earliest escape (NFC)
Added:
Modified:
llvm/test/Transforms/MemCpyOpt/memcpy.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/MemCpyOpt/memcpy.ll b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
index ba260752ce4b56..0114b9c2443582 100644
--- a/llvm/test/Transforms/MemCpyOpt/memcpy.ll
+++ b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
@@ -812,6 +812,94 @@ define void @memcpy_memory_none(ptr %p, ptr %p2, i64 %size) {
ret void
}
+declare void @do_something()
+declare void @capture(ptr)
+
+define void @memcpy_memcpy_escape_before(ptr noalias %P, ptr noalias %Q) {
+; CHECK-LABEL: @memcpy_memcpy_escape_before(
+; CHECK-NEXT: [[MEMTMP:%.*]] = alloca [32 x i8], align 16
+; CHECK-NEXT: call void @capture(ptr [[MEMTMP]])
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 16 [[MEMTMP]], ptr align 16 [[P:%.*]], i32 32, i1 false)
+; CHECK-NEXT: call void @do_something()
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 16 [[Q:%.*]], ptr align 16 [[MEMTMP]], i32 32, i1 false)
+; CHECK-NEXT: ret void
+;
+ %memtmp = alloca [32 x i8], align 16
+ call void @capture(ptr %memtmp)
+ call void @llvm.memcpy.p0.p0.i32(ptr align 16 %memtmp, ptr align 16 %P, i32 32, i1 false)
+ call void @do_something()
+ call void @llvm.memcpy.p0.p0.i32(ptr align 16 %Q, ptr align 16 %memtmp, i32 32, i1 false)
+ ret void
+}
+
+define void @memcpy_memcpy_escape_after1(ptr noalias %P, ptr noalias %Q) {
+; CHECK-LABEL: @memcpy_memcpy_escape_after1(
+; CHECK-NEXT: [[MEMTMP:%.*]] = alloca [32 x i8], align 16
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 16 [[MEMTMP]], ptr align 16 [[P:%.*]], i32 32, i1 false)
+; CHECK-NEXT: call void @do_something()
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 16 [[Q:%.*]], ptr align 16 [[MEMTMP]], i32 32, i1 false)
+; CHECK-NEXT: call void @capture(ptr [[MEMTMP]])
+; CHECK-NEXT: ret void
+;
+ %memtmp = alloca [32 x i8], align 16
+ call void @llvm.memcpy.p0.p0.i32(ptr align 16 %memtmp, ptr align 16 %P, i32 32, i1 false)
+ call void @do_something()
+ call void @llvm.memcpy.p0.p0.i32(ptr align 16 %Q, ptr align 16 %memtmp, i32 32, i1 false)
+ call void @capture(ptr %memtmp)
+ ret void
+}
+
+define void @memcpy_memcpy_escape_after2(ptr noalias %P, ptr noalias %Q) {
+; CHECK-LABEL: @memcpy_memcpy_escape_after2(
+; CHECK-NEXT: [[MEMTMP:%.*]] = alloca [32 x i8], align 16
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 16 [[MEMTMP]], ptr align 16 [[P:%.*]], i32 32, i1 false)
+; CHECK-NEXT: call void @do_something()
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 16 [[Q:%.*]], ptr align 16 [[MEMTMP]], i32 32, i1 false)
+; CHECK-NEXT: call void @capture(ptr [[P]])
+; CHECK-NEXT: ret void
+;
+ %memtmp = alloca [32 x i8], align 16
+ call void @llvm.memcpy.p0.p0.i32(ptr align 16 %memtmp, ptr align 16 %P, i32 32, i1 false)
+ call void @do_something()
+ call void @llvm.memcpy.p0.p0.i32(ptr align 16 %Q, ptr align 16 %memtmp, i32 32, i1 false)
+ call void @capture(ptr %P)
+ ret void
+}
+
+define void @memcpy_byval_escape_after(ptr noalias %P) {
+; CHECK-LABEL: @memcpy_byval_escape_after(
+; CHECK-NEXT: [[A:%.*]] = alloca [8 x i8], align 1
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[A]], ptr align 4 [[P:%.*]], i64 8, i1 false)
+; CHECK-NEXT: call void @do_something()
+; CHECK-NEXT: call void @test4a(ptr byval(i8) align 1 [[A]])
+; CHECK-NEXT: call void @capture(ptr [[P]])
+; CHECK-NEXT: ret void
+;
+ %A = alloca [8 x i8]
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %A, ptr align 4 %P, i64 8, i1 false)
+ call void @do_something()
+ call void @test4a(ptr align 1 byval(i8) %A)
+ call void @capture(ptr %P)
+ ret void
+}
+
+define void @memcpy_immut_escape_after(ptr align 4 noalias %val) {
+; CHECK-LABEL: @memcpy_immut_escape_after(
+; CHECK-NEXT: [[VAL1:%.*]] = alloca i8, align 4
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[VAL1]], ptr align 4 [[VAL:%.*]], i64 1, i1 false)
+; CHECK-NEXT: call void @do_something()
+; CHECK-NEXT: call void @f(ptr noalias nocapture readonly align 4 [[VAL1]])
+; CHECK-NEXT: call void @capture(ptr [[VAL]])
+; CHECK-NEXT: ret void
+;
+ %val1 = alloca i8, align 4
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %val1, ptr align 4 %val, i64 1, i1 false)
+ call void @do_something()
+ call void @f(ptr align 4 nocapture noalias readonly %val1)
+ call void @capture(ptr %val)
+ ret void
+}
+
!0 = !{!0}
!1 = !{!1, !0}
!2 = !{!1}
More information about the llvm-commits
mailing list