1; RUN: opt < %s -callsite-splitting -inline -instcombine -jump-threading -S | FileCheck %s
2; RUN: opt < %s  -passes='function(callsite-splitting),cgscc(inline),function(instcombine,jump-threading)' -S | FileCheck %s
3
4target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5target triple = "aarch64-linaro-linux-gnueabi"
6
7%struct.bitmap = type { i32, %struct.bitmap* }
8
9;CHECK-LABEL: @caller
10;CHECK-LABEL: Top.split:
11;CHECK: call void @callee(%struct.bitmap* null, %struct.bitmap* null, %struct.bitmap* %b_elt, i1 false)
12;CHECK-LABEL: NextCond:
13;CHECK: br {{.*}} label %callee.exit
14;CHECK-LABEL: callee.exit:
15;CHECK: call void @dummy2(%struct.bitmap* %a_elt)
16
17define void @caller(i1 %c, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt) {
18entry:
19  br label %Top
20
21Top:
22  %tobool1 = icmp eq %struct.bitmap* %a_elt, null
23  br i1 %tobool1, label %CallSiteBB, label %NextCond
24
25NextCond:
26  %cmp = icmp ne %struct.bitmap* %b_elt, null
27  br i1 %cmp, label %CallSiteBB, label %End
28
29CallSiteBB:
30  %p = phi i1 [0, %Top], [%c, %NextCond]
31  call void @callee(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt, i1 %p)
32  br label %End
33
34End:
35  ret void
36}
37
38define void @callee(%struct.bitmap* %dst_elt, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt, i1 %c) {
39entry:
40  %tobool = icmp ne %struct.bitmap* %a_elt, null
41  %tobool1 = icmp ne %struct.bitmap* %b_elt, null
42  %or.cond = and i1 %tobool, %tobool1
43  br i1 %or.cond, label %Cond, label %Big
44
45Cond:
46  %cmp = icmp eq %struct.bitmap*  %dst_elt, %a_elt
47  br i1 %cmp, label %Small, label %Big
48
49Small:
50  call void @dummy2(%struct.bitmap* %a_elt)
51  br label %End
52
53Big:
54  call void @dummy1(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt)
55  call void @dummy1(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt)
56  call void @dummy1(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt)
57  call void @dummy1(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt)
58  call void @dummy1(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt)
59  call void @dummy1(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt)
60  call void @dummy1(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %a_elt)
61  br label %End
62
63End:
64  ret void
65}
66
67declare void @dummy2(%struct.bitmap*)
68declare void @dummy1(%struct.bitmap*, %struct.bitmap*, %struct.bitmap*, %struct.bitmap*, %struct.bitmap*, %struct.bitmap*)
69
70
71;CHECK-LABEL: @caller2
72;CHECK-LABEL: Top.split:
73;CHECK: call void @dummy4()
74;CHECK-LABEL: NextCond.split:
75;CHECK: call void @dummy3()
76;CheCK-LABEL: CallSiteBB:
77;CHECK: %phi.call = phi i1 [ true, %NextCond.split ], [ false, %Top.split ]
78;CHECK: call void @foo(i1 %phi.call)
79define void @caller2(i1 %c, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt, %struct.bitmap* %c_elt) {
80entry:
81  br label %Top
82
83Top:
84  %tobool1 = icmp eq %struct.bitmap* %a_elt, %b_elt
85  br i1 %tobool1, label %CallSiteBB, label %NextCond
86
87NextCond:
88  %cmp = icmp ne %struct.bitmap* %b_elt, %c_elt
89  br i1 %cmp, label %CallSiteBB, label %End
90
91CallSiteBB:
92  %phi = phi i1 [0, %Top],[1, %NextCond]
93  %u = call i1 @callee2(i1 %phi)
94  call void @foo(i1 %u)
95  br label %End
96
97End:
98  ret void
99}
100
101define i1 @callee2(i1 %b) {
102entry:
103  br i1 %b, label %BB1, label %BB2
104
105BB1:
106  call void @dummy3()
107  br label %End
108
109BB2:
110  call void @dummy4()
111  br label %End
112
113End:
114  ret i1 %b
115}
116
117declare void @dummy3()
118declare void @dummy4()
119declare void @foo(i1)
120