1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -callbrprepare -S -o - | FileCheck %s
7 ; CHECK-NEXT: [[OUT:%.*]] = callbr i32 asm "# $0", "=r,!i"()
8 ; CHECK-NEXT: to label [[DIRECT:%.*]] [label %entry.indirect_crit_edge]
9 ; CHECK: entry.indirect_crit_edge:
10 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[OUT]])
11 ; CHECK-NEXT: br label [[INDIRECT:%.*]]
13 ; CHECK-NEXT: [[OUT2:%.*]] = callbr i32 asm "# $0", "=r,!i"()
14 ; CHECK-NEXT: to label [[DIRECT2:%.*]] [label %direct.indirect_crit_edge]
15 ; CHECK: direct.indirect_crit_edge:
16 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[OUT2]])
17 ; CHECK-NEXT: br label [[INDIRECT]]
19 ; CHECK-NEXT: ret i32 0
21 ; CHECK-NEXT: [[OUT3:%.*]] = phi i32 [ [[TMP0]], [[ENTRY_INDIRECT_CRIT_EDGE:%.*]] ], [ [[TMP1]], [[DIRECT_INDIRECT_CRIT_EDGE:%.*]] ]
22 ; CHECK-NEXT: ret i32 [[OUT3]]
25 %out = callbr i32 asm "# $0", "=r,!i"()
26 to label %direct [label %indirect]
28 %out2 = callbr i32 asm "# $0", "=r,!i"()
29 to label %direct2 [label %indirect]
33 %out3 = phi i32 [%out, %entry], [%out2, %direct]
37 ; Don't split edges unless they are critical, and callbr produces output, and
38 ; that output is used.
39 ; Here we have none of the above.
40 define i32 @dont_split0() {
41 ; CHECK-LABEL: @dont_split0(
43 ; CHECK-NEXT: callbr void asm "", "!i"()
44 ; CHECK-NEXT: to label [[X:%.*]] [label %y]
46 ; CHECK-NEXT: ret i32 42
48 ; CHECK-NEXT: ret i32 0
51 callbr void asm "", "!i"()
52 to label %x [label %y]
61 ; Don't split edges unless they are critical, and callbr produces output, and
62 ; that output is used.
63 ; Here we have output, but no critical edge.
64 ; That said, we ought to insert a callbr landing pad intrinsic call and update
65 ; to use the correct SSA value.
66 define i32 @dont_split1() {
67 ; CHECK-LABEL: @dont_split1(
69 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
70 ; CHECK-NEXT: to label [[X:%.*]] [label %y]
72 ; CHECK-NEXT: ret i32 42
74 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
75 ; CHECK-NEXT: ret i32 [[TMP1]]
78 %0 = callbr i32 asm "", "=r,!i"()
79 to label %x [label %y]
88 ; Don't split edges unless they are critical, and callbr produces output, and
89 ; that output is used.
90 ; Here we have a critical edge along an indirect branch, but no output.
91 define i32 @dont_split2() {
92 ; CHECK-LABEL: @dont_split2(
94 ; CHECK-NEXT: callbr void asm "", "!i"()
95 ; CHECK-NEXT: to label [[X:%.*]] [label %y]
97 ; CHECK-NEXT: br label [[Y:%.*]]
99 ; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ 0, [[X]] ], [ 42, [[ENTRY:%.*]] ]
100 ; CHECK-NEXT: ret i32 [[TMP0]]
103 callbr void asm "", "!i"()
104 to label %x [label %y]
110 %0 = phi i32 [ 0, %x ], [ 42, %entry ]
114 ; Don't split edges unless they are critical, and callbr produces output, and
115 ; that output is used.
116 ; Here we're missing a use.
117 define i32 @dont_split3() {
118 ; CHECK-LABEL: @dont_split3(
120 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
121 ; CHECK-NEXT: to label [[X:%.*]] [label %v]
123 ; CHECK-NEXT: br label [[V:%.*]]
125 ; CHECK-NEXT: ret i32 42
128 %0 = callbr i32 asm "", "=r,!i"() to label %x [label %v]
137 ; Don't split edges unless they are critical, and callbr produces output, and
138 ; that output is used.
139 ; Here we have output and a critical edge along an indirect branch.
140 define i32 @split_me0() {
141 ; CHECK-LABEL: @split_me0(
143 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
144 ; CHECK-NEXT: to label [[X:%.*]] [label %entry.y_crit_edge]
145 ; CHECK: entry.y_crit_edge:
146 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
147 ; CHECK-NEXT: br label [[Y:%.*]]
149 ; CHECK-NEXT: br label [[Y]]
151 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[ENTRY_Y_CRIT_EDGE:%.*]] ], [ 42, [[X]] ]
152 ; CHECK-NEXT: ret i32 [[TMP2]]
155 %0 = callbr i32 asm "", "=r,!i"()
156 to label %x [label %y]
162 %1 = phi i32 [ %0, %entry ], [ 42, %x ]
166 ; Here we have output and a critical edge along an indirect branch.
167 ; Ensure that if we repeat the indirect destination, that we only split it
169 define i32 @split_me1(i1 %z) {
170 ; CHECK-LABEL: @split_me1(
172 ; CHECK-NEXT: br i1 [[Z:%.*]], label [[W:%.*]], label [[V:%.*]]
174 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i,!i"()
175 ; CHECK-NEXT: to label [[X:%.*]] [label [[W_V_CRIT_EDGE:%.*]], label %w.v_crit_edge]
176 ; CHECK: w.v_crit_edge:
177 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
178 ; CHECK-NEXT: br label [[V]]
180 ; CHECK-NEXT: ret i32 42
182 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[W_V_CRIT_EDGE]] ], [ undef, [[ENTRY:%.*]] ]
183 ; CHECK-NEXT: ret i32 [[TMP2]]
186 br i1 %z, label %w, label %v
189 %0 = callbr i32 asm "", "=r,!i,!i"()
190 to label %x [label %v, label %v]
196 %1 = phi i32 [%0, %w], [%0, %w], [undef, %entry]
200 ; A more interessting case of @split_me1. Check that we still only split the
201 ; critical edge from w to v once.
202 define i32 @split_me2(i1 %z) {
203 ; CHECK-LABEL: @split_me2(
205 ; CHECK-NEXT: br i1 [[Z:%.*]], label [[W:%.*]], label [[V:%.*]]
207 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i,!i"()
208 ; CHECK-NEXT: to label [[X:%.*]] [label [[W_V_CRIT_EDGE:%.*]], label %w.v_crit_edge]
209 ; CHECK: w.v_crit_edge:
210 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
211 ; CHECK-NEXT: br label [[V]]
213 ; CHECK-NEXT: ret i32 42
215 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[W_V_CRIT_EDGE]] ], [ 42, [[ENTRY:%.*]] ]
216 ; CHECK-NEXT: ret i32 [[TMP2]]
219 br i1 %z, label %w, label %v
222 %0 = callbr i32 asm "", "=r,!i,!i"()
223 to label %x [label %v, label %v]
229 %1 = phi i32 [ %0, %w ], [ 42, %entry ], [ %0, %w ]
233 ; Here we have a diamond with no phi.
234 define i32 @dont_split4() {
235 ; CHECK-LABEL: @dont_split4(
237 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
238 ; CHECK-NEXT: to label [[X:%.*]] [label %y]
240 ; CHECK-NEXT: br label [[OUT:%.*]]
242 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
243 ; CHECK-NEXT: br label [[OUT]]
245 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[Y:%.*]] ], [ [[TMP0]], [[X]] ]
246 ; CHECK-NEXT: ret i32 [[TMP2]]
249 %0 = callbr i32 asm "", "=r,!i"()
250 to label %x [label %y]
262 ; Triangle with no phi.
263 define i32 @dont_split5() {
264 ; CHECK-LABEL: @dont_split5(
266 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
267 ; CHECK-NEXT: to label [[OUT:%.*]] [label %y]
269 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
270 ; CHECK-NEXT: br label [[OUT]]
272 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[Y:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
273 ; CHECK-NEXT: ret i32 [[TMP2]]
276 %0 = callbr i32 asm "", "=r,!i"()
277 to label %out [label %y]
286 ; Triangle the other way with no phi.
287 define i32 @split_me3() {
288 ; CHECK-LABEL: @split_me3(
290 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
291 ; CHECK-NEXT: to label [[Y:%.*]] [label %entry.out_crit_edge]
292 ; CHECK: entry.out_crit_edge:
293 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
294 ; CHECK-NEXT: br label [[OUT:%.*]]
296 ; CHECK-NEXT: br label [[OUT]]
298 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[ENTRY_OUT_CRIT_EDGE:%.*]] ], [ [[TMP0]], [[Y]] ]
299 ; CHECK-NEXT: ret i32 [[TMP2]]
302 %0 = callbr i32 asm "", "=r,!i"()
303 to label %y [label %out]
312 ; Test callbr looping back on itself.
313 define i32 @dont_split6(i32 %0) {
314 ; CHECK-LABEL: @dont_split6(
316 ; CHECK-NEXT: br label [[LOOP:%.*]]
318 ; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ [[TMP0:%.*]], [[ENTRY:%.*]] ], [ [[TMP3:%.*]], [[LOOP_LOOP_CRIT_EDGE:%.*]] ]
319 ; CHECK-NEXT: [[TMP2:%.*]] = callbr i32 asm "", "=r,0,!i"(i32 [[TMP1]])
320 ; CHECK-NEXT: to label [[EXIT:%.*]] [label %loop.loop_crit_edge]
321 ; CHECK: loop.loop_crit_edge:
322 ; CHECK-NEXT: [[TMP3]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP2]])
323 ; CHECK-NEXT: br label [[LOOP]]
325 ; CHECK-NEXT: ret i32 0
330 %1 = phi i32 [%0, %entry], [%2, %loop]
331 %2 = callbr i32 asm "", "=r,0,!i"(i32 %1) to label %exit [label %loop]
336 ; Test same direct+indirect dest no phi.
337 define i32 @split_me4() {
338 ; CHECK-LABEL: @split_me4(
340 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
341 ; CHECK-NEXT: to label [[SAME:%.*]] [label %entry.same_crit_edge]
342 ; CHECK: entry.same_crit_edge:
343 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
344 ; CHECK-NEXT: br label [[SAME]]
346 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[ENTRY_SAME_CRIT_EDGE:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
347 ; CHECK-NEXT: ret i32 [[TMP2]]
350 %0 = callbr i32 asm "", "=r,!i"() to label %same [label %same]
355 ; Test same direct+indirect dest w/ phi.
356 define i32 @split_me5() {
357 ; CHECK-LABEL: @split_me5(
359 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
360 ; CHECK-NEXT: to label [[SAME:%.*]] [label %entry.same_crit_edge]
361 ; CHECK: entry.same_crit_edge:
362 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
363 ; CHECK-NEXT: br label [[SAME]]
365 ; CHECK-NEXT: [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[ENTRY_SAME_CRIT_EDGE:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
366 ; CHECK-NEXT: ret i32 [[TMP2]]
369 %0 = callbr i32 asm "", "=r,!i"() to label %same [label %same]
371 %1 = phi i32 [%0, %entry], [%0, %entry]
375 ; "The Devil's cross" (i.e. two asm goto with conflicting physreg constraints
376 ; going to the same destination).
377 define i64 @split_me6() {
378 ; CHECK-LABEL: @split_me6(
380 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i64 asm "# $0 $1", "={dx},!i"()
381 ; CHECK-NEXT: to label [[ASM_FALLTHROUGH:%.*]] [label %entry.foo_crit_edge]
382 ; CHECK: entry.foo_crit_edge:
383 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.callbr.landingpad.i64(i64 [[TMP0]])
384 ; CHECK-NEXT: br label [[FOO:%.*]]
385 ; CHECK: asm.fallthrough:
386 ; CHECK-NEXT: [[TMP2:%.*]] = callbr i64 asm "# $0 $1", "={bx},!i"()
387 ; CHECK-NEXT: to label [[FOO]] [label %asm.fallthrough.foo_crit_edge]
388 ; CHECK: asm.fallthrough.foo_crit_edge:
389 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.callbr.landingpad.i64(i64 [[TMP2]])
390 ; CHECK-NEXT: br label [[FOO]]
392 ; CHECK-NEXT: [[X_0:%.*]] = phi i64 [ [[TMP1]], [[ENTRY_FOO_CRIT_EDGE:%.*]] ], [ [[TMP3]], [[ASM_FALLTHROUGH_FOO_CRIT_EDGE:%.*]] ], [ [[TMP2]], [[ASM_FALLTHROUGH]] ]
393 ; CHECK-NEXT: ret i64 [[X_0]]
396 %0 = callbr i64 asm "# $0 $1", "={dx},!i"()
397 to label %asm.fallthrough [label %foo]
400 %1 = callbr i64 asm "# $0 $1", "={bx},!i"()
401 to label %foo [label %foo]
404 %x.0 = phi i64 [ %0, %entry ], [ %1, %asm.fallthrough ], [ %1, %asm.fallthrough ]
408 ; Test the result of the callbr having multiple uses to avoid iterator
409 ; invalidation bugs in CallBrPrepare::UpdateSSA.
410 define i32 @multiple_split() {
411 ; CHECK-LABEL: @multiple_split(
413 ; CHECK-NEXT: [[TMP0:%.*]] = callbr i32 asm "", "=r,!i"()
414 ; CHECK-NEXT: to label [[X:%.*]] [label %y]
416 ; CHECK-NEXT: ret i32 42
418 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.callbr.landingpad.i32(i32 [[TMP0]])
419 ; CHECK-NEXT: [[TMP2:%.*]] = add nsw i32 [[TMP1]], [[TMP1]]
420 ; CHECK-NEXT: ret i32 [[TMP2]]
423 %0 = callbr i32 asm "", "=r,!i"()
424 to label %x [label %y]
430 %1 = add nsw i32 %0, %0