xref: /llvm-project/llvm/test/Transforms/CallSiteSplitting/musttail.ll (revision 4abc820c667179e2bd72cb410185e7036b1d1cf4)
154c4609fSRoman Lebedev; RUN: opt < %s -passes=callsite-splitting -verify-dom-info -S | FileCheck %s
2cee313d2SEric Christopher
3cee313d2SEric Christopher;CHECK-LABEL: @caller
4cee313d2SEric Christopher;CHECK-LABEL: Top.split:
5*4abc820cSNikita Popov;CHECK: %ca1 = musttail call ptr @callee(ptr null, ptr %b)
6*4abc820cSNikita Popov;CHECK: %cb2 = bitcast ptr %ca1 to ptr
7*4abc820cSNikita Popov;CHECK: ret ptr %cb2
8cee313d2SEric Christopher;CHECK-LABEL: TBB.split
9*4abc820cSNikita Popov;CHECK: %ca3 = musttail call ptr @callee(ptr nonnull %a, ptr null)
10*4abc820cSNikita Popov;CHECK: %cb4 = bitcast ptr %ca3 to ptr
11*4abc820cSNikita Popov;CHECK: ret ptr %cb4
12*4abc820cSNikita Popovdefine ptr @caller(ptr %a, ptr %b) {
13cee313d2SEric ChristopherTop:
14*4abc820cSNikita Popov  %c = icmp eq ptr %a, null
15cee313d2SEric Christopher  br i1 %c, label %Tail, label %TBB
16cee313d2SEric ChristopherTBB:
17*4abc820cSNikita Popov  %c2 = icmp eq ptr %b, null
18cee313d2SEric Christopher  br i1 %c2, label %Tail, label %End
19cee313d2SEric ChristopherTail:
20*4abc820cSNikita Popov  %ca = musttail call ptr @callee(ptr %a, ptr %b)
21*4abc820cSNikita Popov  %cb = bitcast ptr %ca to ptr
22*4abc820cSNikita Popov  ret ptr %cb
23cee313d2SEric ChristopherEnd:
24*4abc820cSNikita Popov  ret ptr null
25cee313d2SEric Christopher}
26cee313d2SEric Christopher
27*4abc820cSNikita Popovdefine ptr @callee(ptr %a, ptr %b) noinline {
28*4abc820cSNikita Popov  ret ptr %a
29cee313d2SEric Christopher}
30cee313d2SEric Christopher
31cee313d2SEric Christopher;CHECK-LABEL: @no_cast_caller
32cee313d2SEric Christopher;CHECK-LABEL: Top.split:
33*4abc820cSNikita Popov;CHECK: %ca1 = musttail call ptr @callee(ptr null, ptr %b)
34*4abc820cSNikita Popov;CHECK: ret ptr %ca1
35cee313d2SEric Christopher;CHECK-LABEL: TBB.split
36*4abc820cSNikita Popov;CHECK: %ca2 = musttail call ptr @callee(ptr nonnull %a, ptr null)
37*4abc820cSNikita Popov;CHECK: ret ptr %ca2
38*4abc820cSNikita Popovdefine ptr @no_cast_caller(ptr %a, ptr %b) {
39cee313d2SEric ChristopherTop:
40*4abc820cSNikita Popov  %c = icmp eq ptr %a, null
41cee313d2SEric Christopher  br i1 %c, label %Tail, label %TBB
42cee313d2SEric ChristopherTBB:
43*4abc820cSNikita Popov  %c2 = icmp eq ptr %b, null
44cee313d2SEric Christopher  br i1 %c2, label %Tail, label %End
45cee313d2SEric ChristopherTail:
46*4abc820cSNikita Popov  %ca = musttail call ptr @callee(ptr %a, ptr %b)
47*4abc820cSNikita Popov  ret ptr %ca
48cee313d2SEric ChristopherEnd:
49*4abc820cSNikita Popov  ret ptr null
50cee313d2SEric Christopher}
51cee313d2SEric Christopher
52cee313d2SEric Christopher;CHECK-LABEL: @void_caller
53cee313d2SEric Christopher;CHECK-LABEL: Top.split:
54*4abc820cSNikita Popov;CHECK: musttail call void @void_callee(ptr null, ptr %b)
55cee313d2SEric Christopher;CHECK: ret void
56cee313d2SEric Christopher;CHECK-LABEL: TBB.split
57*4abc820cSNikita Popov;CHECK: musttail call void @void_callee(ptr nonnull %a, ptr null)
58cee313d2SEric Christopher;CHECK: ret void
59*4abc820cSNikita Popovdefine void @void_caller(ptr %a, ptr %b) {
60cee313d2SEric ChristopherTop:
61*4abc820cSNikita Popov  %c = icmp eq ptr %a, null
62cee313d2SEric Christopher  br i1 %c, label %Tail, label %TBB
63cee313d2SEric ChristopherTBB:
64*4abc820cSNikita Popov  %c2 = icmp eq ptr %b, null
65cee313d2SEric Christopher  br i1 %c2, label %Tail, label %End
66cee313d2SEric ChristopherTail:
67*4abc820cSNikita Popov  musttail call void @void_callee(ptr %a, ptr %b)
68cee313d2SEric Christopher  ret void
69cee313d2SEric ChristopherEnd:
70cee313d2SEric Christopher  ret void
71cee313d2SEric Christopher}
72cee313d2SEric Christopher
73*4abc820cSNikita Popovdefine void @void_callee(ptr %a, ptr %b) noinline {
74cee313d2SEric Christopher  ret void
75cee313d2SEric Christopher}
76cee313d2SEric Christopher
77cee313d2SEric Christopher;   Include a test with a larger CFG that exercises the DomTreeUpdater
78cee313d2SEric Christopher;   machinery a bit more.
79cee313d2SEric Christopher;CHECK-LABEL: @larger_cfg_caller
80cee313d2SEric Christopher;CHECK-LABEL: Top.split:
81*4abc820cSNikita Popov;CHECK: %r1 = musttail call ptr @callee(ptr null, ptr %b)
82*4abc820cSNikita Popov;CHECK: ret ptr %r1
83cee313d2SEric Christopher;CHECK-LABEL: TBB.split
84*4abc820cSNikita Popov;CHECK: %r2 = musttail call ptr @callee(ptr nonnull %a, ptr null)
85*4abc820cSNikita Popov;CHECK: ret ptr %r2
86*4abc820cSNikita Popovdefine ptr @larger_cfg_caller(ptr %a, ptr %b) {
87cee313d2SEric ChristopherTop:
88*4abc820cSNikita Popov  %cond1 = icmp eq ptr %a, null
89cee313d2SEric Christopher  br i1 %cond1, label %Tail, label %ExtraTest
90cee313d2SEric ChristopherExtraTest:
91*4abc820cSNikita Popov  %a0 = load i8, ptr %a
92cee313d2SEric Christopher  %cond2 = icmp eq i8 %a0, 0
93cee313d2SEric Christopher  br i1 %cond2, label %TBB_pred, label %End
94cee313d2SEric ChristopherTBB_pred:
95cee313d2SEric Christopher  br label %TBB
96cee313d2SEric ChristopherTBB:
97*4abc820cSNikita Popov  %cond3 = icmp eq ptr %b, null
98cee313d2SEric Christopher  br i1 %cond3, label %Tail, label %End
99cee313d2SEric ChristopherTail:
100*4abc820cSNikita Popov  %r = musttail call ptr @callee(ptr %a, ptr %b)
101*4abc820cSNikita Popov  ret ptr %r
102cee313d2SEric ChristopherEnd:
103*4abc820cSNikita Popov  ret ptr null
104cee313d2SEric Christopher}
105