1; RUN: opt < %s -simplifycfg -S | FileCheck %s
2
3define void @test1(i1 %C, i1* %BP) {
4; CHECK-LABEL: @test1(
5; CHECK: entry:
6; CHECK-NEXT: ret void
7entry:
8        br i1 %C, label %T, label %F
9T:
10        store i1 %C, i1* %BP
11        unreachable
12F:
13        ret void
14}
15
16define void @test2() personality i32 (...)* @__gxx_personality_v0 {
17; CHECK-LABEL: @test2(
18; CHECK: entry:
19; CHECK-NEXT: call void @test2()
20; CHECK-NEXT: ret void
21entry:
22        invoke void @test2( )
23                        to label %N unwind label %U
24U:
25  %res = landingpad { i8* }
26          cleanup
27        unreachable
28N:
29        ret void
30}
31
32declare i32 @__gxx_personality_v0(...)
33
34define i32 @test3(i32 %v) {
35; CHECK-LABEL: @test3(
36; CHECK: entry:
37; CHECK-NEXT: [[CMP:%[A-Za-z0-9]+]] = icmp eq i32 %v, 2
38; CHECK-NEXT: select i1 [[CMP]], i32 2, i32 1
39; CHECK-NEXT: ret
40entry:
41        switch i32 %v, label %default [
42                 i32 1, label %U
43                 i32 2, label %T
44        ]
45default:
46        ret i32 1
47U:
48        unreachable
49T:
50        ret i32 2
51}
52
53
54;; We can either convert the following control-flow to a select or remove the
55;; unreachable control flow because of the undef store of null. Make sure we do
56;; the latter.
57
58define void @test5(i1 %cond, i8* %ptr) {
59
60; CHECK-LABEL: test5
61; CHECK: entry:
62; CHECK-NOT: select
63; CHECK:  store i8 2, i8* %ptr
64; CHECK:  ret
65
66entry:
67  br i1 %cond, label %bb1, label %bb3
68
69bb3:
70 br label %bb2
71
72bb1:
73 br label %bb2
74
75bb2:
76  %ptr.2 = phi i8* [ %ptr, %bb3 ], [ null, %bb1 ]
77  store i8 2, i8* %ptr.2, align 8
78  ret void
79}
80
81; CHECK-LABEL: test6
82; CHECK: entry:
83; CHECK-NOT: select
84; CHECK:  store i8 2, i8* %ptr
85; CHECK:  ret
86
87define void @test6(i1 %cond, i8* %ptr) {
88entry:
89  br i1 %cond, label %bb1, label %bb2
90
91bb1:
92  br label %bb2
93
94bb2:
95  %ptr.2 = phi i8* [ %ptr, %entry ], [ null, %bb1 ]
96  store i8 2, i8* %ptr.2, align 8
97  ret void
98}
99
100define i32 @test7(i1 %X) {
101entry:
102  br i1 %X, label %if, label %else
103
104if:
105  call void undef()
106  br label %else
107
108else:
109  %phi = phi i32 [ 0, %entry ], [ 1, %if ]
110  ret i32 %phi
111}
112; CHECK-LABEL: define i32 @test7(
113; CHECK-NOT: call
114; CHECK: ret i32 0
115
116define void @test8(i1 %X, void ()* %Y) {
117entry:
118  br i1 %X, label %if, label %else
119
120if:
121  br label %else
122
123else:
124  %phi = phi void ()* [ %Y, %entry ], [ null, %if ]
125  call void %phi()
126  ret void
127}
128; CHECK-LABEL: define void @test8(
129; CHECK: call void %Y(
130