1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=memcpyopt < %s | FileCheck %s
4 define void @test_copy_uninit(ptr %arg) {
5 ; CHECK-LABEL: @test_copy_uninit(
7 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [1000 x i32], align 4
8 ; CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [1000 x [1000 x i32]], ptr [[ARG:%.*]], i64 0, i64 1000
9 ; CHECK-NEXT: br label [[LOOP:%.*]]
11 ; CHECK-NEXT: [[CURRENT:%.*]] = phi ptr [ [[ARG]], [[START:%.*]] ], [ [[NEXT:%.*]], [[LOOP]] ]
12 ; CHECK-NEXT: [[NEXT]] = getelementptr inbounds [1000 x i32], ptr [[CURRENT]], i64 1
13 ; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[NEXT]], [[END]]
14 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
16 ; CHECK-NEXT: ret void
19 %alloca = alloca [1000 x i32], align 4
20 %end = getelementptr inbounds [1000 x [1000 x i32]], ptr %arg, i64 0, i64 1000
23 loop: ; preds = %loop, %start
24 %current = phi ptr [ %arg, %start ], [ %next, %loop ]
25 call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 dereferenceable(4000) %current, ptr nonnull align 4 dereferenceable(4000) %alloca, i64 4000, i1 false)
26 %next = getelementptr inbounds [1000 x i32], ptr %current, i64 1
27 %cond = icmp eq ptr %next, %end
28 br i1 %cond, label %exit, label %loop
34 define void @test_copy_zero(ptr %arg) {
35 ; CHECK-LABEL: @test_copy_zero(
37 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [1000 x i32], align 4
38 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr nonnull align 4 dereferenceable(4000) [[ALLOCA]], i8 0, i64 4000, i1 false)
39 ; CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [1000 x [1000 x i32]], ptr [[ARG:%.*]], i64 0, i64 1000
40 ; CHECK-NEXT: br label [[LOOP:%.*]]
42 ; CHECK-NEXT: [[CURRENT:%.*]] = phi ptr [ [[ARG]], [[START:%.*]] ], [ [[NEXT:%.*]], [[LOOP]] ]
43 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[CURRENT]], i8 0, i64 4000, i1 false)
44 ; CHECK-NEXT: [[NEXT]] = getelementptr inbounds [1000 x i32], ptr [[CURRENT]], i64 1
45 ; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[NEXT]], [[END]]
46 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
48 ; CHECK-NEXT: ret void
51 %alloca = alloca [1000 x i32], align 4
52 call void @llvm.memset.p0.i64(ptr nonnull align 4 dereferenceable(4000) %alloca, i8 0, i64 4000, i1 false)
53 %end = getelementptr inbounds [1000 x [1000 x i32]], ptr %arg, i64 0, i64 1000
56 loop: ; preds = %loop, %start
57 %current = phi ptr [ %arg, %start ], [ %next, %loop ]
58 call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 dereferenceable(4000) %current, ptr nonnull align 4 dereferenceable(4000) %alloca, i64 4000, i1 false)
59 %next = getelementptr inbounds [1000 x i32], ptr %current, i64 1
60 %cond = icmp eq ptr %next, %end
61 br i1 %cond, label %exit, label %loop
67 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
68 declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)