1 ; RUN: opt -memcpyopt -S %s | FileCheck %s
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5 ; CHECK-LABEL: define void @test(
6 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
7 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %dst2, i8 %c, i64 128, i1 false)
9 define void @test(i8* %dst1, i8* %dst2, i8 %c) {
10 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
11 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %dst2, i8* align 8 %dst1, i64 128, i1 false)
15 ; CHECK-LABEL: define void @test_smaller_memcpy(
16 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
17 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst2, i8 %c, i64 100, i1 false)
18 ; CHECK-NEXT: ret void
19 define void @test_smaller_memcpy(i8* %dst1, i8* %dst2, i8 %c) {
20 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
21 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 100, i1 false)
25 ; CHECK-LABEL: define void @test_smaller_memset(
26 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 100, i1 false)
27 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 128, i1 false)
28 ; CHECK-NEXT: ret void
29 define void @test_smaller_memset(i8* %dst1, i8* %dst2, i8 %c) {
30 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 100, i1 false)
31 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 128, i1 false)
35 ; CHECK-LABEL: define void @test_align_memset(
36 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %dst1, i8 %c, i64 128, i1 false)
37 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst2, i8 %c, i64 128, i1 false)
38 ; CHECK-NEXT: ret void
39 define void @test_align_memset(i8* %dst1, i8* %dst2, i8 %c) {
40 call void @llvm.memset.p0i8.i64(i8* align 8 %dst1, i8 %c, i64 128, i1 false)
41 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 128, i1 false)
45 ; CHECK-LABEL: define void @test_different_types(
46 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %dst1, i8 %c, i64 128, i1 false)
47 ; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* %dst2, i8 %c, i32 100, i1 false)
48 ; CHECK-NEXT: ret void
49 define void @test_different_types(i8* %dst1, i8* %dst2, i8 %c) {
50 call void @llvm.memset.p0i8.i64(i8* align 8 %dst1, i8 %c, i64 128, i1 false)
51 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst2, i8* %dst1, i32 100, i1 false)
55 ; CHECK-LABEL: define void @test_different_types_2(
56 ; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* align 8 %dst1, i8 %c, i32 128, i1 false)
57 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst2, i8 %c, i64 100, i1 false)
58 ; CHECK-NEXT: ret void
59 define void @test_different_types_2(i8* %dst1, i8* %dst2, i8 %c) {
60 call void @llvm.memset.p0i8.i32(i8* align 8 %dst1, i8 %c, i32 128, i1 false)
61 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 100, i1 false)
65 ; CHECK-LABEL: define void @test_different_source_gep(
66 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
67 ; CHECK-NEXT: %p = getelementptr i8, i8* %dst1, i64 64
68 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %p, i64 64, i1 false)
69 ; CHECK-NEXT: ret void
70 define void @test_different_source_gep(i8* %dst1, i8* %dst2, i8 %c) {
71 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
72 ; FIXME: We could optimize this as well.
73 %p = getelementptr i8, i8* %dst1, i64 64
74 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %p, i64 64, i1 false)
78 ; CHECK-LABEL: define void @test_variable_size_1(
79 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 %dst1_size, i1 false)
80 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 128, i1 false)
81 ; CHECK-NEXT: ret void
82 define void @test_variable_size_1(i8* %dst1, i64 %dst1_size, i8* %dst2, i8 %c) {
83 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 %dst1_size, i1 false)
84 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 128, i1 false)
88 ; CHECK-LABEL: define void @test_variable_size_2(
89 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
90 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 %dst2_size, i1 false)
91 ; CHECK-NEXT: ret void
92 define void @test_variable_size_2(i8* %dst1, i8* %dst2, i64 %dst2_size, i8 %c) {
93 call void @llvm.memset.p0i8.i64(i8* %dst1, i8 %c, i64 128, i1 false)
94 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %dst1, i64 %dst2_size, i1 false)
98 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1)
99 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1)
100 declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1)
101 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i1)