1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2 ; Test that the strcpy library call simplifier also works when the string
3 ; libcall arguments are in a non-zero address space.
4 ; RUN: opt < %s -instcombine -S | FileCheck %s
5 target datalayout = "e-m:e-p200:128:128:128:64-p:64:64-A200-P200-G200"
7 @str = private unnamed_addr addrspace(200) constant [17 x i8] c"exactly 16 chars\00", align 1
9 declare i8 addrspace(200)* @strcpy(i8 addrspace(200)*, i8 addrspace(200)*) addrspace(200)
10 declare i8 addrspace(200)* @stpcpy(i8 addrspace(200)*, i8 addrspace(200)*) addrspace(200)
11 declare i8 addrspace(200)* @strncpy(i8 addrspace(200)*, i8 addrspace(200)*, i64) addrspace(200)
12 declare i8 addrspace(200)* @stpncpy(i8 addrspace(200)*, i8 addrspace(200)*, i64) addrspace(200)
14 define void @test_strcpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
15 ; CHECK-LABEL: define {{[^@]+}}@test_strcpy_to_memcpy
16 ; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0:#.*]] {
18 ; CHECK-NEXT: call addrspace(200) void @llvm.memcpy.p200i8.p200i8.i64(i8 addrspace(200)* noundef align 1 dereferenceable(17) [[DST]], i8 addrspace(200)* noundef align 1 dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17, i1 false)
19 ; CHECK-NEXT: ret void
22 %call = call i8 addrspace(200)* @strcpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0))
26 define void @test_stpcpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
27 ; CHECK-LABEL: define {{[^@]+}}@test_stpcpy_to_memcpy
28 ; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0]] {
30 ; CHECK-NEXT: call addrspace(200) void @llvm.memcpy.p200i8.p200i8.i128(i8 addrspace(200)* noundef align 1 dereferenceable(17) [[DST]], i8 addrspace(200)* noundef align 1 dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i128 17, i1 false)
31 ; CHECK-NEXT: ret void
34 %call = call i8 addrspace(200)* @stpcpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0))
38 define void @test_strncpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
39 ; CHECK-LABEL: define {{[^@]+}}@test_strncpy_to_memcpy
40 ; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0]] {
42 ; CHECK-NEXT: call addrspace(200) void @llvm.memcpy.p200i8.p200i8.i128(i8 addrspace(200)* noundef align 1 dereferenceable(17) [[DST]], i8 addrspace(200)* noundef align 1 dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i128 17, i1 false)
43 ; CHECK-NEXT: ret void
46 %call = call i8 addrspace(200)* @strncpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17)
50 ; Note: stpncpy is not handled by SimplifyLibcalls yet, so this should not be changed.
51 define void @test_stpncpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
52 ; CHECK-LABEL: define {{[^@]+}}@test_stpncpy_to_memcpy
53 ; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0]] {
55 ; CHECK-NEXT: [[CALL:%.*]] = call addrspace(200) i8 addrspace(200)* @stpncpy(i8 addrspace(200)* [[DST]], i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17)
56 ; CHECK-NEXT: ret void
59 %call = call i8 addrspace(200)* @stpncpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17)