xref: /llvm-project/llvm/test/Transforms/InstCombine/memcpy-to-load.ll (revision a87fa7f0caa1b8bf328524e0aec80a10ed4af7f9)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S                         | FileCheck %s
3; RUN: opt < %s -passes=instcombine -S -data-layout=n32        | FileCheck %s
4; RUN: opt < %s -passes=instcombine -S -data-layout=n32:64     | FileCheck %s
5; RUN: opt < %s -passes=instcombine -S -data-layout=n32:64:128 | FileCheck %s
6
7declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind
8
9; memcpy can be expanded inline with load/store (based on the datalayout?)
10
11define void @copy_1_byte(ptr %d, ptr %s) {
12; CHECK-LABEL: @copy_1_byte(
13; CHECK-NEXT:    [[TMP1:%.*]] = load i8, ptr [[S:%.*]], align 1
14; CHECK-NEXT:    store i8 [[TMP1]], ptr [[D:%.*]], align 1
15; CHECK-NEXT:    ret void
16;
17  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 1, i1 false)
18  ret void
19}
20
21define void @copy_2_bytes(ptr %d, ptr %s) {
22; CHECK-LABEL: @copy_2_bytes(
23; CHECK-NEXT:    [[TMP1:%.*]] = load i16, ptr [[S:%.*]], align 1
24; CHECK-NEXT:    store i16 [[TMP1]], ptr [[D:%.*]], align 1
25; CHECK-NEXT:    ret void
26;
27  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 2, i1 false)
28  ret void
29}
30
31; We don't expand small non-power-of-2. Should we? Might be a target-dependent choice.
32
33define void @copy_3_bytes(ptr %d, ptr %s) {
34; CHECK-LABEL: @copy_3_bytes(
35; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) [[D:%.*]], ptr noundef nonnull align 1 dereferenceable(3) [[S:%.*]], i32 3, i1 false)
36; CHECK-NEXT:    ret void
37;
38  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 3, i1 false)
39  ret void
40}
41
42define void @copy_4_bytes(ptr %d, ptr %s) {
43; CHECK-LABEL: @copy_4_bytes(
44; CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[S:%.*]], align 1
45; CHECK-NEXT:    store i32 [[TMP1]], ptr [[D:%.*]], align 1
46; CHECK-NEXT:    ret void
47;
48  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 4, i1 false)
49  ret void
50}
51
52; We don't expand small non-power-of-2. Should we? Might be a target-dependent choice.
53
54define void @copy_5_bytes(ptr %d, ptr %s) {
55; CHECK-LABEL: @copy_5_bytes(
56; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(5) [[D:%.*]], ptr noundef nonnull align 1 dereferenceable(5) [[S:%.*]], i32 5, i1 false)
57; CHECK-NEXT:    ret void
58;
59  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 5, i1 false)
60  ret void
61}
62
63define void @copy_8_bytes(ptr %d, ptr %s) {
64; CHECK-LABEL: @copy_8_bytes(
65; CHECK-NEXT:    [[TMP1:%.*]] = load i64, ptr [[S:%.*]], align 1
66; CHECK-NEXT:    store i64 [[TMP1]], ptr [[D:%.*]], align 1
67; CHECK-NEXT:    ret void
68;
69  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 8, i1 false)
70  ret void
71}
72
73define void @copy_16_bytes(ptr %d, ptr %s) {
74; CHECK-LABEL: @copy_16_bytes(
75; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(16) [[D:%.*]], ptr noundef nonnull align 1 dereferenceable(16) [[S:%.*]], i32 16, i1 false)
76; CHECK-NEXT:    ret void
77;
78  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 16, i1 false)
79  ret void
80}
81
82define void @copy_8_bytes_noalias(ptr %d, ptr %s) {
83; CHECK-LABEL: @copy_8_bytes_noalias(
84; CHECK-NEXT:    [[TMP1:%.*]] = load i64, ptr [[S:%.*]], align 1, !alias.scope [[META0:![0-9]+]], !noalias [[META3:![0-9]+]]
85; CHECK-NEXT:    store i64 [[TMP1]], ptr [[D:%.*]], align 1, !alias.scope [[META0]], !noalias [[META3]]
86; CHECK-NEXT:    ret void
87;
88  call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 8, i1 false), !alias.scope !4, !noalias !5
89  ret void
90}
91
92!0 = distinct !{!0, !"The domain"}
93!1 = distinct !{!1}
94!2 = !{!2, !0}
95!3 = !{!3, !1}
96!4 = !{!2}
97!5 = !{!3}
98