1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4define i32 @const(i1 %cond) {
5; CHECK-LABEL: @const(
6; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
7; CHECK:       A:
8; CHECK-NEXT:    br label [[C:%.*]]
9; CHECK:       B:
10; CHECK-NEXT:    br label [[C]]
11; CHECK:       C:
12; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ 1, [[B]] ]
13; CHECK-NEXT:    ret i32 [[Y]]
14;
15  br i1 %cond, label %A, label %B
16A:
17  br label %C
18B:
19  br label %C
20C:
21  %y = phi i32 [0, %A], [1, %B]
22  %y.fr = freeze i32 %y
23  ret i32 %y.fr
24}
25
26define <2 x i32> @vec(i1 %cond) {
27; CHECK-LABEL: @vec(
28; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
29; CHECK:       A:
30; CHECK-NEXT:    br label [[C:%.*]]
31; CHECK:       B:
32; CHECK-NEXT:    br label [[C]]
33; CHECK:       C:
34; CHECK-NEXT:    [[Y:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[A]] ], [ <i32 2, i32 3>, [[B]] ]
35; CHECK-NEXT:    ret <2 x i32> [[Y]]
36;
37  br i1 %cond, label %A, label %B
38A:
39  br label %C
40B:
41  br label %C
42C:
43  %y = phi <2 x i32> [<i32 0, i32 1>, %A], [<i32 2, i32 3>, %B]
44  %y.fr = freeze <2 x i32> %y
45  ret <2 x i32> %y.fr
46}
47
48define <2 x i32> @vec_undef(i1 %cond) {
49; CHECK-LABEL: @vec_undef(
50; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
51; CHECK:       A:
52; CHECK-NEXT:    br label [[C:%.*]]
53; CHECK:       B:
54; CHECK-NEXT:    [[PHI_FR:%.*]] = freeze <2 x i32> <i32 2, i32 undef>
55; CHECK-NEXT:    br label [[C]]
56; CHECK:       C:
57; CHECK-NEXT:    [[Y:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[A]] ], [ [[PHI_FR]], [[B]] ]
58; CHECK-NEXT:    ret <2 x i32> [[Y]]
59;
60  br i1 %cond, label %A, label %B
61A:
62  br label %C
63B:
64  br label %C
65C:
66  %y = phi <2 x i32> [<i32 0, i32 1>, %A], [<i32 2, i32 undef>, %B]
67  %y.fr = freeze <2 x i32> %y
68  ret <2 x i32> %y.fr
69}
70
71define i32 @one(i1 %cond, i32 %x) {
72; CHECK-LABEL: @one(
73; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
74; CHECK:       A:
75; CHECK-NEXT:    br label [[C:%.*]]
76; CHECK:       B:
77; CHECK-NEXT:    [[PHI_FR:%.*]] = freeze i32 [[X:%.*]]
78; CHECK-NEXT:    br label [[C]]
79; CHECK:       C:
80; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ [[PHI_FR]], [[B]] ]
81; CHECK-NEXT:    ret i32 [[Y]]
82;
83  br i1 %cond, label %A, label %B
84A:
85  br label %C
86B:
87  br label %C
88C:
89  %y = phi i32 [0, %A], [%x, %B]
90  %y.fr = freeze i32 %y
91  ret i32 %y.fr
92}
93
94define i32 @two(i1 %cond, i32 %x, i32 %x2) {
95; CHECK-LABEL: @two(
96; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
97; CHECK:       A:
98; CHECK-NEXT:    br label [[C:%.*]]
99; CHECK:       B:
100; CHECK-NEXT:    br label [[C]]
101; CHECK:       C:
102; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ [[X:%.*]], [[A]] ], [ [[X2:%.*]], [[B]] ]
103; CHECK-NEXT:    [[Y_FR:%.*]] = freeze i32 [[Y]]
104; CHECK-NEXT:    ret i32 [[Y_FR]]
105;
106  br i1 %cond, label %A, label %B
107A:
108  br label %C
109B:
110  br label %C
111C:
112  %y = phi i32 [%x, %A], [%x2, %B]
113  %y.fr = freeze i32 %y
114  ret i32 %y.fr
115}
116
117define i32 @two_undef(i8 %cond, i32 %x) {
118; CHECK-LABEL: @two_undef(
119; CHECK-NEXT:    switch i8 [[COND:%.*]], label [[A:%.*]] [
120; CHECK-NEXT:    i8 0, label [[B:%.*]]
121; CHECK-NEXT:    i8 1, label [[C:%.*]]
122; CHECK-NEXT:    ]
123; CHECK:       A:
124; CHECK-NEXT:    br label [[D:%.*]]
125; CHECK:       B:
126; CHECK-NEXT:    br label [[D]]
127; CHECK:       C:
128; CHECK-NEXT:    br label [[D]]
129; CHECK:       D:
130; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ undef, [[A]] ], [ [[X:%.*]], [[B]] ], [ 0, [[C]] ]
131; CHECK-NEXT:    [[Y_FR:%.*]] = freeze i32 [[Y]]
132; CHECK-NEXT:    ret i32 [[Y_FR]]
133;
134  switch i8 %cond, label %A [
135  i8 0, label %B
136  i8 1, label %C
137  ]
138A:
139  br label %D
140B:
141  br label %D
142C:
143  br label %D
144D:
145  %y = phi i32 [undef, %A], [%x, %B], [0, %C]
146  %y.fr = freeze i32 %y
147  ret i32 %y.fr
148}
149
150define i32 @one_undef(i8 %cond) {
151; CHECK-LABEL: @one_undef(
152; CHECK-NEXT:    switch i8 [[COND:%.*]], label [[A:%.*]] [
153; CHECK-NEXT:    i8 0, label [[B:%.*]]
154; CHECK-NEXT:    i8 1, label [[C:%.*]]
155; CHECK-NEXT:    ]
156; CHECK:       A:
157; CHECK-NEXT:    br label [[D:%.*]]
158; CHECK:       B:
159; CHECK-NEXT:    br label [[D]]
160; CHECK:       C:
161; CHECK-NEXT:    br label [[D]]
162; CHECK:       D:
163; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
164; CHECK-NEXT:    ret i32 [[Y]]
165;
166  switch i8 %cond, label %A [
167  i8 0, label %B
168  i8 1, label %C
169  ]
170A:
171  br label %D
172B:
173  br label %D
174C:
175  br label %D
176D:
177  %y = phi i32 [undef, %A], [32, %B], [0, %C]
178  %y.fr = freeze i32 %y
179  ret i32 %y.fr
180}
181
182@glb = global i8 0
183
184define i32 @one_constexpr(i8 %cond, i32 %x) {
185; CHECK-LABEL: @one_constexpr(
186; CHECK-NEXT:    switch i8 [[COND:%.*]], label [[A:%.*]] [
187; CHECK-NEXT:    i8 0, label [[B:%.*]]
188; CHECK-NEXT:    i8 1, label [[C:%.*]]
189; CHECK-NEXT:    ]
190; CHECK:       A:
191; CHECK-NEXT:    [[PHI_FR:%.*]] = freeze i32 ptrtoint (i8* getelementptr inbounds (i8, i8* @glb, i64 2) to i32)
192; CHECK-NEXT:    br label [[D:%.*]]
193; CHECK:       B:
194; CHECK-NEXT:    br label [[D]]
195; CHECK:       C:
196; CHECK-NEXT:    br label [[D]]
197; CHECK:       D:
198; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ [[PHI_FR]], [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
199; CHECK-NEXT:    ret i32 [[Y]]
200;
201  switch i8 %cond, label %A [
202  i8 0, label %B
203  i8 1, label %C
204  ]
205A:
206  br label %D
207B:
208  br label %D
209C:
210  br label %D
211D:
212  %y = phi i32 [ptrtoint (i8* getelementptr inbounds (i8, i8* @glb, i64 2) to i32), %A], [32, %B], [0, %C]
213  %y.fr = freeze i32 %y
214  ret i32 %y.fr
215}
216