1; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=core2 | FileCheck %s -check-prefix=LINUX 2; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=core2 | FileCheck %s -check-prefix=DARWIN 3 4declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind 5declare void @llvm.memcpy.p256i8.p256i8.i64(i8 addrspace(256)* nocapture, i8 addrspace(256)* nocapture, i64, i32, i1) nounwind 6 7 8; Variable memcpy's should lower to calls. 9define i8* @test1(i8* %a, i8* %b, i64 %n) nounwind { 10entry: 11 tail call void @llvm.memcpy.p0i8.p0i8.i64( i8* %a, i8* %b, i64 %n, i32 1, i1 0 ) 12 ret i8* %a 13 14; LINUX-LABEL: test1: 15; LINUX: memcpy 16} 17 18; Variable memcpy's should lower to calls. 19define i8* @test2(i64* %a, i64* %b, i64 %n) nounwind { 20entry: 21 %tmp14 = bitcast i64* %a to i8* 22 %tmp25 = bitcast i64* %b to i8* 23 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp14, i8* %tmp25, i64 %n, i32 8, i1 0 ) 24 ret i8* %tmp14 25 26; LINUX-LABEL: test2: 27; LINUX: memcpy 28} 29 30; Large constant memcpy's should lower to a call when optimizing for size. 31; PR6623 32 33; On the other hand, Darwin's definition of -Os is optimizing for size without 34; hurting performance so it should just ignore optsize when expanding memcpy. 35; rdar://8821501 36define void @test3(i8* nocapture %A, i8* nocapture %B) nounwind optsize noredzone { 37entry: 38 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i32 1, i1 false) 39 ret void 40; LINUX-LABEL: test3: 41; LINUX: memcpy 42 43; DARWIN-LABEL: test3: 44; DARWIN-NOT: memcpy 45; DARWIN: movq 46; DARWIN: movq 47; DARWIN: movq 48; DARWIN: movq 49; DARWIN: movq 50; DARWIN: movq 51; DARWIN: movq 52; DARWIN: movq 53; DARWIN: movq 54; DARWIN: movq 55; DARWIN: movq 56; DARWIN: movq 57; DARWIN: movq 58; DARWIN: movq 59; DARWIN: movq 60; DARWIN: movq 61} 62 63define void @test3_minsize(i8* nocapture %A, i8* nocapture %B) nounwind minsize noredzone { 64 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i32 1, i1 false) 65 ret void 66; LINUX-LABEL: test3_minsize: 67; LINUX: memcpy 68 69; DARWIN-LABEL: test3_minsize: 70; DARWIN: memcpy 71} 72 73define void @test3_minsize_optsize(i8* nocapture %A, i8* nocapture %B) nounwind optsize minsize noredzone { 74 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i32 1, i1 false) 75 ret void 76; LINUX-LABEL: test3_minsize_optsize: 77; LINUX: memcpy 78 79; DARWIN-LABEL: test3_minsize_optsize: 80; DARWIN: memcpy 81} 82 83; Large constant memcpy's should be inlined when not optimizing for size. 84define void @test4(i8* nocapture %A, i8* nocapture %B) nounwind noredzone { 85entry: 86 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i32 1, i1 false) 87 ret void 88; LINUX-LABEL: test4: 89; LINUX: movq 90; LINUX: movq 91; LINUX: movq 92; LINUX: movq 93; LINUX: movq 94; LINUX: movq 95; LINUX: movq 96; LINUX: movq 97; LINUX: movq 98; LINUX: movq 99; LINUX: movq 100; LINUX: movq 101} 102 103 104@.str = private unnamed_addr constant [30 x i8] c"\00aaaaaaaaaaaaaaaaaaaaaaaaaaaa\00", align 1 105 106define void @test5(i8* nocapture %C) nounwind uwtable ssp { 107entry: 108 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, i32 1, i1 false) 109 ret void 110 111; DARWIN-LABEL: test5: 112; DARWIN: movabsq $7016996765293437281 113; DARWIN: movabsq $7016996765293437184 114} 115 116 117; PR14896 118@.str2 = private unnamed_addr constant [2 x i8] c"x\00", align 1 119 120define void @test6() nounwind uwtable { 121entry: 122; DARWIN: test6 123; DARWIN: movw $0, 8 124; DARWIN: movq $120, 0 125 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, i32 1, i1 false) 126 ret void 127} 128 129define void @PR15348(i8* %a, i8* %b) { 130; Ensure that alignment of '0' in an @llvm.memcpy intrinsic results in 131; unaligned loads and stores. 132; LINUX: PR15348 133; LINUX: movb 134; LINUX: movb 135; LINUX: movq 136; LINUX: movq 137; LINUX: movq 138; LINUX: movq 139 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 17, i32 0, i1 false) 140 ret void 141} 142 143; Memcpys from / to address space 256 should be lowered to appropriate loads / 144; stores if small enough. 145define void @addrspace256(i8 addrspace(256)* %a, i8 addrspace(256)* %b) nounwind { 146 tail call void @llvm.memcpy.p256i8.p256i8.i64(i8 addrspace(256)* %a, i8 addrspace(256)* %b, i64 16, i32 8, i1 false) 147 ret void 148; LINUX-LABEL: addrspace256: 149; LINUX: movq %gs: 150; LINUX: movq %gs: 151; LINUX: movq {{.*}}, %gs: 152; LINUX: movq {{.*}}, %gs: 153} 154