~ubuntu-branches/ubuntu/quantal/llvm-3.1/quantal

« back to all changes in this revision

Viewing changes to test/Transforms/MemCpyOpt/memcpy.ll

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-03-29 19:09:51 UTC
  • Revision ID: package-import@ubuntu.com-20120329190951-aq83ivog4cg8bxun
Tags: upstream-3.1~svn153643
ImportĀ upstreamĀ versionĀ 3.1~svn153643

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; RUN: opt < %s -basicaa -memcpyopt -dse -S | FileCheck %s
 
2
 
 
3
target 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"
 
4
target triple = "i686-apple-darwin9"
 
5
 
 
6
%0 = type { x86_fp80, x86_fp80 }
 
7
%1 = type { i32, i32 }
 
8
 
 
9
define void @test1(%0* sret  %agg.result, x86_fp80 %z.0, x86_fp80 %z.1) nounwind  {
 
10
entry:
 
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: @test1
 
26
; CHECK: call void @ccoshl
 
27
; CHECK: call void @llvm.memcpy
 
28
; CHECK-NOT: llvm.memcpy
 
29
; CHECK: ret void
 
30
}
 
31
 
 
32
declare 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.
 
37
define 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: @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
 
 
54
define 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: @test3
 
62
; CHECK-NEXT: %agg.result1 = bitcast 
 
63
; CHECK-NEXT: call void @llvm.memcpy
 
64
; CHECK-NEXT: ret void
 
65
}
 
66
 
 
67
 
 
68
; PR8644
 
69
define 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* byval align 1 %a)
 
74
  ret void
 
75
; CHECK: @test4
 
76
; CHECK-NEXT: call void @test4a(
 
77
}
 
78
 
 
79
declare void @test4a(i8* byval align 1)
 
80
declare 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
 
 
86
declare void @test5a(%struct.S* byval align 16) nounwind ssp
 
87
 
 
88
 
 
89
; rdar://8713376 - This memcpy can't be eliminated.
 
90
define i32 @test5(i32 %x) nounwind ssp {
 
91
entry:
 
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* byval align 16 %y)
 
98
  ret i32 0
 
99
  ; CHECK: @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.
 
105
define 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: @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
 
 
117
define i32 @test7(%struct.p* nocapture byval align 8 %q) nounwind ssp {
 
118
entry:
 
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* byval align 8 %agg.tmp) nounwind
 
124
  ret i32 %call
 
125
; CHECK: @test7
 
126
; CHECK: call i32 @g(%struct.p* byval align 8 %q) nounwind
 
127
}
 
128
 
 
129
declare i32 @g(%struct.p* byval align 8)
 
130
 
 
131
declare 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
 
 
137
define 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
 
 
150
declare noalias i8* @malloc(i32)