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
7 declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind
9 ; memcpy can be expanded inline with load/store (based on the datalayout?)
11 define 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
17 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 1, i1 false)
21 define 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
27 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 2, i1 false)
31 ; We don't expand small non-power-of-2. Should we? Might be a target-dependent choice.
33 define 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
38 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 3, i1 false)
42 define 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
48 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 4, i1 false)
52 ; We don't expand small non-power-of-2. Should we? Might be a target-dependent choice.
54 define 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
59 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 5, i1 false)
63 define 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
69 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 8, i1 false)
73 define 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
78 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 16, i1 false)
82 define 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
88 call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 8, i1 false), !alias.scope !4, !noalias !5
92 !0 = distinct !{!0, !"The domain"}