1 ; RUN: opt -memcpyopt -S < %s | FileCheck %s
3 target datalayout = "e-i64:64-f80:128-n8:16:32:64"
4 target triple = "x86_64-unknown-linux-gnu"
6 %S = type { i8*, i8, i32 }
8 define void @copy(%S* %src, %S* %dst) {
11 ; CHECK: call void @llvm.memmove.p0i8.p0i8.i64
12 ; CHECK-NEXT: ret void
13 %1 = load %S, %S* %src
18 define void @noaliassrc(%S* noalias %src, %S* %dst) {
19 ; CHECK-LABEL: noaliassrc
21 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
22 ; CHECK-NEXT: ret void
23 %1 = load %S, %S* %src
28 define void @noaliasdst(%S* %src, %S* noalias %dst) {
29 ; CHECK-LABEL: noaliasdst
31 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
32 ; CHECK-NEXT: ret void
33 %1 = load %S, %S* %src
38 define void @destroysrc(%S* %src, %S* %dst) {
39 ; CHECK-LABEL: destroysrc
40 ; CHECK: load %S, %S* %src
41 ; CHECK: call void @llvm.memset.p0i8.i64
42 ; CHECK-NEXT: store %S %1, %S* %dst
43 ; CHECK-NEXT: ret void
44 %1 = load %S, %S* %src
45 store %S zeroinitializer, %S* %src
50 define void @destroynoaliassrc(%S* noalias %src, %S* %dst) {
51 ; CHECK-LABEL: destroynoaliassrc
53 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
54 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64
55 ; CHECK-NEXT: ret void
56 %1 = load %S, %S* %src
57 store %S zeroinitializer, %S* %src
62 define void @copyalias(%S* %src, %S* %dst) {
63 ; CHECK-LABEL: copyalias
64 ; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %S, %S* %src
66 ; CHECK: call void @llvm.memmove.p0i8.p0i8.i64
67 ; CHECK-NEXT: store %S [[LOAD]], %S* %dst
68 ; CHECK-NEXT: ret void
69 %1 = load %S, %S* %src
70 %2 = load %S, %S* %src
76 ; If the store address is computed in a complex manner, make
77 ; sure we lift the computation as well if needed and possible.
78 define void @addrproducer(%S* %src, %S* %dst) {
79 ; CHECK-LABEL: addrproducer(
80 ; CHECK-NEXT: %[[DSTCAST:[0-9]+]] = bitcast %S* %dst to i8*
81 ; CHECK-NEXT: %dst2 = getelementptr %S, %S* %dst, i64 1
82 ; CHECK-NEXT: %[[DST2CAST:[0-9]+]] = bitcast %S* %dst2 to i8*
83 ; CHECK-NEXT: %[[SRCCAST:[0-9]+]] = bitcast %S* %src to i8*
84 ; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i64(i8* align 8 %[[DST2CAST]], i8* align 8 %[[SRCCAST]], i64 16, i1 false)
85 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %[[DSTCAST]], i8 undef, i64 16, i1 false)
86 ; CHECK-NEXT: ret void
87 %1 = load %S, %S* %src
88 store %S undef, %S* %dst
89 %dst2 = getelementptr %S , %S* %dst, i64 1
90 store %S %1, %S* %dst2
94 define void @aliasaddrproducer(%S* %src, %S* %dst, i32* %dstidptr) {
95 ; CHECK-LABEL: aliasaddrproducer(
96 ; CHECK-NEXT: %[[SRC:[0-9]+]] = load %S, %S* %src
97 ; CHECK-NEXT: %[[DSTCAST:[0-9]+]] = bitcast %S* %dst to i8*
98 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %[[DSTCAST]], i8 undef, i64 16, i1 false)
99 ; CHECK-NEXT: %dstindex = load i32, i32* %dstidptr
100 ; CHECK-NEXT: %dst2 = getelementptr %S, %S* %dst, i32 %dstindex
101 ; CHECK-NEXT: store %S %[[SRC]], %S* %dst2
102 ; CHECK-NEXT: ret void
103 %1 = load %S, %S* %src
104 store %S undef, %S* %dst
105 %dstindex = load i32, i32* %dstidptr
106 %dst2 = getelementptr %S , %S* %dst, i32 %dstindex
107 store %S %1, %S* %dst2
111 define void @noaliasaddrproducer(%S* %src, %S* noalias %dst, i32* noalias %dstidptr) {
112 ; CHECK-LABEL: noaliasaddrproducer(
113 ; CHECK-NEXT: %[[SRCCAST:[0-9]+]] = bitcast %S* %src to i8*
114 ; CHECK-NEXT: %[[LOADED:[0-9]+]] = load i32, i32* %dstidptr
115 ; CHECK-NEXT: %dstindex = or i32 %[[LOADED]], 1
116 ; CHECK-NEXT: %dst2 = getelementptr %S, %S* %dst, i32 %dstindex
117 ; CHECK-NEXT: %[[DST2CAST:[0-9]+]] = bitcast %S* %dst2 to i8*
118 ; CHECK-NEXT: %[[SRCCAST2:[0-9]+]] = bitcast %S* %src to i8*
119 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[DST2CAST]], i8* align 8 %[[SRCCAST2]], i64 16, i1 false)
120 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %[[SRCCAST]], i8 undef, i64 16, i1 false)
121 ; CHECK-NEXT: ret void
122 %1 = load %S, %S* %src
123 store %S undef, %S* %src
124 %2 = load i32, i32* %dstidptr
125 %dstindex = or i32 %2, 1
126 %dst2 = getelementptr %S , %S* %dst, i32 %dstindex
127 store %S %1, %S* %dst2