1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 @hello = private constant [11 x i8] c"helloworld\00", align 1
5 @NoNulTerminator = private constant [10 x i8] c"helloworld", align 1
6 @StopCharAfterNulTerminator = private constant [12 x i8] c"helloworld\00x", align 1
7 @StringWithEOF = constant [14 x i8] c"helloworld\FFab\00", align 1
9 declare ptr @memccpy(ptr, ptr, i32, i64)
11 define ptr @memccpy_to_memcpy(ptr %dst) {
12 ; CHECK-LABEL: @memccpy_to_memcpy(
13 ; CHECK-NEXT: store i64 8245940763182785896, ptr [[DST:%.*]], align 1
14 ; CHECK-NEXT: [[CALL:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 8
15 ; CHECK-NEXT: ret ptr [[CALL]]
17 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 12) ; 114 is 'r'
21 define ptr @memccpy_to_memcpy2(ptr %dst) {
22 ; CHECK-LABEL: @memccpy_to_memcpy2(
23 ; CHECK-NEXT: store i64 8245940763182785896, ptr [[DST:%.*]], align 1
24 ; CHECK-NEXT: [[CALL:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 8
25 ; CHECK-NEXT: ret ptr [[CALL]]
27 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 8); ; 114 is 'r'
31 define void @memccpy_to_memcpy3(ptr %dst) {
32 ; CHECK-LABEL: @memccpy_to_memcpy3(
33 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(5) @hello, i64 5, i1 false)
34 ; CHECK-NEXT: ret void
36 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 111, i64 10) ; 111 is 'o'
40 define void @memccpy_to_memcpy3_tail(ptr %dst) {
41 ; CHECK-LABEL: @memccpy_to_memcpy3_tail(
42 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(5) @hello, i64 5, i1 false)
43 ; CHECK-NEXT: ret void
45 %call = tail call ptr @memccpy(ptr %dst, ptr @hello, i32 111, i64 10) ; 111 is 'o'
49 define ptr @memccpy_to_memcpy3_musttail(ptr %dst, ptr %x, i32 %y, i64 %z) {
50 ; CHECK-LABEL: @memccpy_to_memcpy3_musttail(
51 ; CHECK-NEXT: [[CALL:%.*]] = musttail call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 111, i64 10)
52 ; CHECK-NEXT: ret ptr [[CALL]]
54 %call = musttail call ptr @memccpy(ptr %dst, ptr @hello, i32 111, i64 10) ; 111 is 'o'
59 define void @memccpy_to_memcpy4(ptr %dst) {
60 ; CHECK-LABEL: @memccpy_to_memcpy4(
61 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(11) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(11) @hello, i64 11, i1 false)
62 ; CHECK-NEXT: ret void
64 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 0, i64 12)
68 define ptr @memccpy_to_memcpy5(ptr %dst) {
69 ; CHECK-LABEL: @memccpy_to_memcpy5(
70 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(7) @hello, i64 7, i1 false)
71 ; CHECK-NEXT: ret ptr null
73 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 7)
77 define ptr @memccpy_to_memcpy5_tail(ptr %dst) {
78 ; CHECK-LABEL: @memccpy_to_memcpy5_tail(
79 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(7) @hello, i64 7, i1 false)
80 ; CHECK-NEXT: ret ptr null
82 %call = tail call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 7)
86 define ptr @memccpy_to_memcpy5_musttail(ptr %dst, ptr %x, i32 %y, i64 %z) {
87 ; CHECK-LABEL: @memccpy_to_memcpy5_musttail(
88 ; CHECK-NEXT: [[CALL:%.*]] = musttail call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 114, i64 7)
89 ; CHECK-NEXT: ret ptr [[CALL]]
91 %call = musttail call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 7)
95 define ptr @memccpy_to_memcpy6(ptr %dst) {
96 ; CHECK-LABEL: @memccpy_to_memcpy6(
97 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(6) @hello, i64 6, i1 false)
98 ; CHECK-NEXT: ret ptr null
100 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 6);
104 define ptr @memccpy_to_memcpy7(ptr %dst) {
105 ; CHECK-LABEL: @memccpy_to_memcpy7(
106 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(5) @hello, i64 5, i1 false)
107 ; CHECK-NEXT: ret ptr null
109 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 115, i64 5) ; 115 is 's'
113 define ptr @memccpy_to_memcpy8(ptr %dst) {
114 ; CHECK-LABEL: @memccpy_to_memcpy8(
115 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(11) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(11) @hello, i64 11, i1 false)
116 ; CHECK-NEXT: ret ptr null
118 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 115, i64 11) ; 115 is 's'
122 define ptr @memccpy_to_memcpy9(ptr %dst, i64 %n) {
123 ; CHECK-LABEL: @memccpy_to_memcpy9(
124 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(12) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(12) @StopCharAfterNulTerminator, i64 12, i1 false)
125 ; CHECK-NEXT: [[CALL:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 12
126 ; CHECK-NEXT: ret ptr [[CALL]]
128 %call = call ptr @memccpy(ptr %dst, ptr @StopCharAfterNulTerminator, i32 120, i64 15) ; 120 is 'x'
132 define ptr @memccpy_to_memcpy10(ptr %dst, i64 %n) {
133 ; CHECK-LABEL: @memccpy_to_memcpy10(
134 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(11) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(11) @StringWithEOF, i64 11, i1 false)
135 ; CHECK-NEXT: [[CALL:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 11
136 ; CHECK-NEXT: ret ptr [[CALL]]
138 %call = call ptr @memccpy(ptr %dst, ptr @StringWithEOF, i32 255, i64 15)
142 define ptr @memccpy_to_memcpy11(ptr %dst, i64 %n) {
143 ; CHECK-LABEL: @memccpy_to_memcpy11(
144 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(11) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(11) @StringWithEOF, i64 11, i1 false)
145 ; CHECK-NEXT: [[CALL:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 11
146 ; CHECK-NEXT: ret ptr [[CALL]]
148 %call = call ptr @memccpy(ptr %dst, ptr @StringWithEOF, i32 -1, i64 15)
152 define ptr @memccpy_to_memcpy12(ptr %dst, i64 %n) {
153 ; CHECK-LABEL: @memccpy_to_memcpy12(
154 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(11) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(11) @StringWithEOF, i64 11, i1 false)
155 ; CHECK-NEXT: [[CALL:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 11
156 ; CHECK-NEXT: ret ptr [[CALL]]
158 %call = call ptr @memccpy(ptr %dst, ptr @StringWithEOF, i32 1023, i64 15)
162 define ptr @memccpy_to_null(ptr %dst, ptr %src, i32 %c) {
163 ; CHECK-LABEL: @memccpy_to_null(
164 ; CHECK-NEXT: ret ptr null
166 %call = call ptr @memccpy(ptr %dst, ptr %src, i32 %c, i64 0)
170 define void @memccpy_dst_src_same_retval_unused(ptr %dst, i32 %c, i64 %n) {
171 ; CHECK-LABEL: @memccpy_dst_src_same_retval_unused(
172 ; CHECK-NEXT: ret void
174 %call = call ptr @memccpy(ptr %dst, ptr %dst, i32 %c, i64 %n)
179 define ptr @unknown_src(ptr %dst, ptr %src) {
180 ; CHECK-LABEL: @unknown_src(
181 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr [[SRC:%.*]], i32 114, i64 12)
182 ; CHECK-NEXT: ret ptr [[CALL]]
184 %call = call ptr @memccpy(ptr %dst, ptr %src, i32 114, i64 12)
188 define ptr @unknown_stop_char(ptr %dst, i32 %c) {
189 ; CHECK-LABEL: @unknown_stop_char(
190 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 [[C:%.*]], i64 12)
191 ; CHECK-NEXT: ret ptr [[CALL]]
193 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 %c, i64 12)
197 define ptr @unknown_size_n(ptr %dst, i64 %n) {
198 ; CHECK-LABEL: @unknown_size_n(
199 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 114, i64 [[N:%.*]])
200 ; CHECK-NEXT: ret ptr [[CALL]]
202 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 %n)
206 define ptr @no_nul_terminator(ptr %dst, i64 %n) {
207 ; CHECK-LABEL: @no_nul_terminator(
208 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @StopCharAfterNulTerminator, i32 120, i64 [[N:%.*]])
209 ; CHECK-NEXT: ret ptr [[CALL]]
211 %call = call ptr @memccpy(ptr %dst, ptr @StopCharAfterNulTerminator, i32 120, i64 %n) ; 120 is 'x'
215 define ptr @possibly_valid_data_after_array(ptr %dst, i64 %n) {
216 ; CHECK-LABEL: @possibly_valid_data_after_array(
217 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @NoNulTerminator, i32 115, i64 [[N:%.*]])
218 ; CHECK-NEXT: ret ptr [[CALL]]
220 %call = call ptr @memccpy(ptr %dst, ptr @NoNulTerminator, i32 115, i64 %n) ; 115 is 's'
224 define ptr @possibly_valid_data_after_array2(ptr %dst, i64 %n) {
225 ; CHECK-LABEL: @possibly_valid_data_after_array2(
226 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 115, i64 [[N:%.*]])
227 ; CHECK-NEXT: ret ptr [[CALL]]
229 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 115, i64 %n) ; 115 is 's'
233 define ptr @possibly_valid_data_after_array3(ptr %dst) {
234 ; CHECK-LABEL: @possibly_valid_data_after_array3(
235 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 115, i64 12)
236 ; CHECK-NEXT: ret ptr [[CALL]]
238 %call = call ptr @memccpy(ptr %dst, ptr @hello, i32 115, i64 12) ; 115 is 's'
242 define ptr @memccpy_dst_src_same_retval_used(ptr %dst, i32 %c, i64 %n) {
243 ; CHECK-LABEL: @memccpy_dst_src_same_retval_used(
244 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @memccpy(ptr [[DST:%.*]], ptr [[DST]], i32 [[C:%.*]], i64 [[N:%.*]])
245 ; CHECK-NEXT: ret ptr [[CALL]]
247 %call = call ptr @memccpy(ptr %dst, ptr %dst, i32 %c, i64 %n)
251 define ptr @memccpy_to_memcpy_musttail(ptr %dst, ptr %x, i32 %y, i64 %z) {
252 ; CHECK-LABEL: @memccpy_to_memcpy_musttail(
253 ; CHECK-NEXT: [[CALL:%.*]] = musttail call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 114, i64 12)
254 ; CHECK-NEXT: ret ptr [[CALL]]
256 %call = musttail call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 12) ; 114 is 'r'
260 define ptr @memccpy_to_memcpy2_musttail(ptr %dst, ptr %x, i32 %y, i64 %z) {
261 ; CHECK-LABEL: @memccpy_to_memcpy2_musttail(
262 ; CHECK-NEXT: [[CALL:%.*]] = musttail call ptr @memccpy(ptr [[DST:%.*]], ptr nonnull @hello, i32 114, i64 8)
263 ; CHECK-NEXT: ret ptr [[CALL]]
265 %call = musttail call ptr @memccpy(ptr %dst, ptr @hello, i32 114, i64 8) ; 114 is 'r'