xref: /llvm-project/llvm/test/CodeGen/X86/callbr-asm-outputs-pred-succ.ll (revision a3a84c9e2511c06f1c47af76e26581b674149b82)
1; Tests that InstrEmitter::EmitMachineNode correctly sets predecessors and
2; successors.
3
4; RUN: llc -stop-after=finalize-isel -print-after=finalize-isel -mtriple=i686-- < %s 2>&1 | FileCheck %s
5
6; The block containting the INLINEASM_BR should have a fallthrough and its
7; indirect targets as its successors. Fallthrough should have 100% branch weight,
8; while the indirect targets have 0%.
9; CHECK: bb.0 (%ir-block.2):
10; CHECK-NEXT: successors: %bb.1(0x80000000), %bb.4(0x00000000); %bb.1(100.00%), %bb.4(0.00%)
11
12; The fallthrough is a block containing a second INLINEASM_BR. Check it has two successors,
13; and the the probability for fallthrough is 100%.
14; CHECK: bb.1 (%ir-block.4):
15; CHECK-NEXT: predecessors: %bb.0
16; CHECK-NEXT: successors: %bb.3(0x80000000), %bb.2(0x00000000); %bb.3(100.00%), %bb.2(0.00%)
17
18; Check the second INLINEASM_BR target block is preceded by the block with the
19; second INLINEASM_BR.
20; CHECK: bb.2 (%ir-block.7, machine-block-address-taken, inlineasm-br-indirect-target):
21; CHECK-NEXT: predecessors: %bb.1
22
23; Check the first INLINEASM_BR target block is predecessed by the block with
24; the first INLINEASM_BR.
25; CHECK: bb.4 (%ir-block.12, machine-block-address-taken, inlineasm-br-indirect-target):
26; CHECK-NEXT: predecessors: %bb.0
27
28@.str = private unnamed_addr constant [26 x i8] c"inline asm#1 returned %d\0A\00", align 1
29@.str.2 = private unnamed_addr constant [26 x i8] c"inline asm#2 returned %d\0A\00", align 1
30@str = private unnamed_addr constant [30 x i8] c"inline asm#1 caused exception\00", align 1
31@str.4 = private unnamed_addr constant [30 x i8] c"inline asm#2 caused exception\00", align 1
32
33; Function Attrs: nounwind uwtable
34define dso_local i32 @main(i32 %0, ptr nocapture readnone %1) #0 {
35  %3 = callbr i32 asm "jmp ${1:l}", "=r,!i,~{dirflag},~{fpsr},~{flags}"() #3
36          to label %4 [label %11]
37
384:                                                ; preds = %2
39  %5 = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i32 %3)
40  %6 = callbr i32 asm "jmp ${1:l}", "=r,!i,~{dirflag},~{fpsr},~{flags}"() #3
41          to label %9 [label %7]
42
437:                                                ; preds = %4
44  %8 = tail call i32 @puts(ptr nonnull dereferenceable(1) @str.4)
45  br label %13
46
479:                                                ; preds = %4
48  %10 = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str.2, i32 %6)
49  br label %13
50
5111:                                               ; preds = %2
52  %12 = tail call i32 @puts(ptr nonnull dereferenceable(1) @str)
53  br label %13
54
5513:                                               ; preds = %11, %9, %7
56  %14 = phi i32 [ 1, %7 ], [ 0, %9 ], [ 1, %11 ]
57  ret i32 %14
58}
59
60declare dso_local i32 @printf(ptr nocapture readonly, ...) local_unnamed_addr #1
61declare i32 @puts(ptr nocapture readonly) local_unnamed_addr #2
62