1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-- -O3 | FileCheck %s
4 ; Tests for using callbr as an asm-goto wrapper
6 ; Test 1 - fallthrough label gets removed, but the fallthrough code that is
7 ; unreachable due to asm ending on a jmp is still left in.
8 define i32 @test1(i32 %a) {
10 ; CHECK: # %bb.0: # %entry
11 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
12 ; CHECK-NEXT: addl $4, %eax
14 ; CHECK-NEXT: xorl %eax, %eax
15 ; CHECK-NEXT: jmp .Ltmp0
17 ; CHECK-NEXT: .LBB0_1: # %normal
18 ; CHECK-NEXT: xorl %eax, %eax
20 ; CHECK-NEXT: .Ltmp0: # Block address taken
21 ; CHECK-NEXT: .LBB0_2: # %fail
22 ; CHECK-NEXT: movl $1, %eax
26 callbr void asm "xorl $0, $0; jmp ${1:l}", "r,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@test1, %fail)) to label %normal [label %fail]
35 ; Test 2 - callbr terminates an unreachable block, function gets simplified
36 ; to a trivial zero return.
37 define i32 @test2(i32 %a) {
39 ; CHECK: # %bb.0: # %entry
40 ; CHECK-NEXT: xorl %eax, %eax
47 callbr void asm sideeffect "xorl $0, $0; jmp ${1:l}", "r,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@test2, %fail)) to label %normal [label %fail]
57 ; Test 3 - asm-goto implements a loop. The loop gets recognized, but many loop
58 ; transforms fail due to canonicalization having callbr exceptions. Trivial
59 ; blocks at labels 1 and 3 also don't get simplified due to callbr.
60 define dso_local i32 @test3(i32 %a) {
62 ; CHECK: # %bb.0: # %entry
63 ; CHECK-NEXT: .Ltmp1: # Block address taken
64 ; CHECK-NEXT: .LBB2_1: # %label01
65 ; CHECK-NEXT: # =>This Loop Header: Depth=1
66 ; CHECK-NEXT: # Child Loop BB2_2 Depth 2
67 ; CHECK-NEXT: # Child Loop BB2_3 Depth 3
68 ; CHECK-NEXT: # Child Loop BB2_4 Depth 4
69 ; CHECK-NEXT: .Ltmp2: # Block address taken
70 ; CHECK-NEXT: .LBB2_2: # %label02
71 ; CHECK-NEXT: # Parent Loop BB2_1 Depth=1
72 ; CHECK-NEXT: # => This Loop Header: Depth=2
73 ; CHECK-NEXT: # Child Loop BB2_3 Depth 3
74 ; CHECK-NEXT: # Child Loop BB2_4 Depth 4
75 ; CHECK-NEXT: addl $4, {{[0-9]+}}(%esp)
76 ; CHECK-NEXT: .Ltmp3: # Block address taken
77 ; CHECK-NEXT: .LBB2_3: # %label03
78 ; CHECK-NEXT: # Parent Loop BB2_1 Depth=1
79 ; CHECK-NEXT: # Parent Loop BB2_2 Depth=2
80 ; CHECK-NEXT: # => This Loop Header: Depth=3
81 ; CHECK-NEXT: # Child Loop BB2_4 Depth 4
82 ; CHECK-NEXT: .p2align 4, 0x90
83 ; CHECK-NEXT: .Ltmp4: # Block address taken
84 ; CHECK-NEXT: .LBB2_4: # %label04
85 ; CHECK-NEXT: # Parent Loop BB2_1 Depth=1
86 ; CHECK-NEXT: # Parent Loop BB2_2 Depth=2
87 ; CHECK-NEXT: # Parent Loop BB2_3 Depth=3
88 ; CHECK-NEXT: # => This Inner Loop Header: Depth=4
90 ; CHECK-NEXT: jmp .Ltmp1
91 ; CHECK-NEXT: jmp .Ltmp2
92 ; CHECK-NEXT: jmp .Ltmp3
94 ; CHECK-NEXT: .LBB2_5: # %normal0
95 ; CHECK-NEXT: # in Loop: Header=BB2_4 Depth=4
97 ; CHECK-NEXT: jmp .Ltmp1
98 ; CHECK-NEXT: jmp .Ltmp2
99 ; CHECK-NEXT: jmp .Ltmp3
100 ; CHECK-NEXT: jmp .Ltmp4
101 ; CHECK-NEXT: #NO_APP
102 ; CHECK-NEXT: .LBB2_6: # %normal1
103 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
106 %a.addr = alloca i32, align 4
107 store i32 %a, i32* %a.addr, align 4
110 label01: ; preds = %normal0, %label04, %entry
113 label02: ; preds = %normal0, %label04, %label01
114 %0 = load i32, i32* %a.addr, align 4
115 %add = add nsw i32 %0, 4
116 store i32 %add, i32* %a.addr, align 4
119 label03: ; preds = %normal0, %label04, %label02
122 label04: ; preds = %normal0, %label03
123 callbr void asm sideeffect "jmp ${0:l}; jmp ${1:l}; jmp ${2:l}", "X,X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test3, %label01), i8* blockaddress(@test3, %label02), i8* blockaddress(@test3, %label03))
124 to label %normal0 [label %label01, label %label02, label %label03]
126 normal0: ; preds = %label04
127 callbr void asm sideeffect "jmp ${0:l}; jmp ${1:l}; jmp ${2:l}; jmp ${3:l}", "X,X,X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test3, %label01), i8* blockaddress(@test3, %label02), i8* blockaddress(@test3, %label03), i8* blockaddress(@test3, %label04))
128 to label %normal1 [label %label01, label %label02, label %label03, label %label04]
130 normal1: ; preds = %normal0
131 %1 = load i32, i32* %a.addr, align 4