1; MemCpy optimizations should take place even in presence of invariant.start 2; RUN: opt < %s -basicaa -memcpyopt -dse -S | FileCheck %s 3 4target 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" 5 6target triple = "i686-apple-darwin9" 7 8%0 = type { x86_fp80, x86_fp80 } 9declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind 10declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1) 11declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) 12 13declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) nounwind readonly 14 15; FIXME: The invariant.start does not modify %P. 16; The intermediate alloca and one of the memcpy's should be eliminated, the 17; other should be transformed to a memmove. 18define void @test1(i8* %P, i8* %Q) nounwind { 19 %memtmp = alloca %0, align 16 20 %R = bitcast %0* %memtmp to i8* 21 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %R, i8* align 16 %P, i32 32, i1 false) 22 %i = call {}* @llvm.invariant.start.p0i8(i64 32, i8* %P) 23 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %Q, i8* align 16 %R, i32 32, i1 false) 24 ret void 25; CHECK-LABEL: @test1( 26; CHECK-NEXT: %memtmp = alloca %0, align 16 27; CHECK-NEXT: %R = bitcast %0* %memtmp to i8* 28; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %R, i8* align 16 %P, i32 32, i1 false) 29; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 32, i8* %P) 30; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %Q, i8* align 16 %R, i32 32, i1 false) 31; CHECK-NEXT: ret void 32} 33 34 35; The invariant.start intrinsic does not inhibit tranforming the memcpy to a 36; memset. 37define void @test2(i8* %dst1, i8* %dst2, i8 %c) { 38; CHECK-LABEL: define void @test2( 39; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false) 40; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 32, i8* %dst1) 41; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %dst2, i8 %c, i64 128, i1 false) 42; CHECK-NEXT: ret void 43 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false) 44 %i = call {}* @llvm.invariant.start.p0i8(i64 32, i8* %dst1) 45 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %dst2, i8* align 8 %dst1, i64 128, i1 false) 46 ret void 47} 48