1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 @hello = private constant [11 x i8] c"helloworld\00", align 1
6 declare i8* @memccpy(i8*, i8*, i32, i64)
8 define i8* @memccpy_to_memcpy(i8* %dst) {
9 ; CHECK-LABEL: @memccpy_to_memcpy(
10 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 12)
11 ; CHECK-NEXT: ret i8* [[CALL]]
13 %call = call i8* @memccpy(i8* %dst, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 12) ; 114 is 'r'
17 define i8* @memccpy_to_memcpy2(i8* %dst) {
18 ; CHECK-LABEL: @memccpy_to_memcpy2(
19 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 5)
20 ; CHECK-NEXT: ret i8* [[CALL]]
22 %call = call i8* @memccpy(i8* %dst, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 5)
26 define void @memccpy_to_memcpy3(i8* %dst) {
27 ; CHECK-LABEL: @memccpy_to_memcpy3(
28 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 5)
29 ; CHECK-NEXT: ret void
31 %call = call i8* @memccpy(i8* %dst, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 5)
35 define i8* @memccpy_to_null(i8* %dst, i8* %src, i32 %c) {
36 ; CHECK-LABEL: @memccpy_to_null(
37 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* [[SRC:%.*]], i32 [[C:%.*]], i64 0)
38 ; CHECK-NEXT: ret i8* [[CALL]]
40 %call = call i8* @memccpy(i8* %dst, i8* %src, i32 %c, i64 0)
44 define i8* @memccpy_to_null2(i8* %dst) {
45 ; CHECK-LABEL: @memccpy_to_null2(
46 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 115, i64 5)
47 ; CHECK-NEXT: ret i8* [[CALL]]
49 %call = call i8* @memccpy(i8* %dst, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 115, i64 5) ; 115 is 's'
54 define i8* @unknown_src(i8* %dst, i8* %src) {
55 ; CHECK-LABEL: @unknown_src(
56 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* [[SRC:%.*]], i32 114, i64 12)
57 ; CHECK-NEXT: ret i8* [[CALL]]
59 %call = call i8* @memccpy(i8* %dst, i8* %src, i32 114, i64 12)
63 define i8* @unknown_stop_char(i8* %dst, i32 %c) {
64 ; CHECK-LABEL: @unknown_stop_char(
65 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 [[C:%.*]], i64 12)
66 ; CHECK-NEXT: ret i8* [[CALL]]
68 %call = call i8* @memccpy(i8* %dst, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 %c, i64 12)
72 define i8* @unknown_size_n(i8* %dst, i64 %n) {
73 ; CHECK-LABEL: @unknown_size_n(
74 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @memccpy(i8* [[DST:%.*]], i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 [[N:%.*]])
75 ; CHECK-NEXT: ret i8* [[CALL]]
77 %call = call i8* @memccpy(i8* %dst, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @hello, i64 0, i64 0), i32 114, i64 %n)