1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -aa-pipeline=basic-aa -passes='require<memoryssa>,memcpyopt' -verify-memoryssa -S %s | FileCheck %s
6 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-apple-macosx10.15.0"
9 %t = type <{ i8*, [4 x i8], i8*, i8*, i32, [8192 x i8] }>
12 define i32 @test1(%t* %ptr) {
13 ; CHECK-LABEL: @test1(
14 ; CHECK-NEXT: invoke.cont6:
15 ; CHECK-NEXT: [[P_1:%.*]] = getelementptr inbounds [[T:%.*]], %t* [[PTR:%.*]], i64 0, i32 0
16 ; CHECK-NEXT: [[P_1_C:%.*]] = bitcast i8** [[P_1]] to i8*
17 ; CHECK-NEXT: [[P_2:%.*]] = getelementptr inbounds [[T]], %t* [[PTR]], i64 0, i32 4
18 ; CHECK-NEXT: [[P_3:%.*]] = getelementptr inbounds [[T]], %t* [[PTR]], i64 0, i32 5, i64 0
19 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast i8** [[P_1]] to i8*
20 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP0]], i8 0, i64 20, i1 false)
21 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[P_2]] to i8*
22 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP1]], i8 0, i64 8195, i1 false)
23 ; CHECK-NEXT: ret i32 0
26 %p.1 = getelementptr inbounds %t, %t* %ptr, i64 0, i32 0
27 %p.1.c = bitcast i8** %p.1 to i8*
28 call void @llvm.memset.p0i8.i64(i8* %p.1.c, i8 0, i64 20, i1 false)
29 store i8* null, i8** %p.1, align 8
30 %p.2 = getelementptr inbounds %t, %t* %ptr, i64 0, i32 4
31 store i32 0, i32* %p.2, align 8
32 %p.3 = getelementptr inbounds %t, %t* %ptr, i64 0, i32 5, i64 0
33 call void @llvm.memset.p0i8.i64(i8* %p.3, i8 0, i64 8191, i1 false)
37 declare i8* @get_ptr()
39 define void @test2(i8* noalias %in) {
40 ; CHECK-LABEL: @test2(
42 ; CHECK-NEXT: [[CALL_I1_I:%.*]] = tail call i8* @get_ptr()
43 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[CALL_I1_I]], i8* [[IN:%.*]], i64 10, i1 false)
44 ; CHECK-NEXT: ret void
47 %call.i1.i = tail call i8* @get_ptr()
48 tail call void @llvm.memset.p0i8.i64(i8* %call.i1.i, i8 0, i64 10, i1 false)
49 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %call.i1.i, i8* %in, i64 10, i1 false)
53 declare i8* @malloc(i64)
55 define i32 @test3(i8* noalias %in) {
56 ; CHECK-LABEL: @test3(
57 ; CHECK-NEXT: [[CALL_I_I_I:%.*]] = tail call i8* @malloc(i64 20)
58 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[CALL_I_I_I]], i8* [[IN:%.*]], i64 20, i1 false)
59 ; CHECK-NEXT: ret i32 10
61 %call.i.i.i = tail call i8* @malloc(i64 20)
62 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %call.i.i.i, i8* %in, i64 20, i1 false)
66 define void @test4(i32 %n, i8* noalias %ptr.0, i8* noalias %ptr.1, i32* %ptr.2) unnamed_addr {
67 ; CHECK-LABEL: @test4(
68 ; CHECK-NEXT: [[ELEM_I:%.*]] = getelementptr i8, i8* [[PTR_0:%.*]], i64 8
69 ; CHECK-NEXT: store i32 [[N:%.*]], i32* [[PTR_2:%.*]], align 8
70 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[ELEM_I]], i8* [[PTR_1:%.*]], i64 10, i1 false)
71 ; CHECK-NEXT: ret void
73 %elem.i = getelementptr i8, i8* %ptr.0, i64 8
74 call void @llvm.memset.p0i8.i64(i8* %elem.i, i8 0, i64 10, i1 false)
75 store i32 %n, i32* %ptr.2, align 8
76 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %elem.i, i8* %ptr.1, i64 10, i1 false)
80 declare void @decompose(%t* nocapture)
82 define void @test5(i32* %ptr) {
83 ; CHECK-LABEL: @test5(
85 ; CHECK-NEXT: [[EARLY_DATA:%.*]] = alloca [128 x i8], align 8
86 ; CHECK-NEXT: [[TMP:%.*]] = alloca [[T:%.*]], align 8
87 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast [128 x i8]* [[EARLY_DATA]] to i8*
88 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast %t* [[TMP]] to i8*
89 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 32, i8* [[TMP0]])
90 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[PTR:%.*]], align 8
91 ; CHECK-NEXT: call fastcc void @decompose(%t* [[TMP]])
92 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP0]], i8* [[TMP1]], i64 32, i1 false)
93 ; CHECK-NEXT: ret void
96 %early_data = alloca [128 x i8], align 8
97 %tmp = alloca %t, align 8
98 %0 = bitcast [128 x i8]* %early_data to i8*
99 %1 = bitcast %t* %tmp to i8*
100 call void @llvm.lifetime.start.p0i8(i64 32, i8* %0)
101 %2 = load i32, i32* %ptr, align 8
102 call fastcc void @decompose(%t* %tmp)
103 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %1, i64 32, i1 false)
107 define i8 @test6(i8* %ptr, i8* noalias %ptr.1) {
108 ; CHECK-LABEL: @test6(
110 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 24, i8* [[PTR:%.*]])
111 ; CHECK-NEXT: [[TMP0:%.*]] = load i8, i8* [[PTR]], align 8
112 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[PTR]], i8* [[PTR_1:%.*]], i64 24, i1 false)
113 ; CHECK-NEXT: ret i8 [[TMP0]]
116 call void @llvm.lifetime.start.p0i8(i64 24, i8* %ptr)
117 %0 = load i8, i8* %ptr, align 8
118 call void @llvm.memmove.p0i8.p0i8.i64(i8* %ptr, i8* %ptr.1, i64 24, i1 false)
122 define void @test7([4 x i32]* %ptr) {
123 ; CHECK-LABEL: @test7(
125 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR:%.*]], i64 0, i32 0
126 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR]], i64 0, i32 1
127 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR]], i64 0, i32 2
128 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR]], i64 0, i32 3
129 ; CHECK-NEXT: [[TMP4:%.*]] = bitcast i32* [[TMP0]] to i8*
130 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[TMP4]], i8 0, i64 16, i1 false)
131 ; CHECK-NEXT: call void @clobber()
132 ; CHECK-NEXT: ret void
135 %0 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 0
136 store i32 0, i32* %0, align 1
137 %1 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 1
138 store i32 0, i32* %1, align 1
139 %2 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 2
140 store i32 0, i32* %2, align 1
141 %3 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 3
142 store i32 0, i32* %3, align 1
147 define void @test8(%t* noalias %src, %t* %dst) {
148 ; CHECK-LABEL: @test8(
149 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast %t* [[SRC:%.*]] to i8*
150 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast %t* [[DST:%.*]] to i8*
151 ; CHECK-NEXT: [[TMP3:%.*]] = bitcast %t* [[SRC]] to i8*
152 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[TMP2]], i8* align 1 [[TMP3]], i64 8224, i1 false)
153 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[TMP1]], i8 0, i64 8224, i1 false)
154 ; CHECK-NEXT: ret void
156 %1 = load %t, %t* %src
157 store %t zeroinitializer, %t* %src
158 store %t %1, %t* %dst
162 declare void @clobber()
164 ; Function Attrs: argmemonly nounwind willreturn
165 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
167 ; Function Attrs: argmemonly nounwind willreturn
168 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #0
170 ; Function Attrs: argmemonly nounwind willreturn writeonly
171 declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #1
173 ; Function Attrs: argmemonly nounwind willreturn
174 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1 immarg) #0
176 attributes #0 = { argmemonly nounwind willreturn }
177 attributes #1 = { argmemonly nounwind willreturn writeonly }