1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -basic-aa -memcpyopt -S -verify-memoryssa | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx10.8.0"
7 %struct.foo = type { i8, [7 x i8], i32 }
9 ; Check that the memcpy is removed.
10 define i32 @test1(%struct.foo* nocapture %foobie) nounwind noinline ssp uwtable {
11 ; CHECK-LABEL: @test1(
12 ; CHECK-NEXT: [[BLETCH_SROA_1:%.*]] = alloca [7 x i8], align 1
13 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], %struct.foo* [[FOOBIE:%.*]], i64 0, i32 0
14 ; CHECK-NEXT: store i8 98, i8* [[TMP1]], align 4
15 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[FOOBIE]], i64 0, i32 1, i64 0
16 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [7 x i8], [7 x i8]* [[BLETCH_SROA_1]], i64 0, i64 0
17 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[FOOBIE]], i64 0, i32 2
18 ; CHECK-NEXT: store i32 20, i32* [[TMP4]], align 4
19 ; CHECK-NEXT: ret i32 undef
21 %bletch.sroa.1 = alloca [7 x i8], align 1
22 %1 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 0
23 store i8 98, i8* %1, align 4
24 %2 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 1, i64 0
25 %3 = getelementptr inbounds [7 x i8], [7 x i8]* %bletch.sroa.1, i64 0, i64 0
26 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 7, i1 false)
27 %4 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 2
28 store i32 20, i32* %4, align 4
32 ; Check that the memcpy is removed.
33 define void @test2(i8* sret(i8) noalias nocapture %out, i8* %in) nounwind noinline ssp uwtable {
34 ; CHECK-LABEL: @test2(
35 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[IN:%.*]])
36 ; CHECK-NEXT: ret void
38 call void @llvm.lifetime.start.p0i8(i64 8, i8* %in)
39 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %out, i8* %in, i64 8, i1 false)
43 ; Check that the memcpy is not removed.
44 define void @test3(i8* sret(i8) noalias nocapture %out, i8* %in) nounwind noinline ssp uwtable {
45 ; CHECK-LABEL: @test3(
46 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* [[IN:%.*]])
47 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[OUT:%.*]], i8* [[IN]], i64 8, i1 false)
48 ; CHECK-NEXT: ret void
50 call void @llvm.lifetime.start.p0i8(i64 4, i8* %in)
51 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %out, i8* %in, i64 8, i1 false)
55 ; Check that the memcpy is not removed.
56 define void @test_lifetime_may_alias(i8* %lifetime, i8* %src, i8* %dst) {
57 ; CHECK-LABEL: @test_lifetime_may_alias(
58 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[LIFETIME:%.*]])
59 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST:%.*]], i8* [[SRC:%.*]], i64 8, i1 false)
60 ; CHECK-NEXT: ret void
62 call void @llvm.lifetime.start.p0i8(i64 8, i8* %lifetime)
63 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 8, i1 false)
67 ; lifetime.start on full alloca size, copy in range.
68 define void @test_lifetime_partial_alias_1(i8* noalias %dst) {
69 ; CHECK-LABEL: @test_lifetime_partial_alias_1(
70 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
71 ; CHECK-NEXT: [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
72 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 16, i8* [[A_I8]])
73 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
74 ; CHECK-NEXT: ret void
77 %a.i8 = bitcast [16 x i8]* %a to i8*
78 call void @llvm.lifetime.start.p0i8(i64 16, i8* %a.i8)
79 %gep = getelementptr i8, i8* %a.i8, i64 8
80 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 8, i1 false)
84 ; lifetime.start on full alloca size, copy out of range.
85 define void @test_lifetime_partial_alias_2(i8* noalias %dst) {
86 ; CHECK-LABEL: @test_lifetime_partial_alias_2(
87 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
88 ; CHECK-NEXT: [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
89 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 16, i8* [[A_I8]])
90 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
91 ; CHECK-NEXT: ret void
94 %a.i8 = bitcast [16 x i8]* %a to i8*
95 call void @llvm.lifetime.start.p0i8(i64 16, i8* %a.i8)
96 %gep = getelementptr i8, i8* %a.i8, i64 8
97 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 16, i1 false)
101 ; lifetime.start on part of alloca, copy in range.
102 define void @test_lifetime_partial_alias_3(i8* noalias %dst) {
103 ; CHECK-LABEL: @test_lifetime_partial_alias_3(
104 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
105 ; CHECK-NEXT: [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
106 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 12, i8* [[A_I8]])
107 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
108 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST:%.*]], i8* [[GEP]], i64 4, i1 false)
109 ; CHECK-NEXT: ret void
111 %a = alloca [16 x i8]
112 %a.i8 = bitcast [16 x i8]* %a to i8*
113 call void @llvm.lifetime.start.p0i8(i64 12, i8* %a.i8)
114 %gep = getelementptr i8, i8* %a.i8, i64 8
115 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 4, i1 false)
119 ; lifetime.start on part of alloca, copy out of range.
120 define void @test_lifetime_partial_alias_4(i8* noalias %dst) {
121 ; CHECK-LABEL: @test_lifetime_partial_alias_4(
122 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
123 ; CHECK-NEXT: [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
124 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 12, i8* [[A_I8]])
125 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
126 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST:%.*]], i8* [[GEP]], i64 8, i1 false)
127 ; CHECK-NEXT: ret void
129 %a = alloca [16 x i8]
130 %a.i8 = bitcast [16 x i8]* %a to i8*
131 call void @llvm.lifetime.start.p0i8(i64 12, i8* %a.i8)
132 %gep = getelementptr i8, i8* %a.i8, i64 8
133 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 8, i1 false)
137 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
139 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) nounwind