1 ; RUN: opt < %s -callsite-splitting -S | FileCheck %s
2 ; RUN: opt < %s -passes='function(callsite-splitting)' -S | FileCheck %s
4 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5 target triple = "aarch64-linaro-linux-gnueabi"
7 ;CHECK-LABEL: @test_eq_eq
10 ;CHECK: br i1 %tobool1, label %Header.split, label %TBB
11 ;CHECK-LABEL: Header.split:
12 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* null, i32 %v, i32 1)
14 ;CHECK: br i1 %cmp, label %TBB.split, label %End
15 ;CHECK-LABEL: TBB.split:
16 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* nonnull %a, i32 1, i32 2)
18 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
19 ;CHECK: ret i32 %[[MERGED]]
20 define i32 @test_eq_eq(i32* %a, i32 %v) {
22 %tobool1 = icmp eq i32* %a, null
23 br i1 %tobool1, label %Tail, label %TBB
26 %cmp = icmp eq i32 %v, 1
27 br i1 %cmp, label %Tail, label %End
30 %p = phi i32[1,%Header], [2, %TBB]
31 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
38 ;CHECK-LABEL: @test_eq_eq_eq
39 ;CHECK-LABEL: Header2.split:
40 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 %v, i32 10)
41 ;CHECK-LABEL: TBB.split:
42 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 1, i32 %p)
44 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header2.split ], [ %[[CALL2]], %TBB.split ]
45 ;CHECK: ret i32 %[[MERGED]]
46 define i32 @test_eq_eq_eq(i32* %a, i32 %v, i32 %p) {
48 %tobool1 = icmp eq i32* %a, null
49 br i1 %tobool1, label %Header2, label %End
52 %tobool2 = icmp eq i32 %p, 10
53 br i1 %tobool2, label %Tail, label %TBB
56 %cmp = icmp eq i32 %v, 1
57 br i1 %cmp, label %Tail, label %End
60 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
67 ;CHECK-LABEL: @test_eq_eq_eq_constrain_same_i32_arg
68 ;CHECK-LABEL: Header2.split:
69 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 222, i32 %p)
70 ;CHECK-LABEL: TBB.split:
71 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 333, i32 %p)
73 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header2.split ], [ %[[CALL2]], %TBB.split ]
74 ;CHECK: ret i32 %[[MERGED]]
75 define i32 @test_eq_eq_eq_constrain_same_i32_arg(i32* %a, i32 %v, i32 %p) {
77 %tobool1 = icmp eq i32 %v, 111
78 br i1 %tobool1, label %Header2, label %End
81 %tobool2 = icmp eq i32 %v, 222
82 br i1 %tobool2, label %Tail, label %TBB
85 %cmp = icmp eq i32 %v, 333
86 br i1 %cmp, label %Tail, label %End
89 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
96 ;CHECK-LABEL: @test_ne_eq
97 ;CHECK-LABEL: Header.split:
98 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 1)
99 ;CHECK-LABEL: TBB.split:
100 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 1, i32 2)
102 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
103 ;CHECK: ret i32 %[[MERGED]]
104 define i32 @test_ne_eq(i32* %a, i32 %v) {
106 %tobool1 = icmp ne i32* %a, null
107 br i1 %tobool1, label %Tail, label %TBB
110 %cmp = icmp eq i32 %v, 1
111 br i1 %cmp, label %Tail, label %End
114 %p = phi i32[1,%Header], [2, %TBB]
115 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
122 ;CHECK-LABEL: @test_ne_eq_ne
123 ;CHECK-LABEL: Header2.split:
124 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 10)
125 ;CHECK-LABEL: TBB.split:
126 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 %v, i32 %p)
128 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header2.split ], [ %[[CALL2]], %TBB.split ]
129 ;CHECK: ret i32 %[[MERGED]]
130 define i32 @test_ne_eq_ne(i32* %a, i32 %v, i32 %p) {
132 %tobool1 = icmp ne i32* %a, null
133 br i1 %tobool1, label %Header2, label %TBB
136 %tobool2 = icmp eq i32 %p, 10
137 br i1 %tobool2, label %Tail, label %TBB
140 %cmp = icmp ne i32 %v, 1
141 br i1 %cmp, label %Tail, label %End
144 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
151 ;CHECK-LABEL: @test_ne_ne
152 ;CHECK-LABEL: Header.split:
153 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 1)
154 ;CHECK-LABEL: TBB.split:
155 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 %v, i32 2)
157 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
158 ;CHECK: ret i32 %[[MERGED]]
159 define i32 @test_ne_ne(i32* %a, i32 %v) {
161 %tobool1 = icmp ne i32* %a, null
162 br i1 %tobool1, label %Tail, label %TBB
165 %cmp = icmp ne i32 %v, 1
166 br i1 %cmp, label %Tail, label %End
169 %p = phi i32[1,%Header], [2, %TBB]
170 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
177 ;CHECK-LABEL: @test_ne_ne_ne_constrain_same_pointer_arg
178 ;CHECK-LABEL: Header2.split:
179 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 %p)
180 ;CHECK-LABEL: TBB.split:
181 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 %v, i32 %p)
183 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header2.split ], [ %[[CALL2]], %TBB.split ]
184 ;CHECK: ret i32 %[[MERGED]]
185 define i32 @test_ne_ne_ne_constrain_same_pointer_arg(i32* %a, i32 %v, i32 %p, i32* %a2, i32* %a3) {
187 %tobool1 = icmp ne i32* %a, null
188 br i1 %tobool1, label %Header2, label %TBB
191 %tobool2 = icmp ne i32* %a, %a2
192 br i1 %tobool2, label %Tail, label %TBB
195 %cmp = icmp ne i32* %a, %a3
196 br i1 %cmp, label %Tail, label %End
199 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
208 ;CHECK-LABEL: @test_eq_eq_untaken
209 ;CHECK-LABEL: Header.split:
210 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 1)
211 ;CHECK-LABEL: TBB.split:
212 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 1, i32 2)
214 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
215 ;CHECK: ret i32 %[[MERGED]]
216 define i32 @test_eq_eq_untaken(i32* %a, i32 %v) {
218 %tobool1 = icmp eq i32* %a, null
219 br i1 %tobool1, label %TBB, label %Tail
222 %cmp = icmp eq i32 %v, 1
223 br i1 %cmp, label %Tail, label %End
226 %p = phi i32[1,%Header], [2, %TBB]
227 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
234 ;CHECK-LABEL: @test_eq_eq_eq_untaken
235 ;CHECK-LABEL: Header2.split:
236 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 10)
237 ;CHECK-LABEL: TBB.split:
238 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 1, i32 %p)
240 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header2.split ], [ %[[CALL2]], %TBB.split ]
241 ;CHECK: ret i32 %[[MERGED]]
242 define i32 @test_eq_eq_eq_untaken(i32* %a, i32 %v, i32 %p) {
244 %tobool1 = icmp eq i32* %a, null
245 br i1 %tobool1, label %TBB, label %Header2
248 %tobool2 = icmp eq i32 %p, 10
249 br i1 %tobool2, label %Tail, label %TBB
252 %cmp = icmp eq i32 %v, 1
253 br i1 %cmp, label %Tail, label %End
256 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
263 ;CHECK-LABEL: @test_ne_eq_untaken
264 ;CHECK-LABEL: Header.split:
265 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* null, i32 %v, i32 1)
266 ;CHECK-LABEL: TBB.split:
267 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* nonnull %a, i32 1, i32 2)
269 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
270 ;CHECK: ret i32 %[[MERGED]]
271 define i32 @test_ne_eq_untaken(i32* %a, i32 %v) {
273 %tobool1 = icmp ne i32* %a, null
274 br i1 %tobool1, label %TBB, label %Tail
277 %cmp = icmp eq i32 %v, 1
278 br i1 %cmp, label %Tail, label %End
281 %p = phi i32[1,%Header], [2, %TBB]
282 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
289 ;CHECK-LABEL: @test_ne_eq_ne_untaken
290 ;CHECK-LABEL: Header2.split:
291 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* null, i32 %v, i32 10)
292 ;CHECK-LABEL: TBB.split:
293 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 %v, i32 %p)
295 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header2.split ], [ %[[CALL2]], %TBB.split ]
296 ;CHECK: ret i32 %[[MERGED]]
297 define i32 @test_ne_eq_ne_untaken(i32* %a, i32 %v, i32 %p) {
299 %tobool1 = icmp ne i32* %a, null
300 br i1 %tobool1, label %TBB, label %Header2
303 %tobool2 = icmp eq i32 %p, 10
304 br i1 %tobool2, label %Tail, label %TBB
307 %cmp = icmp ne i32 %v, 1
308 br i1 %cmp, label %Tail, label %End
311 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
318 ;CHECK-LABEL: @test_ne_ne_untaken
319 ;CHECK-LABEL: Header.split:
320 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* null, i32 %v, i32 1)
321 ;CHECK-LABEL: TBB.split:
322 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* nonnull %a, i32 1, i32 2)
324 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
325 ;CHECK: ret i32 %[[MERGED]]
326 define i32 @test_ne_ne_untaken(i32* %a, i32 %v) {
328 %tobool1 = icmp ne i32* %a, null
329 br i1 %tobool1, label %TBB, label %Tail
332 %cmp = icmp ne i32 %v, 1
333 br i1 %cmp, label %End, label %Tail
336 %p = phi i32[1,%Header], [2, %TBB]
337 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
344 ;CHECK-LABEL: @test_nonconst_const_phi
345 ;CHECK-LABEL: Header.split:
346 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 %v, i32 1)
347 ;CHECK-LABEL: TBB.split:
348 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 1, i32 2)
350 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
351 ;CHECK: ret i32 %[[MERGED]]
352 define i32 @test_nonconst_const_phi(i32* %a, i32* %b, i32 %v) {
354 %tobool1 = icmp eq i32* %a, %b
355 br i1 %tobool1, label %Tail, label %TBB
358 %cmp = icmp eq i32 %v, 1
359 br i1 %cmp, label %Tail, label %End
362 %p = phi i32[1,%Header], [2, %TBB]
363 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
370 ;CHECK-LABEL: @test_nonconst_nonconst_phi
371 ;CHECK-LABEL: Header.split:
372 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 %v, i32 1)
373 ;CHECK-LABEL: TBB.split:
374 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 %v, i32 2)
376 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL2]], %TBB.split ], [ %[[CALL1]], %Header.split ]
377 ;CHECK: ret i32 %[[MERGED]]
378 define i32 @test_nonconst_nonconst_phi(i32* %a, i32* %b, i32 %v, i32 %v2) {
380 %tobool1 = icmp eq i32* %a, %b
381 br i1 %tobool1, label %Tail, label %TBB
384 %cmp = icmp eq i32 %v, %v2
385 br i1 %cmp, label %Tail, label %End
388 %p = phi i32[1,%Header], [2, %TBB]
389 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
396 ;CHECK-LABEL: @test_cfg_no_or_phi
397 ;CHECK-LABEL: TBB0.split
398 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 %v, i32 1)
399 ;CHECK-LABEL: TBB1.split:
400 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 %v, i32 2)
402 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL2]], %TBB1.split ], [ %[[CALL1]], %TBB0.split ]
403 ;CHECK: ret i32 %[[MERGED]]
404 define i32 @test_cfg_no_or_phi(i32* %a, i32 %v) {
406 br i1 undef, label %TBB0, label %TBB1
408 br i1 undef, label %Tail, label %End
410 br i1 undef, label %Tail, label %End
412 %p = phi i32[1,%TBB0], [2, %TBB1]
413 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
419 ;CHECK-LABEL: @test_nonconst_nonconst_phi_noncost
420 ;CHECK-NOT: Header.split:
421 ;CHECK-NOT: TBB.split:
423 ;CHECK: %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
425 define i32 @test_nonconst_nonconst_phi_noncost(i32* %a, i32* %b, i32 %v, i32 %v2) {
427 %tobool1 = icmp eq i32* %a, %b
428 br i1 %tobool1, label %Tail, label %TBB
431 %cmp = icmp eq i32 %v, %v2
432 br i1 %cmp, label %Tail, label %End
435 %p = phi i32[%v,%Header], [%v2, %TBB]
436 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
443 ;CHECK-LABEL: @test_3preds_constphi
444 ;CHECK-NOT: Header.split:
445 ;CHECK-NOT: TBB.split:
447 ;CHECK: %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
449 define i32 @test_3preds_constphi(i32* %a, i32 %v, i1 %c1, i1 %c2, i1 %c3) {
451 br i1 %c1, label %Tail, label %TBB1
454 br i1 %c2, label %Tail, label %TBB2
457 br i1 %c3, label %Tail, label %End
460 %p = phi i32[1,%Header], [2, %TBB1], [3, %TBB2]
461 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
468 ;CHECK-LABEL: @test_indirectbr_phi
469 ;CHECK-NOT: Header.split:
470 ;CHECK-NOT: TBB.split:
472 ;CHECK: %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
474 define i32 @test_indirectbr_phi(i8* %address, i32* %a, i32* %b, i32 %v) {
476 %indirect.goto.dest = select i1 undef, i8* blockaddress(@test_indirectbr_phi, %End), i8* %address
477 indirectbr i8* %indirect.goto.dest, [label %TBB, label %Tail]
480 %indirect.goto.dest2 = select i1 undef, i8* blockaddress(@test_indirectbr_phi, %End), i8* %address
481 indirectbr i8* %indirect.goto.dest2, [label %Tail, label %End]
484 %p = phi i32[1,%Header], [2, %TBB]
485 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
492 ;CHECK-LABEL: @test_cond_no_effect
493 ;CHECK-NOT: Header.split:
494 ;CHECK-NOT: TBB.split:
496 ;CHECK: %r = call i32 @callee(i32* %a, i32 %v, i32 0)
498 define i32 @test_cond_no_effect(i32* %a, i32 %v) {
500 %tobool1 = icmp eq i32* %a, null
501 br i1 %tobool1, label %Header, label %End
504 br i1 undef, label %Tail, label %TBB
507 br i1 undef, label %Tail, label %End
510 %r = call i32 @callee(i32* %a, i32 %v, i32 0)
517 ;CHECK-LABEL: @test_unreachable
518 ;CHECK-LABEL: Header.split:
519 ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 %v, i32 10)
520 ;CHECK-LABEL: TBB.split:
521 ;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 1, i32 %p)
523 ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Header.split ], [ %[[CALL2]], %TBB.split ]
524 ;CHECK: ret i32 %[[MERGED]]
525 define i32 @test_unreachable(i32* %a, i32 %v, i32 %p) {
529 %tobool2 = icmp eq i32 %p, 10
530 br i1 %tobool2, label %Tail, label %TBB
532 %cmp = icmp eq i32 %v, 1
533 br i1 %cmp, label %Tail, label %Header
535 %r = call i32 @callee(i32* %a, i32 %v, i32 %p)
541 define i32 @callee(i32* %a, i32 %v, i32 %p) {
543 %c = icmp ne i32* %a, null
544 br i1 %c, label %BB1, label %BB2
547 call void @dummy(i32* %a, i32 %p)
551 call void @dummy2(i32 %v, i32 %p)
558 declare void @dummy(i32*, i32)
559 declare void @dummy2(i32, i32)
561 ; Make sure we remove the non-nullness on constant paramater.
563 ;CHECK-LABEL: @caller2
564 ;CHECK-LABEL: Top1.split:
565 ;CHECK: call i32 @callee(i32* inttoptr (i64 4643 to i32*)
566 define void @caller2(i32 %c, i32* %a_elt, i32* %b_elt) {
571 %tobool1 = icmp eq i32* %a_elt, inttoptr (i64 4643 to i32*)
572 br i1 %tobool1, label %Top1, label %NextCond
575 %tobool2 = icmp ne i32* %a_elt, null
576 br i1 %tobool2, label %CallSiteBB, label %NextCond
579 %cmp = icmp ne i32* %b_elt, null
580 br i1 %cmp, label %CallSiteBB, label %End
583 call i32 @callee(i32* %a_elt, i32 %c, i32 %c)