1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 declare i32 @memcmp(i8* nocapture, i8* nocapture, i64)
5 declare i8* @memcpy(i8* nocapture, i8* nocapture, i64)
6 declare i8* @memmove(i8* nocapture, i8* nocapture, i64)
7 declare i8* @memset(i8* nocapture, i8, i64)
8 declare i8* @memchr(i8* nocapture, i32, i64)
9 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1)
10 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1)
11 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1)
13 define i32 @memcmp_const_size_set_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
14 ; CHECK-LABEL: @memcmp_const_size_set_deref(
15 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(16) [[D:%.*]], i8* noundef nonnull dereferenceable(16) [[S:%.*]], i64 16)
16 ; CHECK-NEXT: ret i32 [[CALL]]
18 %call = tail call i32 @memcmp(i8* %d, i8* %s, i64 16)
22 define i32 @memcmp_const_size_update_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
23 ; CHECK-LABEL: @memcmp_const_size_update_deref(
24 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(16) [[D:%.*]], i8* noundef nonnull dereferenceable(16) [[S:%.*]], i64 16)
25 ; CHECK-NEXT: ret i32 [[CALL]]
27 %call = tail call i32 @memcmp(i8* dereferenceable(4) %d, i8* dereferenceable(8) %s, i64 16)
31 define i32 @memcmp_const_size_update_deref2(i8* nocapture readonly %d, i8* nocapture readonly %s) {
32 ; CHECK-LABEL: @memcmp_const_size_update_deref2(
33 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(16) [[D:%.*]], i8* noundef nonnull dereferenceable(16) [[S:%.*]], i64 16)
34 ; CHECK-NEXT: ret i32 [[CALL]]
36 %call = tail call i32 @memcmp(i8* %d, i8* dereferenceable_or_null(8) %s, i64 16)
40 define i32 @memcmp_const_size_update_deref3(i8* nocapture readonly %d, i8* nocapture readonly %s) {
41 ; CHECK-LABEL: @memcmp_const_size_update_deref3(
42 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(40) [[D:%.*]], i8* noundef nonnull dereferenceable(16) [[S:%.*]], i64 16)
43 ; CHECK-NEXT: ret i32 [[CALL]]
45 %call = tail call i32 @memcmp(i8* dereferenceable(40) %d, i8* %s, i64 16)
49 define i32 @memcmp_const_size_update_deref4(i8* nocapture readonly %d, i8* nocapture readonly %s) {
50 ; CHECK-LABEL: @memcmp_const_size_update_deref4(
51 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(16) [[D:%.*]], i8* noundef nonnull dereferenceable(16) [[S:%.*]], i64 16)
52 ; CHECK-NEXT: ret i32 [[CALL]]
54 %call = tail call i32 @memcmp(i8* dereferenceable_or_null(16) %d, i8* %s, i64 16)
58 define i32 @memcmp_const_size_update_deref5(i8* nocapture readonly %d, i8* nocapture readonly %s) {
59 ; CHECK-LABEL: @memcmp_const_size_update_deref5(
60 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(40) [[D:%.*]], i8* noundef nonnull dereferenceable(16) [[S:%.*]], i64 16)
61 ; CHECK-NEXT: ret i32 [[CALL]]
63 %call = tail call i32 @memcmp(i8* dereferenceable_or_null(40) %d, i8* %s, i64 16)
67 define i32 @memcmp_const_size_update_deref6(i8* nocapture readonly %d, i8* nocapture readonly %s) null_pointer_is_valid {
68 ; CHECK-LABEL: @memcmp_const_size_update_deref6(
69 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef dereferenceable(16) dereferenceable_or_null(40) [[D:%.*]], i8* noundef dereferenceable(16) [[S:%.*]], i64 16)
70 ; CHECK-NEXT: ret i32 [[CALL]]
72 %call = tail call i32 @memcmp(i8* dereferenceable_or_null(40) %d, i8* %s, i64 16)
76 define i32 @memcmp_const_size_update_deref7(i8* nocapture readonly %d, i8* nocapture readonly %s) null_pointer_is_valid {
77 ; CHECK-LABEL: @memcmp_const_size_update_deref7(
78 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(40) [[D:%.*]], i8* noundef dereferenceable(16) [[S:%.*]], i64 16)
79 ; CHECK-NEXT: ret i32 [[CALL]]
81 %call = tail call i32 @memcmp(i8* nonnull dereferenceable_or_null(40) %d, i8* %s, i64 16)
85 define i32 @memcmp_const_size_no_update_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
86 ; CHECK-LABEL: @memcmp_const_size_no_update_deref(
87 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* noundef nonnull dereferenceable(40) [[D:%.*]], i8* noundef nonnull dereferenceable(20) [[S:%.*]], i64 16)
88 ; CHECK-NEXT: ret i32 [[CALL]]
90 %call = tail call i32 @memcmp(i8* dereferenceable(40) %d, i8* dereferenceable(20) %s, i64 16)
94 define i32 @memcmp_nonconst_size(i8* nocapture readonly %d, i8* nocapture readonly %s, i64 %n) {
95 ; CHECK-LABEL: @memcmp_nonconst_size(
96 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* [[D:%.*]], i8* [[S:%.*]], i64 [[N:%.*]])
97 ; CHECK-NEXT: ret i32 [[CALL]]
99 %call = tail call i32 @memcmp(i8* %d, i8* %s, i64 %n)
103 define i8* @memcpy_const_size_set_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
104 ; CHECK-LABEL: @memcpy_const_size_set_deref(
105 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 1 dereferenceable(64) [[D:%.*]], i8* noundef nonnull align 1 dereferenceable(64) [[S:%.*]], i64 64, i1 false)
106 ; CHECK-NEXT: ret i8* [[D]]
108 %call = tail call i8* @memcpy(i8* %d, i8* %s, i64 64)
112 define i8* @memmove_const_size_set_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
113 ; CHECK-LABEL: @memmove_const_size_set_deref(
114 ; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i64(i8* noundef nonnull align 1 dereferenceable(64) [[D:%.*]], i8* noundef nonnull align 1 dereferenceable(64) [[S:%.*]], i64 64, i1 false)
115 ; CHECK-NEXT: ret i8* [[D]]
117 %call = tail call i8* @memmove(i8* %d, i8* %s, i64 64)
121 define i8* @memset_const_size_set_deref(i8* nocapture readonly %s, i8 %c) {
122 ; CHECK-LABEL: @memset_const_size_set_deref(
123 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* noundef nonnull align 1 dereferenceable(64) [[S:%.*]], i8 [[C:%.*]], i64 64, i1 false)
124 ; CHECK-NEXT: ret i8* [[S]]
126 %call = tail call i8* @memset(i8* %s, i8 %c, i64 64)
130 define i8* @memchr_const_size_set_deref(i8* nocapture readonly %s, i32 %c) {
131 ; CHECK-LABEL: @memchr_const_size_set_deref(
132 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @memchr(i8* noundef nonnull dereferenceable(64) [[S:%.*]], i32 [[C:%.*]], i64 64)
133 ; CHECK-NEXT: ret i8* [[CALL]]
135 %call = tail call i8* @memchr(i8* %s, i32 %c, i64 64)
139 define i8* @llvm_memcpy_const_size_set_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
140 ; CHECK-LABEL: @llvm_memcpy_const_size_set_deref(
141 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 1 dereferenceable(16) [[D:%.*]], i8* noundef nonnull align 1 dereferenceable(16) [[S:%.*]], i64 16, i1 false)
142 ; CHECK-NEXT: ret i8* [[D]]
144 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %d, i8* align 1 %s, i64 16, i1 false)
148 define i8* @llvm_memmove_const_size_set_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
149 ; CHECK-LABEL: @llvm_memmove_const_size_set_deref(
150 ; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i64(i8* noundef nonnull align 1 dereferenceable(16) [[D:%.*]], i8* noundef nonnull align 1 dereferenceable(16) [[S:%.*]], i64 16, i1 false)
151 ; CHECK-NEXT: ret i8* [[D]]
153 call void @llvm.memmove.p0i8.p0i8.i64(i8* align 1 %d, i8* align 1 %s, i64 16, i1 false)
156 define i8* @llvm_memset_const_size_set_deref(i8* nocapture readonly %s, i8 %c) {
157 ; CHECK-LABEL: @llvm_memset_const_size_set_deref(
158 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* noundef nonnull align 1 dereferenceable(16) [[S:%.*]], i8 [[C:%.*]], i64 16, i1 false)
159 ; CHECK-NEXT: ret i8* [[S]]
161 call void @llvm.memset.p0i8.i64(i8* align 1 %s, i8 %c, i64 16, i1 false)