xref: /llvm-project/llvm/test/CodeGen/AArch64/tailcall-string-rvo.ll (revision 5ddce70ef0e5a641d7fea95e31fc5e2439cb98cb)
1; RUN: llc -relocation-model=static -verify-machineinstrs -O2 < %s | FileCheck %s
2; RUN: llc -relocation-model=static -verify-machineinstrs -global-isel -O2 < %s | FileCheck %s
3
4; The call to function TestBar should be a tail call, when in C++ the string
5; `ret` is RVO returned.
6; string TestFoo() {
7;   string ret = undef;
8;   TestBar(&ret);  // tail call optimized
9;   return ret;
10; }
11
12target triple = "aarch64-linux-gnu"
13
14%class.basic_string.11.42.73 = type { %"class.__gnu_cxx::__versa_string.10.41.72" }
15%"class.__gnu_cxx::__versa_string.10.41.72" = type { %"class.__gnu_cxx::__sso_string_base.9.40.71" }
16%"class.__gnu_cxx::__sso_string_base.9.40.71" = type { %"struct.__gnu_cxx::__vstring_utility<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider.7.38.69", i64, %union.anon.8.39.70 }
17%"struct.__gnu_cxx::__vstring_utility<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider.7.38.69" = type { ptr }
18%union.anon.8.39.70 = type { i64, [8 x i8] }
19
20declare void @TestBaz(ptr noalias sret(%class.basic_string.11.42.73) %arg)
21
22define void @TestBar(ptr noalias sret(%class.basic_string.11.42.73) %arg) {
23bb:
24  call void @TestBaz(ptr noalias sret(%class.basic_string.11.42.73) %arg)
25  ret void
26}
27
28define void @TestFoo(ptr noalias sret(%class.basic_string.11.42.73) %arg) {
29; CHECK-LABEL: TestFoo:
30; CHECK: b TestBar
31bb:
32  %tmp = getelementptr inbounds %class.basic_string.11.42.73, ptr %arg, i64 0, i32 0, i32 0, i32 2
33  store ptr %tmp, ptr %arg, align 8
34  tail call void @llvm.memcpy.p0.p0.i64(ptr %tmp, ptr nonnull undef, i64 13, i1 false)
35  %tmp3 = getelementptr inbounds %class.basic_string.11.42.73, ptr %arg, i64 0, i32 0, i32 0, i32 1
36  store i64 13, ptr %tmp3, align 8
37  %tmp4 = getelementptr inbounds %class.basic_string.11.42.73, ptr %arg, i64 0, i32 0, i32 0, i32 2, i32 1, i64 5
38  store i8 0, ptr %tmp4, align 1
39  tail call void @TestBar(ptr noalias sret(%class.basic_string.11.42.73) %arg)
40  ret void
41}
42
43; Function Attrs: argmemonly nounwind
44declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture readonly, i64, i1) #0
45
46attributes #0 = { argmemonly nounwind }
47