1 ; RUN: opt -S -simplifycfg < %s | FileCheck %s
3 ; SimplifyCFG should eliminate redundant indirectbr edges.
6 ; CHECK: indirectbr i8* %t, [label %BB0, label %BB1, label %BB2]
7 ; CHECK: %x = phi i32 [ 0, %BB0 ], [ 1, %entry ]
14 define void @indbrtest0(i8** %P, i8** %Q) {
16 store i8* blockaddress(@indbrtest0, %BB0), i8** %P
17 store i8* blockaddress(@indbrtest0, %BB1), i8** %P
18 store i8* blockaddress(@indbrtest0, %BB2), i8** %P
21 indirectbr i8* %t, [label %BB0, label %BB1, label %BB2, label %BB0, label %BB1, label %BB2]
26 %x = phi i32 [ 0, %BB0 ], [ 1, %entry ], [ 1, %entry ]
34 ; SimplifyCFG should convert the indirectbr into a directbr. It would be even
35 ; better if it removed the branch altogether, but simplifycfdg currently misses
36 ; that because the predecessor is the entry block.
39 ; CHECK: br label %BB0
41 define void @indbrtest1(i8** %P, i8** %Q) {
43 store i8* blockaddress(@indbrtest1, %BB0), i8** %P
46 indirectbr i8* %t, [label %BB0, label %BB0]
52 ; SimplifyCFG should notice that BB0 does not have its address taken and
53 ; remove it from entry's successor list.
57 ; CHECK-NEXT: unreachable
59 define void @indbrtest2(i8* %t) {
61 indirectbr i8* %t, [label %BB0, label %BB0]
67 ; Make sure the blocks in the next few tests aren't trivially removable as
68 ; successors by taking their addresses.
70 @anchor = constant [13 x i8*] [
71 i8* blockaddress(@indbrtest3, %L1), i8* blockaddress(@indbrtest3, %L2), i8* blockaddress(@indbrtest3, %L3),
72 i8* blockaddress(@indbrtest4, %L1), i8* blockaddress(@indbrtest4, %L2), i8* blockaddress(@indbrtest4, %L3),
73 i8* blockaddress(@indbrtest5, %L1), i8* blockaddress(@indbrtest5, %L2), i8* blockaddress(@indbrtest5, %L3), i8* blockaddress(@indbrtest5, %L4),
74 i8* blockaddress(@indbrtest6, %L1), i8* blockaddress(@indbrtest6, %L2), i8* blockaddress(@indbrtest6, %L3)
77 ; SimplifyCFG should turn the indirectbr into a conditional branch on the
78 ; condition of the select.
82 ; CHECK-NEXT: br i1 %cond, label %L1, label %L2
83 ; CHECK-NOT: indirectbr
86 define void @indbrtest3(i1 %cond, i8* %address) nounwind {
88 %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest3, %L1), i8* blockaddress(@indbrtest3, %L2)
89 indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
102 ; SimplifyCFG should turn the indirectbr into an unconditional branch to the
103 ; only possible destination.
104 ; As in @indbrtest1, it should really remove the branch entirely, but it doesn't
105 ; because it's in the entry block.
109 ; CHECK-NEXT: br label %L1
110 define void @indbrtest4(i1 %cond) nounwind {
112 %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest4, %L1), i8* blockaddress(@indbrtest4, %L1)
113 indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
126 ; SimplifyCFG should turn the indirectbr into an unreachable because neither
127 ; destination is listed as a successor.
131 ; CHECK-NEXT: unreachable
133 define void @indbrtest5(i1 %cond, i8* %anchor) nounwind {
135 %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest5, %L1), i8* blockaddress(@indbrtest5, %L2)
136 ; This needs to have more than one successor for this test, otherwise it gets
137 ; replaced with an unconditional branch to the single successor.
138 indirectbr i8* %indirect.goto.dest, [label %L3, label %L4]
152 ; This keeps blockaddresses not otherwise listed as successors from being zapped
153 ; before SimplifyCFG even looks at the indirectbr.
154 indirectbr i8* %anchor, [label %L1, label %L2]
157 ; The same as above, except the selected addresses are equal.
161 ; CHECK-NEXT: unreachable
163 define void @indbrtest6(i1 %cond, i8* %anchor) nounwind {
165 %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest6, %L1), i8* blockaddress(@indbrtest6, %L1)
166 ; This needs to have more than one successor for this test, otherwise it gets
167 ; replaced with an unconditional branch to the single successor.
168 indirectbr i8* %indirect.goto.dest, [label %L2, label %L3]
179 ; This keeps blockaddresses not otherwise listed as successors from being zapped
180 ; before SimplifyCFG even looks at the indirectbr.
181 indirectbr i8* %anchor, [label %L1, label %L2]