1; RUN: opt -simplifycfg -S < %s | FileCheck %s
2
3declare void @bar() nounwind
4
5define i32 @test1(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
6entry:
7  %tobool = icmp eq i32 %b, 0
8  br i1 %tobool, label %if.else, label %if.then
9
10if.then:                                          ; preds = %entry
11  tail call void @bar() nounwind
12  br label %if.end7
13
14if.else:                                          ; preds = %entry
15  %tobool3 = icmp eq i32 %d, 0
16  br i1 %tobool3, label %if.end7, label %if.then4
17
18if.then4:                                         ; preds = %if.else
19  tail call void @bar() nounwind
20  br label %if.end7
21
22if.end7:                                          ; preds = %if.else, %if.then4, %if.then
23  %x.0 = phi i32* [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
24  %tmp9 = load i32, i32* %x.0
25  ret i32 %tmp9
26
27; CHECK-LABEL: @test1(
28; CHECK: if.else:
29; CHECK: br label %if.end7
30
31; CHECK: phi i32* [ %a, %if.then ], [ %c, %if.else ]
32}
33
34define i32 @test2(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
35entry:
36  %tobool = icmp eq i32 %b, 0
37  br i1 %tobool, label %if.else, label %if.then
38
39if.then:                                          ; preds = %entry
40  tail call void @bar() nounwind
41  br label %if.end7
42
43if.else:                                          ; preds = %entry
44  %tobool3 = icmp eq i32 %d, 0
45  br i1 %tobool3, label %if.end7, label %if.then4
46
47if.then4:                                         ; preds = %if.else
48  tail call void @bar() nounwind
49  br label %if.end7
50
51if.end7:                                          ; preds = %if.else, %if.then4, %if.then
52  %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
53  %tmp9 = load i32, i32* %x.0
54  ret i32 %tmp9
55; CHECK-LABEL: @test2(
56; CHECK: if.else:
57; CHECK: unreachable
58
59; CHECK-NOT: phi
60}
61
62define i32 @test3(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
63entry:
64  %tobool = icmp eq i32 %b, 0
65  br i1 %tobool, label %if.else, label %if.then
66
67if.then:                                          ; preds = %entry
68  tail call void @bar() nounwind
69  br label %if.end7
70
71if.else:                                          ; preds = %entry
72  %tobool3 = icmp eq i32 %d, 0
73  br i1 %tobool3, label %if.end7, label %if.then4
74
75if.then4:                                         ; preds = %if.else
76  tail call void @bar() nounwind
77  br label %if.end7
78
79if.end7:                                          ; preds = %if.else, %if.then4, %if.then
80  %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
81  tail call void @bar() nounwind
82  %tmp9 = load i32, i32* %x.0
83  ret i32 %tmp9
84; CHECK-LABEL: @test3(
85; CHECK: if.end7:
86; CHECK: phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
87}
88
89define i32 @test4(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
90entry:
91  %tobool = icmp eq i32 %b, 0
92  br i1 %tobool, label %if.else, label %if.then
93
94if.then:                                          ; preds = %entry
95  tail call void @bar() nounwind
96  br label %if.end7
97
98if.else:                                          ; preds = %entry
99  %tobool3 = icmp eq i32 %d, 0
100  br i1 %tobool3, label %if.end7, label %if.then4
101
102if.then4:                                         ; preds = %if.else
103  tail call void @bar() nounwind
104  br label %if.end7
105
106if.end7:                                          ; preds = %if.else, %if.then4, %if.then
107  %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
108  %gep = getelementptr i32, i32* %x.0, i32 10
109  %tmp9 = load i32, i32* %gep
110  %tmp10 = or i32 %tmp9, 1
111  store i32 %tmp10, i32* %gep
112  ret i32 %tmp9
113; CHECK-LABEL: @test4(
114; CHECK-NOT: phi
115}
116