blob: de4f5b607551113b1f4a86a0765e20f56d7a1819 [file] [log] [blame]
Dan Gohman4a63fad2010-08-14 00:29:42 +00001; RUN: opt -S -simplifycfg < %s | FileCheck %s
2
3; SimplifyCFG should eliminate redundant indirectbr edges.
4
5; CHECK: indbrtest0
6; CHECK: indirectbr i8* %t, [label %BB0, label %BB1, label %BB2]
7; CHECK: %x = phi i32 [ 0, %BB0 ], [ 1, %entry ]
8
9declare void @foo()
10declare void @A()
11declare void @B(i32)
12declare void @C()
13
14define void @indbrtest0(i8** %P, i8** %Q) {
15entry:
16 store i8* blockaddress(@indbrtest0, %BB0), i8** %P
17 store i8* blockaddress(@indbrtest0, %BB1), i8** %P
18 store i8* blockaddress(@indbrtest0, %BB2), i8** %P
19 call void @foo()
20 %t = load i8** %Q
21 indirectbr i8* %t, [label %BB0, label %BB1, label %BB2, label %BB0, label %BB1, label %BB2]
22BB0:
23 call void @A()
24 br label %BB1
25BB1:
26 %x = phi i32 [ 0, %BB0 ], [ 1, %entry ], [ 1, %entry ]
27 call void @B(i32 %x)
28 ret void
29BB2:
30 call void @C()
31 ret void
32}
33
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.
37
38; CHECK: indbrtest1
39; CHECK: br label %BB0
40
41define void @indbrtest1(i8** %P, i8** %Q) {
42entry:
43 store i8* blockaddress(@indbrtest1, %BB0), i8** %P
44 call void @foo()
45 %t = load i8** %Q
46 indirectbr i8* %t, [label %BB0, label %BB0]
47BB0:
48 call void @A()
49 ret void
50}
51
Dan Gohman250b7542010-08-16 14:41:14 +000052; SimplifyCFG should notice that BB0 does not have its address taken and
53; remove it from entry's successor list.
54
55; CHECK: indbrtest2
56; CHECK: entry:
57; CHECK-NEXT: unreachable
58
59define void @indbrtest2(i8* %t) {
60entry:
61 indirectbr i8* %t, [label %BB0, label %BB0]
62BB0:
63 ret void
64}