• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -basicaa -memcpyopt -dse -S | FileCheck %s
2
3target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
4target triple = "i686-apple-darwin9"
5
6%0 = type { x86_fp80, x86_fp80 }
7%1 = type { i32, i32 }
8
9define void @test1(%0* sret  %agg.result, x86_fp80 %z.0, x86_fp80 %z.1) nounwind  {
10entry:
11  %tmp2 = alloca %0
12  %memtmp = alloca %0, align 16
13  %tmp5 = fsub x86_fp80 0xK80000000000000000000, %z.1
14  call void @ccoshl(%0* sret %memtmp, x86_fp80 %tmp5, x86_fp80 %z.0) nounwind
15  %tmp219 = bitcast %0* %tmp2 to i8*
16  %memtmp20 = bitcast %0* %memtmp to i8*
17  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp219, i8* %memtmp20, i32 32, i32 16, i1 false)
18  %agg.result21 = bitcast %0* %agg.result to i8*
19  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %agg.result21, i8* %tmp219, i32 32, i32 16, i1 false)
20  ret void
21
22; Check that one of the memcpy's are removed.
23;; FIXME: PR 8643 We should be able to eliminate the last memcpy here.
24
25; CHECK-LABEL: @test1(
26; CHECK: call void @ccoshl
27; CHECK: call void @llvm.memcpy
28; CHECK-NOT: llvm.memcpy
29; CHECK: ret void
30}
31
32declare void @ccoshl(%0* sret , x86_fp80, x86_fp80) nounwind
33
34
35; The intermediate alloca and one of the memcpy's should be eliminated, the
36; other should be related with a memmove.
37define void @test2(i8* %P, i8* %Q) nounwind  {
38  %memtmp = alloca %0, align 16
39  %R = bitcast %0* %memtmp to i8*
40  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %R, i8* %P, i32 32, i32 16, i1 false)
41  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %Q, i8* %R, i32 32, i32 16, i1 false)
42  ret void
43
44; CHECK-LABEL: @test2(
45; CHECK-NEXT: call void @llvm.memmove{{.*}}(i8* %Q, i8* %P
46; CHECK-NEXT: ret void
47}
48
49
50
51
52@x = external global %0
53
54define void @test3(%0* noalias sret %agg.result) nounwind  {
55  %x.0 = alloca %0
56  %x.01 = bitcast %0* %x.0 to i8*
57  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %x.01, i8* bitcast (%0* @x to i8*), i32 32, i32 16, i1 false)
58  %agg.result2 = bitcast %0* %agg.result to i8*
59  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %agg.result2, i8* %x.01, i32 32, i32 16, i1 false)
60  ret void
61; CHECK-LABEL: @test3(
62; CHECK-NEXT: %agg.result1 = bitcast
63; CHECK-NEXT: call void @llvm.memcpy
64; CHECK-NEXT: ret void
65}
66
67
68; PR8644
69define void @test4(i8 *%P) {
70  %A = alloca %1
71  %a = bitcast %1* %A to i8*
72  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %P, i64 8, i32 4, i1 false)
73  call void @test4a(i8* align 1 byval %a)
74  ret void
75; CHECK-LABEL: @test4(
76; CHECK-NEXT: call void @test4a(
77}
78
79declare void @test4a(i8* align 1 byval)
80declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
81
82%struct.S = type { i128, [4 x i8]}
83
84@sS = external global %struct.S, align 16
85
86declare void @test5a(%struct.S* align 16 byval) nounwind ssp
87
88
89; rdar://8713376 - This memcpy can't be eliminated.
90define i32 @test5(i32 %x) nounwind ssp {
91entry:
92  %y = alloca %struct.S, align 16
93  %tmp = bitcast %struct.S* %y to i8*
94  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp, i8* bitcast (%struct.S* @sS to i8*), i64 32, i32 16, i1 false)
95  %a = getelementptr %struct.S* %y, i64 0, i32 1, i64 0
96  store i8 4, i8* %a
97  call void @test5a(%struct.S* align 16 byval %y)
98  ret i32 0
99  ; CHECK-LABEL: @test5(
100  ; CHECK: store i8 4
101  ; CHECK: call void @test5a(%struct.S* byval align 16 %y)
102}
103
104;; Noop memcpy should be zapped.
105define void @test6(i8 *%P) {
106  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %P, i64 8, i32 4, i1 false)
107  ret void
108; CHECK-LABEL: @test6(
109; CHECK-NEXT: ret void
110}
111
112
113; PR9794 - Should forward memcpy into byval argument even though the memcpy
114; isn't itself 8 byte aligned.
115%struct.p = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
116
117define i32 @test7(%struct.p* nocapture align 8 byval %q) nounwind ssp {
118entry:
119  %agg.tmp = alloca %struct.p, align 4
120  %tmp = bitcast %struct.p* %agg.tmp to i8*
121  %tmp1 = bitcast %struct.p* %q to i8*
122  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp, i8* %tmp1, i64 48, i32 4, i1 false)
123  %call = call i32 @g(%struct.p* align 8 byval %agg.tmp) nounwind
124  ret i32 %call
125; CHECK-LABEL: @test7(
126; CHECK: call i32 @g(%struct.p* byval align 8 %q) [[NUW:#[0-9]+]]
127}
128
129declare i32 @g(%struct.p* align 8 byval)
130
131declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
132
133; PR11142 - When looking for a memcpy-memcpy dependency, don't get stuck on
134; instructions between the memcpy's that only affect the destination pointer.
135@test8.str = internal constant [7 x i8] c"ABCDEF\00"
136
137define void @test8() {
138; CHECK: test8
139; CHECK-NOT: memcpy
140  %A = tail call i8* @malloc(i32 10)
141  %B = getelementptr inbounds i8* %A, i64 2
142  tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %B, i8* getelementptr inbounds ([7 x i8]* @test8.str, i64 0, i64 0), i32 7, i32 1, i1 false)
143  %C = tail call i8* @malloc(i32 10)
144  %D = getelementptr inbounds i8* %C, i64 2
145  tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %D, i8* %B, i32 7, i32 1, i1 false)
146  ret void
147; CHECK: ret void
148}
149
150declare noalias i8* @malloc(i32)
151
152; rdar://11341081
153%struct.big = type { [50 x i32] }
154
155define void @test9() nounwind ssp uwtable {
156entry:
157; CHECK: test9
158; CHECK: f1
159; CHECK-NOT: memcpy
160; CHECK: f2
161  %b = alloca %struct.big, align 4
162  %tmp = alloca %struct.big, align 4
163  call void @f1(%struct.big* sret %tmp)
164  %0 = bitcast %struct.big* %b to i8*
165  %1 = bitcast %struct.big* %tmp to i8*
166  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %1, i64 200, i32 4, i1 false)
167  call void @f2(%struct.big* %b)
168  ret void
169}
170
171; rdar://14073661.
172; Test10 triggered assertion when the compiler try to get the size of the
173; opaque type of *x, where the x is the formal argument with attribute 'sret'.
174
175%opaque = type opaque
176declare void @foo(i32* noalias nocapture)
177
178define void @test10(%opaque* noalias nocapture sret %x, i32 %y) {
179  %a = alloca i32, align 4
180  store i32 %y, i32* %a
181  call void @foo(i32* noalias nocapture %a)
182  %c = load i32* %a
183  %d = bitcast %opaque* %x to i32*
184  store i32 %c, i32* %d
185  ret void
186}
187
188declare void @f1(%struct.big* sret)
189declare void @f2(%struct.big*)
190
191; CHECK: attributes [[NUW]] = { nounwind }
192; CHECK: attributes #1 = { nounwind ssp }
193; CHECK: attributes #2 = { nounwind ssp uwtable }
194