1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -memcpyopt -S < %s -verify-memoryssa | FileCheck %s
3; RUN: opt -passes=memcpyopt -S < %s -verify-memoryssa | FileCheck %s
4; rdar://8875553
5
6; Memcpyopt shouldn't optimize the second memcpy using the first
7; because the first has a smaller size.
8
9target datalayout = "e-p:32:32:32"
10
11%struct.s = type { [11 x i8], i32 }
12
13@.str = private constant [11 x i8] c"0123456789\00"
14@cell = external global %struct.s
15
16declare void @check(%struct.s* byval(%struct.s) %p) nounwind
17declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind
18
19define void @foo() nounwind {
20; CHECK-LABEL: @foo(
21; CHECK-NEXT:  entry:
22; CHECK-NEXT:    [[AGG_TMP:%.*]] = alloca [[STRUCT_S:%.*]], align 4
23; CHECK-NEXT:    store i32 99, i32* getelementptr inbounds (%struct.s, %struct.s* @cell, i32 0, i32 1), align 4
24; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 getelementptr inbounds (%struct.s, %struct.s* @cell, i32 0, i32 0, i32 0), i8* align 1 getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i32 11, i1 false)
25; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds [[STRUCT_S]], %struct.s* [[AGG_TMP]], i32 0, i32 0, i32 0
26; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 [[TMP]], i8* align 4 getelementptr inbounds (%struct.s, %struct.s* @cell, i32 0, i32 0, i32 0), i32 16, i1 false)
27; CHECK-NEXT:    call void @check(%struct.s* byval(%struct.s) [[AGG_TMP]])
28; CHECK-NEXT:    ret void
29;
30entry:
31  %agg.tmp = alloca %struct.s, align 4
32  store i32 99, i32* getelementptr inbounds (%struct.s, %struct.s* @cell, i32 0, i32 1), align 4
33  call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 getelementptr inbounds (%struct.s, %struct.s* @cell, i32 0, i32 0, i32 0), i8* align 1 getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i32 11, i1 false)
34  %tmp = getelementptr inbounds %struct.s, %struct.s* %agg.tmp, i32 0, i32 0, i32 0
35  call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %tmp, i8* align 4 getelementptr inbounds (%struct.s, %struct.s* @cell, i32 0, i32 0, i32 0), i32 16, i1 false)
36  call void @check(%struct.s* byval(%struct.s) %agg.tmp)
37  ret void
38}
39