1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=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(ptr 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: store i8 98, ptr [[FOOBIE:%.*]], align 4
14 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], ptr [[FOOBIE]], i64 0, i32 1, i64 0
15 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT_FOO]], ptr [[FOOBIE]], i64 0, i32 2
16 ; CHECK-NEXT: store i32 20, ptr [[TMP2]], align 4
17 ; CHECK-NEXT: ret i32 undef
19 %bletch.sroa.1 = alloca [7 x i8], align 1
20 store i8 98, ptr %foobie, align 4
21 %1 = getelementptr inbounds %struct.foo, ptr %foobie, i64 0, i32 1, i64 0
22 call void @llvm.memcpy.p0.p0.i64(ptr %1, ptr %bletch.sroa.1, i64 7, i1 false)
23 %2 = getelementptr inbounds %struct.foo, ptr %foobie, i64 0, i32 2
24 store i32 20, ptr %2, align 4
28 ; Check that the memcpy is removed.
29 define void @test2(ptr sret(i8) noalias nocapture %out, ptr %in) nounwind noinline ssp uwtable {
30 ; CHECK-LABEL: @test2(
31 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr [[IN:%.*]])
32 ; CHECK-NEXT: ret void
34 call void @llvm.lifetime.start.p0(i64 8, ptr %in)
35 call void @llvm.memcpy.p0.p0.i64(ptr %out, ptr %in, i64 8, i1 false)
39 ; Check that the memcpy is not removed.
40 define void @test3(ptr sret(i8) noalias nocapture %out, ptr %in) nounwind noinline ssp uwtable {
41 ; CHECK-LABEL: @test3(
42 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[IN:%.*]])
43 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[OUT:%.*]], ptr [[IN]], i64 8, i1 false)
44 ; CHECK-NEXT: ret void
46 call void @llvm.lifetime.start.p0(i64 4, ptr %in)
47 call void @llvm.memcpy.p0.p0.i64(ptr %out, ptr %in, i64 8, i1 false)
51 ; Check that the memcpy is not removed.
52 define void @test_lifetime_may_alias(ptr %lifetime, ptr %src, ptr %dst) {
53 ; CHECK-LABEL: @test_lifetime_may_alias(
54 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr [[LIFETIME:%.*]])
55 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[DST:%.*]], ptr [[SRC:%.*]], i64 8, i1 false)
56 ; CHECK-NEXT: ret void
58 call void @llvm.lifetime.start.p0(i64 8, ptr %lifetime)
59 call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 8, i1 false)
63 ; lifetime.start on full alloca size, copy in range.
64 define void @test_lifetime_partial_alias_1(ptr noalias %dst) {
65 ; CHECK-LABEL: @test_lifetime_partial_alias_1(
66 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
67 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 16, ptr [[A]])
68 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 8
69 ; CHECK-NEXT: ret void
72 call void @llvm.lifetime.start.p0(i64 16, ptr %a)
73 %gep = getelementptr i8, ptr %a, i64 8
74 call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %gep, i64 8, i1 false)
78 ; lifetime.start on full alloca size, copy out of range.
79 define void @test_lifetime_partial_alias_2(ptr noalias %dst) {
80 ; CHECK-LABEL: @test_lifetime_partial_alias_2(
81 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
82 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 16, ptr [[A]])
83 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 8
84 ; CHECK-NEXT: ret void
87 call void @llvm.lifetime.start.p0(i64 16, ptr %a)
88 %gep = getelementptr i8, ptr %a, i64 8
89 call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %gep, i64 16, i1 false)
93 ; lifetime.start on part of alloca, copy in range.
94 define void @test_lifetime_partial_alias_3(ptr noalias %dst) {
95 ; CHECK-LABEL: @test_lifetime_partial_alias_3(
96 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
97 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 12, ptr [[A]])
98 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 8
99 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[DST:%.*]], ptr [[GEP]], i64 4, i1 false)
100 ; CHECK-NEXT: ret void
102 %a = alloca [16 x i8]
103 call void @llvm.lifetime.start.p0(i64 12, ptr %a)
104 %gep = getelementptr i8, ptr %a, i64 8
105 call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %gep, i64 4, i1 false)
109 ; lifetime.start on part of alloca, copy out of range.
110 define void @test_lifetime_partial_alias_4(ptr noalias %dst) {
111 ; CHECK-LABEL: @test_lifetime_partial_alias_4(
112 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
113 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 12, ptr [[A]])
114 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 8
115 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[DST:%.*]], ptr [[GEP]], i64 8, i1 false)
116 ; CHECK-NEXT: ret void
118 %a = alloca [16 x i8]
119 call void @llvm.lifetime.start.p0(i64 12, ptr %a)
120 %gep = getelementptr i8, ptr %a, i64 8
121 call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %gep, i64 8, i1 false)
125 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
127 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind