xref: /llvm-project/llvm/test/Transforms/CodeGenPrepare/ARM/tailcall-dup.ll (revision f1ec0d12bb0843f0deab83ef2b5cf1339cbc4f0b)
1; RUN: opt -passes='require<profile-summary>,function(codegenprepare)' -S < %s | FileCheck %s
2
3target triple = "armv8m.main-none-eabi"
4
5declare ptr @f0()
6declare ptr @f1()
7declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind
8declare void @llvm.lifetime.end.p0(i64, ptr nocapture) nounwind
9
10define ptr @tail_dup() {
11; CHECK-LABEL: tail_dup
12; CHECK: tail call ptr @f0()
13; CHECK-NEXT: ret ptr
14; CHECK: tail call ptr @f1()
15; CHECK-NEXT: ret ptr
16bb0:
17  %a = alloca i32
18  call void @llvm.lifetime.start.p0(i64 -1, ptr %a) nounwind
19  %tmp0 = tail call ptr @f0()
20  br label %return
21bb1:
22  %tmp1 = tail call ptr @f1()
23  br label %return
24return:
25  %retval = phi ptr [ %tmp0, %bb0 ], [ %tmp1, %bb1 ]
26  call void @llvm.lifetime.end.p0(i64 -1, ptr %a) nounwind
27  ret ptr %retval
28}
29
30define nonnull ptr @nonnull_dup() {
31; CHECK-LABEL: nonnull_dup
32; CHECK: tail call ptr @f0()
33; CHECK-NEXT: ret ptr
34; CHECK: tail call ptr @f1()
35; CHECK-NEXT: ret ptr
36bb0:
37  %tmp0 = tail call ptr @f0()
38  br label %return
39bb1:
40  %tmp1 = tail call ptr @f1()
41  br label %return
42return:
43  %retval = phi ptr [ %tmp0, %bb0 ], [ %tmp1, %bb1 ]
44  ret ptr %retval
45}
46
47define ptr @noalias_dup() {
48; CHECK-LABEL: noalias_dup
49; CHECK: tail call noalias ptr @f0()
50; CHECK-NEXT: ret ptr
51; CHECK: tail call noalias ptr @f1()
52; CHECK-NEXT: ret ptr
53bb0:
54  %tmp0 = tail call noalias ptr @f0()
55  br label %return
56bb1:
57  %tmp1 = tail call noalias ptr @f1()
58  br label %return
59return:
60  %retval = phi ptr [ %tmp0, %bb0 ], [ %tmp1, %bb1 ]
61  ret ptr %retval
62}
63
64; Use inreg as a way of testing that attributes (other than nonnull and
65; noalias) disable the tailcall duplication in cgp.
66
67define inreg ptr @inreg_nodup() {
68; CHECK-LABEL: inreg_nodup
69; CHECK: tail call ptr @f0()
70; CHECK-NEXT: br label %return
71; CHECK: tail call ptr @f1()
72; CHECK-NEXT: br label %return
73bb0:
74  %tmp0 = tail call ptr @f0()
75  br label %return
76bb1:
77  %tmp1 = tail call ptr @f1()
78  br label %return
79return:
80  %retval = phi ptr [ %tmp0, %bb0 ], [ %tmp1, %bb1 ]
81  ret ptr %retval
82}
83