1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
; RUN: opt -S -simplifycfg < %s | FileCheck %s
; SimplifyCFG should eliminate redundant indirectbr edges.
; CHECK: indbrtest0
; CHECK: indirectbr i8* %t, [label %BB0, label %BB1, label %BB2]
; CHECK: %x = phi i32 [ 0, %BB0 ], [ 1, %entry ]
declare void @foo()
declare void @A()
declare void @B(i32)
declare void @C()
define void @indbrtest0(i8** %P, i8** %Q) {
entry:
store i8* blockaddress(@indbrtest0, %BB0), i8** %P
store i8* blockaddress(@indbrtest0, %BB1), i8** %P
store i8* blockaddress(@indbrtest0, %BB2), i8** %P
call void @foo()
%t = load i8** %Q
indirectbr i8* %t, [label %BB0, label %BB1, label %BB2, label %BB0, label %BB1, label %BB2]
BB0:
call void @A()
br label %BB1
BB1:
%x = phi i32 [ 0, %BB0 ], [ 1, %entry ], [ 1, %entry ]
call void @B(i32 %x)
ret void
BB2:
call void @C()
ret void
}
; SimplifyCFG should convert the indirectbr into a directbr. It would be even
; better if it removed the branch altogether, but simplifycfdg currently misses
; that because the predecessor is the entry block.
; CHECK: indbrtest1
; CHECK: br label %BB0
define void @indbrtest1(i8** %P, i8** %Q) {
entry:
store i8* blockaddress(@indbrtest1, %BB0), i8** %P
call void @foo()
%t = load i8** %Q
indirectbr i8* %t, [label %BB0, label %BB0]
BB0:
call void @A()
ret void
}
; SimplifyCFG should notice that BB0 does not have its address taken and
; remove it from entry's successor list.
; CHECK: indbrtest2
; CHECK: entry:
; CHECK-NEXT: unreachable
define void @indbrtest2(i8* %t) {
entry:
indirectbr i8* %t, [label %BB0, label %BB0]
BB0:
ret void
}
|