1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -memcpyopt < %s | FileCheck %s
4 define void @test_copy_uninit([1000 x [1000 x i32]]* %arg) {
5 ; CHECK-LABEL: @test_copy_uninit(
7 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [1000 x i32], align 4
8 ; CHECK-NEXT: [[ALLOCA_I8:%.*]] = bitcast [1000 x i32]* [[ALLOCA]] to i8*
9 ; CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* [[ARG:%.*]], i64 0, i64 0
10 ; CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* [[ARG]], i64 0, i64 1000
11 ; CHECK-NEXT: br label [[LOOP:%.*]]
13 ; CHECK-NEXT: [[CURRENT:%.*]] = phi [1000 x i32]* [ [[BEGIN]], [[START:%.*]] ], [ [[NEXT:%.*]], [[LOOP]] ]
14 ; CHECK-NEXT: [[CURRENT_I8:%.*]] = bitcast [1000 x i32]* [[CURRENT]] to i8*
15 ; CHECK-NEXT: [[NEXT]] = getelementptr inbounds [1000 x i32], [1000 x i32]* [[CURRENT]], i64 1
16 ; CHECK-NEXT: [[COND:%.*]] = icmp eq [1000 x i32]* [[NEXT]], [[END]]
17 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
19 ; CHECK-NEXT: ret void
22 %alloca = alloca [1000 x i32], align 4
23 %alloca.i8 = bitcast [1000 x i32]* %alloca to i8*
24 %begin = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %arg, i64 0, i64 0
25 %end = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %arg, i64 0, i64 1000
28 loop: ; preds = %loop, %start
29 %current = phi [1000 x i32]* [ %begin, %start ], [ %next, %loop ]
30 %current.i8 = bitcast [1000 x i32]* %current to i8*
31 call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(4000) %current.i8, i8* nonnull align 4 dereferenceable(4000) %alloca.i8, i64 4000, i1 false)
32 %next = getelementptr inbounds [1000 x i32], [1000 x i32]* %current, i64 1
33 %cond = icmp eq [1000 x i32]* %next, %end
34 br i1 %cond, label %exit, label %loop
40 define void @test_copy_zero([1000 x [1000 x i32]]* %arg) {
41 ; CHECK-LABEL: @test_copy_zero(
43 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [1000 x i32], align 4
44 ; CHECK-NEXT: [[ALLOCA_I8:%.*]] = bitcast [1000 x i32]* [[ALLOCA]] to i8*
45 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* nonnull align 4 dereferenceable(4000) [[ALLOCA_I8]], i8 0, i64 4000, i1 false)
46 ; CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* [[ARG:%.*]], i64 0, i64 0
47 ; CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* [[ARG]], i64 0, i64 1000
48 ; CHECK-NEXT: br label [[LOOP:%.*]]
50 ; CHECK-NEXT: [[CURRENT:%.*]] = phi [1000 x i32]* [ [[BEGIN]], [[START:%.*]] ], [ [[NEXT:%.*]], [[LOOP]] ]
51 ; CHECK-NEXT: [[CURRENT_I8:%.*]] = bitcast [1000 x i32]* [[CURRENT]] to i8*
52 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 4 [[CURRENT_I8]], i8 0, i64 4000, i1 false)
53 ; CHECK-NEXT: [[NEXT]] = getelementptr inbounds [1000 x i32], [1000 x i32]* [[CURRENT]], i64 1
54 ; CHECK-NEXT: [[COND:%.*]] = icmp eq [1000 x i32]* [[NEXT]], [[END]]
55 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
57 ; CHECK-NEXT: ret void
60 %alloca = alloca [1000 x i32], align 4
61 %alloca.i8 = bitcast [1000 x i32]* %alloca to i8*
62 call void @llvm.memset.p0i8.i64(i8* nonnull align 4 dereferenceable(4000) %alloca.i8, i8 0, i64 4000, i1 false)
63 %begin = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %arg, i64 0, i64 0
64 %end = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %arg, i64 0, i64 1000
67 loop: ; preds = %loop, %start
68 %current = phi [1000 x i32]* [ %begin, %start ], [ %next, %loop ]
69 %current.i8 = bitcast [1000 x i32]* %current to i8*
70 call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(4000) %current.i8, i8* nonnull align 4 dereferenceable(4000) %alloca.i8, i64 4000, i1 false)
71 %next = getelementptr inbounds [1000 x i32], [1000 x i32]* %current, i64 1
72 %cond = icmp eq [1000 x i32]* %next, %end
73 br i1 %cond, label %exit, label %loop
79 declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
80 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)