1 ; RUN: opt < %s -callsite-splitting -S | FileCheck %s
2 ; RUN: opt < %s -passes='function(callsite-splitting)' -S | FileCheck %s
4 ; CHECK-LABEL: @test_simple
6 ; CHECK-NEXT: br i1 undef, label %Header.split
7 ; CHECK-LABEL: Header.split:
8 ; CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 %v, i32 %p)
10 ; CHECK: br i1 %cmp, label %TBB.split
11 ; CHECK-LABEL: TBB.split:
12 ; CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 %v, i32 %p)
14 ; CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
15 ; CHECK: ret i32 %[[MERGED]]
16 define i32 @test_simple(i32* %a, i32 %v, i32 %p) {
18 br i1 undef, label %Tail, label %End
21 %cmp = icmp eq i32* %a, null
22 br i1 %cmp, label %Tail, label %End
25 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
32 ; CHECK-LABEL: @test_eq_eq_eq_untaken
33 ; CHECK-LABEL: Header:
34 ; CHECK: br i1 %tobool1, label %TBB1, label %Header.split
35 ; CHECK-LABEL: Header.split:
36 ; CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 %p)
38 ; CHECK: br i1 %cmp2, label %TBB2.split, label %End
39 ; CHECK-LABEL: TBB2.split:
40 ; CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 1, i32 99)
42 ; CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB2.split ]
43 ; CHECK: ret i32 %[[MERGED]]
44 define i32 @test_eq_eq_eq_untaken2(i32* %a, i32 %v, i32 %p) {
46 %tobool1 = icmp eq i32* %a, null
47 br i1 %tobool1, label %TBB1, label %Tail
50 %cmp1 = icmp eq i32 %v, 1
51 br i1 %cmp1, label %TBB2, label %End
54 %cmp2 = icmp eq i32 %p, 99
55 br i1 %cmp2, label %Tail, label %End
58 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
65 ; CHECK-LABEL: @test_eq_ne_eq_untaken
66 ; CHECK-LABEL: Header:
67 ; CHECK: br i1 %tobool1, label %TBB1, label %Header.split
68 ; CHECK-LABEL: Header.split:
69 ; CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 %p)
71 ; CHECK: br i1 %cmp2, label %TBB2.split, label %End
72 ; CHECK-LABEL: TBB2.split:
73 ; CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 %v, i32 99)
75 ; CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB2.split ]
76 ; CHECK: ret i32 %[[MERGED]]
77 define i32 @test_eq_ne_eq_untaken(i32* %a, i32 %v, i32 %p) {
79 %tobool1 = icmp eq i32* %a, null
80 br i1 %tobool1, label %TBB1, label %Tail
83 %cmp1 = icmp ne i32 %v, 1
84 br i1 %cmp1, label %TBB2, label %End
87 %cmp2 = icmp eq i32 %p, 99
88 br i1 %cmp2, label %Tail, label %End
91 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
98 ; CHECK-LABEL: @test_header_header2_tbb
100 ; CHECK:br i1 %tobool2, label %Header2.split, label %TBB1
101 ; CHECK-LABEL: Header2.split:
102 ; CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 10)
104 ; CHECK: br i1 %cmp2, label %TBB2.split, label %End
105 ; CHECK-LABEL: TBB2.split:
106 ; NOTE: CallSiteSplitting cannot infer that %a is null here, as it currently
107 ; only supports recording conditions along a single predecessor path.
108 ; CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 1, i32 99)
110 ; CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header2.split ], [ %[[CALL2]], %TBB2.split ]
111 ; CHECK: ret i32 %[[MERGED]]
112 define i32 @test_header_header2_tbb(i32* %a, i32 %v, i32 %p) {
114 %tobool1 = icmp eq i32* %a, null
115 br i1 %tobool1, label %TBB1, label %Header2
118 %tobool2 = icmp eq i32 %p, 10
119 br i1 %tobool2, label %Tail, label %TBB1
122 %cmp1 = icmp eq i32 %v, 1
123 br i1 %cmp1, label %TBB2, label %End
126 %cmp2 = icmp eq i32 %p, 99
127 br i1 %cmp2, label %Tail, label %End
130 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
137 define i32 @callee(i32* %a, i32 %v, i32 %p) {