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