1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; MemCpy optimizations should take place even in presence of invariant.start
3 ; RUN: opt < %s -basic-aa -memcpyopt -S -verify-memoryssa | FileCheck %s
5 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"
7 target triple = "i686-apple-darwin9"
9 %0 = type { x86_fp80, x86_fp80 }
10 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind
11 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1)
12 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1)
14 declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) nounwind readonly
16 ; The intermediate alloca and one of the memcpy's should be eliminated, the
17 ; other should be transformed to a memmove.
18 define void @test1(i8* %P, i8* %Q) nounwind {
19 ; CHECK-LABEL: @test1(
20 ; CHECK-NEXT: [[MEMTMP:%.*]] = alloca [[TMP0:%.*]], align 16
21 ; CHECK-NEXT: [[R:%.*]] = bitcast %0* [[MEMTMP]] to i8*
22 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 [[R]], i8* align 16 [[P:%.*]], i32 32, i1 false)
23 ; CHECK-NEXT: [[I:%.*]] = call {}* @llvm.invariant.start.p0i8(i64 32, i8* [[P]])
24 ; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i32(i8* align 16 [[Q:%.*]], i8* align 16 [[P]], i32 32, i1 false)
25 ; CHECK-NEXT: ret void
27 %memtmp = alloca %0, align 16
28 %R = bitcast %0* %memtmp to i8*
29 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %R, i8* align 16 %P, i32 32, i1 false)
30 %i = call {}* @llvm.invariant.start.p0i8(i64 32, i8* %P)
31 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %Q, i8* align 16 %R, i32 32, i1 false)
36 ; The invariant.start intrinsic does not inhibit tranforming the memcpy to a
38 define void @test2(i8* %dst1, i8* %dst2, i8 %c) {
39 ; CHECK-LABEL: @test2(
40 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[DST1:%.*]], i8 [[C:%.*]], i64 128, i1 false)
41 ; CHECK-NEXT: [[I:%.*]] = call {}* @llvm.invariant.start.p0i8(i64 32, i8* [[DST1]])
42 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 [[DST2:%.*]], i8 [[C]], i64 128, i1 false)
43 ; CHECK-NEXT: ret void
45 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
46 %i = call {}* @llvm.invariant.start.p0i8(i64 32, i8* %dst1)
47 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %dst2, i8* align 8 %dst1, i64 128, i1 false)