1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
4 define ptr @memcpy_nonconst_n(ptr %d, ptr nocapture readonly %s, i64 %n) {
5 ; CHECK-LABEL: @memcpy_nonconst_n(
6 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[D:%.*]], ptr align 1 [[S:%.*]], i64 [[N:%.*]], i1 false)
7 ; CHECK-NEXT: [[R:%.*]] = getelementptr inbounds i8, ptr [[D]], i64 [[N]]
8 ; CHECK-NEXT: ret ptr [[R]]
10 %r = tail call ptr @mempcpy(ptr %d, ptr %s, i64 %n)
14 define ptr @memcpy_nonconst_n_copy_attrs(ptr %d, ptr nocapture readonly %s, i64 %n) {
15 ; CHECK-LABEL: @memcpy_nonconst_n_copy_attrs(
16 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 dereferenceable(16) [[D:%.*]], ptr align 1 [[S:%.*]], i64 [[N:%.*]], i1 false)
17 ; CHECK-NEXT: [[R:%.*]] = getelementptr inbounds i8, ptr [[D]], i64 [[N]]
18 ; CHECK-NEXT: ret ptr [[R]]
20 %r = tail call ptr @mempcpy(ptr dereferenceable(16) %d, ptr %s, i64 %n)
24 define void @memcpy_nonconst_n_unused_retval(ptr %d, ptr nocapture readonly %s, i64 %n) {
25 ; CHECK-LABEL: @memcpy_nonconst_n_unused_retval(
26 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[D:%.*]], ptr align 1 [[S:%.*]], i64 [[N:%.*]], i1 false)
27 ; CHECK-NEXT: ret void
29 call ptr @mempcpy(ptr %d, ptr %s, i64 %n)
33 define ptr @memcpy_small_const_n(ptr %d, ptr nocapture readonly %s) {
34 ; CHECK-LABEL: @memcpy_small_const_n(
35 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[S:%.*]], align 1
36 ; CHECK-NEXT: store i64 [[TMP1]], ptr [[D:%.*]], align 1
37 ; CHECK-NEXT: [[R:%.*]] = getelementptr inbounds i8, ptr [[D]], i64 8
38 ; CHECK-NEXT: ret ptr [[R]]
40 %r = tail call ptr @mempcpy(ptr %d, ptr %s, i64 8)
44 define ptr @memcpy_big_const_n(ptr %d, ptr nocapture readonly %s) {
45 ; CHECK-LABEL: @memcpy_big_const_n(
46 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1024) [[D:%.*]], ptr noundef nonnull align 1 dereferenceable(1024) [[S:%.*]], i64 1024, i1 false)
47 ; CHECK-NEXT: [[R:%.*]] = getelementptr inbounds i8, ptr [[D]], i64 1024
48 ; CHECK-NEXT: ret ptr [[R]]
50 %r = tail call ptr @mempcpy(ptr %d, ptr %s, i64 1024)
54 ; The original call may have attributes that can not propagate to memcpy.
56 define i32 @PR48810() {
57 ; CHECK-LABEL: @PR48810(
58 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 undef, ptr align 4294967296 null, i64 undef, i1 false)
59 ; CHECK-NEXT: ret i32 undef
61 %r = call dereferenceable(1) ptr @mempcpy(ptr undef, ptr null, i64 undef)
65 define ptr @memcpy_no_simplify1(ptr %d, ptr nocapture readonly %s, i64 %n) {
66 ; CHECK-LABEL: @memcpy_no_simplify1(
67 ; CHECK-NEXT: [[R:%.*]] = musttail call ptr @mempcpy(ptr [[D:%.*]], ptr [[S:%.*]], i64 [[N:%.*]])
68 ; CHECK-NEXT: ret ptr [[R]]
70 %r = musttail call ptr @mempcpy(ptr %d, ptr %s, i64 %n)
74 declare ptr @mempcpy(ptr, ptr nocapture readonly, i64)