1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=core2 | FileCheck %s -check-prefix=LINUX
3 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=core2 | FileCheck %s -check-prefix=DARWIN
5 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
6 declare void @llvm.memcpy.p256i8.p256i8.i64(i8 addrspace(256)* nocapture, i8 addrspace(256)* nocapture, i64, i1) nounwind
9 ; Variable memcpy's should lower to calls.
10 define i8* @test1(i8* %a, i8* %b, i64 %n) nounwind {
12 ; LINUX: # %bb.0: # %entry
13 ; LINUX-NEXT: jmp memcpy # TAILCALL
15 ; DARWIN-LABEL: test1:
16 ; DARWIN: ## %bb.0: ## %entry
17 ; DARWIN-NEXT: jmp _memcpy ## TAILCALL
19 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 %n, i1 0 )
23 ; Variable memcpy's should lower to calls.
24 define i8* @test2(i64* %a, i64* %b, i64 %n) nounwind {
26 ; LINUX: # %bb.0: # %entry
27 ; LINUX-NEXT: jmp memcpy # TAILCALL
29 ; DARWIN-LABEL: test2:
30 ; DARWIN: ## %bb.0: ## %entry
31 ; DARWIN-NEXT: jmp _memcpy ## TAILCALL
33 %tmp14 = bitcast i64* %a to i8*
34 %tmp25 = bitcast i64* %b to i8*
35 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %tmp14, i8* align 8 %tmp25, i64 %n, i1 0 )
39 ; Large constant memcpy's should lower to a call when optimizing for size.
42 ; On the other hand, Darwin's definition of -Os is optimizing for size without
43 ; hurting performance so it should just ignore optsize when expanding memcpy.
45 define void @test3(i8* nocapture %A, i8* nocapture %B) nounwind optsize noredzone {
47 ; LINUX: # %bb.0: # %entry
48 ; LINUX-NEXT: movl $64, %edx
49 ; LINUX-NEXT: jmp memcpy # TAILCALL
51 ; DARWIN-LABEL: test3:
52 ; DARWIN: ## %bb.0: ## %entry
53 ; DARWIN-NEXT: movq 56(%rsi), %rax
54 ; DARWIN-NEXT: movq %rax, 56(%rdi)
55 ; DARWIN-NEXT: movq 48(%rsi), %rax
56 ; DARWIN-NEXT: movq %rax, 48(%rdi)
57 ; DARWIN-NEXT: movq 40(%rsi), %rax
58 ; DARWIN-NEXT: movq %rax, 40(%rdi)
59 ; DARWIN-NEXT: movq 32(%rsi), %rax
60 ; DARWIN-NEXT: movq %rax, 32(%rdi)
61 ; DARWIN-NEXT: movq 24(%rsi), %rax
62 ; DARWIN-NEXT: movq %rax, 24(%rdi)
63 ; DARWIN-NEXT: movq 16(%rsi), %rax
64 ; DARWIN-NEXT: movq %rax, 16(%rdi)
65 ; DARWIN-NEXT: movq (%rsi), %rax
66 ; DARWIN-NEXT: movq 8(%rsi), %rcx
67 ; DARWIN-NEXT: movq %rcx, 8(%rdi)
68 ; DARWIN-NEXT: movq %rax, (%rdi)
71 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i1 false)
75 define void @test3_minsize(i8* nocapture %A, i8* nocapture %B) nounwind minsize noredzone {
76 ; LINUX-LABEL: test3_minsize:
78 ; LINUX-NEXT: pushq $64
79 ; LINUX-NEXT: popq %rdx
80 ; LINUX-NEXT: jmp memcpy # TAILCALL
82 ; DARWIN-LABEL: test3_minsize:
84 ; DARWIN-NEXT: pushq $64
85 ; DARWIN-NEXT: popq %rdx
86 ; DARWIN-NEXT: jmp _memcpy ## TAILCALL
87 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i1 false)
91 define void @test3_minsize_optsize(i8* nocapture %A, i8* nocapture %B) nounwind optsize minsize noredzone {
92 ; LINUX-LABEL: test3_minsize_optsize:
94 ; LINUX-NEXT: pushq $64
95 ; LINUX-NEXT: popq %rdx
96 ; LINUX-NEXT: jmp memcpy # TAILCALL
98 ; DARWIN-LABEL: test3_minsize_optsize:
100 ; DARWIN-NEXT: pushq $64
101 ; DARWIN-NEXT: popq %rdx
102 ; DARWIN-NEXT: jmp _memcpy ## TAILCALL
103 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i1 false)
107 ; Large constant memcpy's should be inlined when not optimizing for size.
108 define void @test4(i8* nocapture %A, i8* nocapture %B) nounwind noredzone {
109 ; LINUX-LABEL: test4:
110 ; LINUX: # %bb.0: # %entry
111 ; LINUX-NEXT: movq 56(%rsi), %rax
112 ; LINUX-NEXT: movq %rax, 56(%rdi)
113 ; LINUX-NEXT: movq 48(%rsi), %rax
114 ; LINUX-NEXT: movq %rax, 48(%rdi)
115 ; LINUX-NEXT: movq 40(%rsi), %rax
116 ; LINUX-NEXT: movq %rax, 40(%rdi)
117 ; LINUX-NEXT: movq 32(%rsi), %rax
118 ; LINUX-NEXT: movq %rax, 32(%rdi)
119 ; LINUX-NEXT: movq 24(%rsi), %rax
120 ; LINUX-NEXT: movq %rax, 24(%rdi)
121 ; LINUX-NEXT: movq 16(%rsi), %rax
122 ; LINUX-NEXT: movq %rax, 16(%rdi)
123 ; LINUX-NEXT: movq (%rsi), %rax
124 ; LINUX-NEXT: movq 8(%rsi), %rcx
125 ; LINUX-NEXT: movq %rcx, 8(%rdi)
126 ; LINUX-NEXT: movq %rax, (%rdi)
129 ; DARWIN-LABEL: test4:
130 ; DARWIN: ## %bb.0: ## %entry
131 ; DARWIN-NEXT: movq 56(%rsi), %rax
132 ; DARWIN-NEXT: movq %rax, 56(%rdi)
133 ; DARWIN-NEXT: movq 48(%rsi), %rax
134 ; DARWIN-NEXT: movq %rax, 48(%rdi)
135 ; DARWIN-NEXT: movq 40(%rsi), %rax
136 ; DARWIN-NEXT: movq %rax, 40(%rdi)
137 ; DARWIN-NEXT: movq 32(%rsi), %rax
138 ; DARWIN-NEXT: movq %rax, 32(%rdi)
139 ; DARWIN-NEXT: movq 24(%rsi), %rax
140 ; DARWIN-NEXT: movq %rax, 24(%rdi)
141 ; DARWIN-NEXT: movq 16(%rsi), %rax
142 ; DARWIN-NEXT: movq %rax, 16(%rdi)
143 ; DARWIN-NEXT: movq (%rsi), %rax
144 ; DARWIN-NEXT: movq 8(%rsi), %rcx
145 ; DARWIN-NEXT: movq %rcx, 8(%rdi)
146 ; DARWIN-NEXT: movq %rax, (%rdi)
149 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i1 false)
154 @.str = private unnamed_addr constant [30 x i8] c"\00aaaaaaaaaaaaaaaaaaaaaaaaaaaa\00", align 1
156 define void @test5(i8* nocapture %C) nounwind uwtable ssp {
157 ; LINUX-LABEL: test5:
158 ; LINUX: # %bb.0: # %entry
159 ; LINUX-NEXT: movabsq $7016996765293437281, %rax # imm = 0x6161616161616161
160 ; LINUX-NEXT: movq %rax, 8(%rdi)
161 ; LINUX-NEXT: movabsq $7016996765293437184, %rax # imm = 0x6161616161616100
162 ; LINUX-NEXT: movq %rax, (%rdi)
165 ; DARWIN-LABEL: test5:
166 ; DARWIN: ## %bb.0: ## %entry
167 ; DARWIN-NEXT: movabsq $7016996765293437281, %rax ## imm = 0x6161616161616161
168 ; DARWIN-NEXT: movq %rax, 8(%rdi)
169 ; DARWIN-NEXT: movabsq $7016996765293437184, %rax ## imm = 0x6161616161616100
170 ; DARWIN-NEXT: movq %rax, (%rdi)
173 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %C, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 16, i1 false)
179 @.str2 = private unnamed_addr constant [2 x i8] c"x\00", align 1
181 define void @test6() nounwind uwtable {
182 ; LINUX-LABEL: test6:
183 ; LINUX: # %bb.0: # %entry
184 ; LINUX-NEXT: movw $0, 8
185 ; LINUX-NEXT: movq $120, 0
188 ; DARWIN-LABEL: test6:
189 ; DARWIN: ## %bb.0: ## %entry
190 ; DARWIN-NEXT: movw $0, 8
191 ; DARWIN-NEXT: movq $120, 0
194 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str2, i64 0, i64 0), i64 10, i1 false)
198 define void @PR15348(i8* %a, i8* %b) {
199 ; Ensure that alignment of '0' in an @llvm.memcpy intrinsic results in
200 ; unaligned loads and stores.
201 ; LINUX-LABEL: PR15348:
203 ; LINUX-NEXT: movb 16(%rsi), %al
204 ; LINUX-NEXT: movb %al, 16(%rdi)
205 ; LINUX-NEXT: movq (%rsi), %rax
206 ; LINUX-NEXT: movq 8(%rsi), %rcx
207 ; LINUX-NEXT: movq %rcx, 8(%rdi)
208 ; LINUX-NEXT: movq %rax, (%rdi)
211 ; DARWIN-LABEL: PR15348:
213 ; DARWIN-NEXT: movb 16(%rsi), %al
214 ; DARWIN-NEXT: movb %al, 16(%rdi)
215 ; DARWIN-NEXT: movq (%rsi), %rax
216 ; DARWIN-NEXT: movq 8(%rsi), %rcx
217 ; DARWIN-NEXT: movq %rcx, 8(%rdi)
218 ; DARWIN-NEXT: movq %rax, (%rdi)
220 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 17, i1 false)
224 ; Memcpys from / to address space 256 should be lowered to appropriate loads /
225 ; stores if small enough.
226 define void @addrspace256(i8 addrspace(256)* %a, i8 addrspace(256)* %b) nounwind {
227 ; LINUX-LABEL: addrspace256:
229 ; LINUX-NEXT: movq %gs:(%rsi), %rax
230 ; LINUX-NEXT: movq %gs:8(%rsi), %rcx
231 ; LINUX-NEXT: movq %rcx, %gs:8(%rdi)
232 ; LINUX-NEXT: movq %rax, %gs:(%rdi)
235 ; DARWIN-LABEL: addrspace256:
237 ; DARWIN-NEXT: movq %gs:(%rsi), %rax
238 ; DARWIN-NEXT: movq %gs:8(%rsi), %rcx
239 ; DARWIN-NEXT: movq %rcx, %gs:8(%rdi)
240 ; DARWIN-NEXT: movq %rax, %gs:(%rdi)
242 tail call void @llvm.memcpy.p256i8.p256i8.i64(i8 addrspace(256)* align 8 %a, i8 addrspace(256)* align 8 %b, i64 16, i1 false)