1*cee313d2SEric Christopher; RUN: opt -jump-threading -S < %s | FileCheck %s
2*cee313d2SEric Christopher
3*cee313d2SEric Christopherdeclare i32 @f1()
4*cee313d2SEric Christopherdeclare i32 @f2()
5*cee313d2SEric Christopherdeclare void @f3()
6*cee313d2SEric Christopher
7*cee313d2SEric Christopherdefine i32 @test1(i1 %cond) {
8*cee313d2SEric Christopher; CHECK-LABEL: @test1(
9*cee313d2SEric Christopher
10*cee313d2SEric Christopher	br i1 %cond, label %T1, label %F1
11*cee313d2SEric Christopher
12*cee313d2SEric ChristopherT1:
13*cee313d2SEric Christopher	%v1 = call i32 @f1()
14*cee313d2SEric Christopher	br label %Merge
15*cee313d2SEric Christopher
16*cee313d2SEric ChristopherF1:
17*cee313d2SEric Christopher	%v2 = call i32 @f2()
18*cee313d2SEric Christopher	br label %Merge
19*cee313d2SEric Christopher
20*cee313d2SEric ChristopherMerge:
21*cee313d2SEric Christopher	%A = phi i1 [true, %T1], [false, %F1]
22*cee313d2SEric Christopher	%B = phi i32 [%v1, %T1], [%v2, %F1]
23*cee313d2SEric Christopher	br i1 %A, label %T2, label %F2
24*cee313d2SEric Christopher
25*cee313d2SEric ChristopherT2:
26*cee313d2SEric Christopher; CHECK: T2:
27*cee313d2SEric Christopher; CHECK: ret i32 %v1
28*cee313d2SEric Christopher	call void @f3()
29*cee313d2SEric Christopher	ret i32 %B
30*cee313d2SEric Christopher
31*cee313d2SEric ChristopherF2:
32*cee313d2SEric Christopher; CHECK: F2:
33*cee313d2SEric Christopher; CHECK: ret i32 %v2
34*cee313d2SEric Christopher	ret i32 %B
35*cee313d2SEric Christopher}
36*cee313d2SEric Christopher
37*cee313d2SEric Christopher
38*cee313d2SEric Christopher;; cond is known false on Entry -> F1 edge!
39*cee313d2SEric Christopherdefine i32 @test2(i1 %cond) {
40*cee313d2SEric Christopher; CHECK-LABEL: @test2(
41*cee313d2SEric ChristopherEntry:
42*cee313d2SEric Christopher	br i1 %cond, label %T1, label %F1
43*cee313d2SEric Christopher
44*cee313d2SEric ChristopherT1:
45*cee313d2SEric Christopher; CHECK: %v1 = call i32 @f1()
46*cee313d2SEric Christopher; CHECK: ret i32 47
47*cee313d2SEric Christopher	%v1 = call i32 @f1()
48*cee313d2SEric Christopher	br label %Merge
49*cee313d2SEric Christopher
50*cee313d2SEric ChristopherF1:
51*cee313d2SEric Christopher	br i1 %cond, label %Merge, label %F2
52*cee313d2SEric Christopher
53*cee313d2SEric ChristopherMerge:
54*cee313d2SEric Christopher	%B = phi i32 [47, %T1], [192, %F1]
55*cee313d2SEric Christopher	ret i32 %B
56*cee313d2SEric Christopher
57*cee313d2SEric ChristopherF2:
58*cee313d2SEric Christopher	call void @f3()
59*cee313d2SEric Christopher	ret i32 12
60*cee313d2SEric Christopher}
61*cee313d2SEric Christopher
62*cee313d2SEric Christopher
63*cee313d2SEric Christopher; Undef handling.
64*cee313d2SEric Christopherdefine i32 @test3(i1 %cond) {
65*cee313d2SEric Christopher; CHECK-LABEL: @test3(
66*cee313d2SEric Christopher; CHECK-NEXT: T1:
67*cee313d2SEric Christopher; CHECK-NEXT: ret i32 42
68*cee313d2SEric Christopher	br i1 undef, label %T1, label %F1
69*cee313d2SEric Christopher
70*cee313d2SEric ChristopherT1:
71*cee313d2SEric Christopher	ret i32 42
72*cee313d2SEric Christopher
73*cee313d2SEric ChristopherF1:
74*cee313d2SEric Christopher	ret i32 17
75*cee313d2SEric Christopher}
76*cee313d2SEric Christopher
77*cee313d2SEric Christopherdefine i32 @test4(i1 %cond, i1 %cond2) {
78*cee313d2SEric Christopher; CHECK-LABEL: @test4(
79*cee313d2SEric Christopher
80*cee313d2SEric Christopher	br i1 %cond, label %T1, label %F1
81*cee313d2SEric Christopher
82*cee313d2SEric ChristopherT1:
83*cee313d2SEric Christopher; CHECK:   %v1 = call i32 @f1()
84*cee313d2SEric Christopher; CHECK-NEXT:   br label %T
85*cee313d2SEric Christopher
86*cee313d2SEric Christopher	%v1 = call i32 @f1()
87*cee313d2SEric Christopher	br label %Merge
88*cee313d2SEric Christopher
89*cee313d2SEric ChristopherF1:
90*cee313d2SEric Christopher	%v2 = call i32 @f2()
91*cee313d2SEric Christopher; CHECK:   %v2 = call i32 @f2()
92*cee313d2SEric Christopher; CHECK-NEXT:   br i1 %cond2,
93*cee313d2SEric Christopher	br label %Merge
94*cee313d2SEric Christopher
95*cee313d2SEric ChristopherMerge:
96*cee313d2SEric Christopher	%A = phi i1 [undef, %T1], [%cond2, %F1]
97*cee313d2SEric Christopher	%B = phi i32 [%v1, %T1], [%v2, %F1]
98*cee313d2SEric Christopher	br i1 %A, label %T2, label %F2
99*cee313d2SEric Christopher
100*cee313d2SEric ChristopherT2:
101*cee313d2SEric Christopher	call void @f3()
102*cee313d2SEric Christopher	ret i32 %B
103*cee313d2SEric Christopher
104*cee313d2SEric ChristopherF2:
105*cee313d2SEric Christopher	ret i32 %B
106*cee313d2SEric Christopher}
107*cee313d2SEric Christopher
108*cee313d2SEric Christopher
109*cee313d2SEric Christopher;; This tests that the branch in 'merge' can be cloned up into T1.
110*cee313d2SEric Christopherdefine i32 @test5(i1 %cond, i1 %cond2) {
111*cee313d2SEric Christopher; CHECK-LABEL: @test5(
112*cee313d2SEric Christopher
113*cee313d2SEric Christopher	br i1 %cond, label %T1, label %F1
114*cee313d2SEric Christopher
115*cee313d2SEric ChristopherT1:
116*cee313d2SEric Christopher; CHECK: T1:
117*cee313d2SEric Christopher; CHECK-NEXT:   %v1 = call i32 @f1()
118*cee313d2SEric Christopher; CHECK-NEXT:   %cond3 = icmp eq i32 %v1, 412
119*cee313d2SEric Christopher; CHECK-NEXT:   br i1 %cond3, label %T2, label %F2
120*cee313d2SEric Christopher
121*cee313d2SEric Christopher	%v1 = call i32 @f1()
122*cee313d2SEric Christopher        %cond3 = icmp eq i32 %v1, 412
123*cee313d2SEric Christopher	br label %Merge
124*cee313d2SEric Christopher
125*cee313d2SEric ChristopherF1:
126*cee313d2SEric Christopher	%v2 = call i32 @f2()
127*cee313d2SEric Christopher	br label %Merge
128*cee313d2SEric Christopher
129*cee313d2SEric ChristopherMerge:
130*cee313d2SEric Christopher	%A = phi i1 [%cond3, %T1], [%cond2, %F1]
131*cee313d2SEric Christopher	%B = phi i32 [%v1, %T1], [%v2, %F1]
132*cee313d2SEric Christopher	br i1 %A, label %T2, label %F2
133*cee313d2SEric Christopher
134*cee313d2SEric ChristopherT2:
135*cee313d2SEric Christopher	call void @f3()
136*cee313d2SEric Christopher	ret i32 %B
137*cee313d2SEric Christopher
138*cee313d2SEric ChristopherF2:
139*cee313d2SEric Christopher	ret i32 %B
140*cee313d2SEric Christopher}
141*cee313d2SEric Christopher
142*cee313d2SEric Christopher
143*cee313d2SEric Christopher;; Lexically duplicated conditionals should be threaded.
144*cee313d2SEric Christopher
145*cee313d2SEric Christopher
146*cee313d2SEric Christopherdefine i32 @test6(i32 %A) {
147*cee313d2SEric Christopher; CHECK-LABEL: @test6(
148*cee313d2SEric Christopher	%tmp455 = icmp eq i32 %A, 42
149*cee313d2SEric Christopher	br i1 %tmp455, label %BB1, label %BB2
150*cee313d2SEric Christopher
151*cee313d2SEric Christopher; CHECK: call i32 @f2()
152*cee313d2SEric Christopher; CHECK-NEXT: ret i32 3
153*cee313d2SEric Christopher
154*cee313d2SEric Christopher; CHECK: call i32 @f1()
155*cee313d2SEric Christopher; CHECK-NOT: br
156*cee313d2SEric Christopher; CHECK: call void @f3()
157*cee313d2SEric Christopher; CHECK-NOT: br
158*cee313d2SEric Christopher; CHECK: ret i32 4
159*cee313d2SEric Christopher
160*cee313d2SEric ChristopherBB2:
161*cee313d2SEric Christopher	call i32 @f1()
162*cee313d2SEric Christopher	br label %BB1
163*cee313d2SEric Christopher
164*cee313d2SEric Christopher
165*cee313d2SEric ChristopherBB1:
166*cee313d2SEric Christopher	%tmp459 = icmp eq i32 %A, 42
167*cee313d2SEric Christopher	br i1 %tmp459, label %BB3, label %BB4
168*cee313d2SEric Christopher
169*cee313d2SEric ChristopherBB3:
170*cee313d2SEric Christopher	call i32 @f2()
171*cee313d2SEric Christopher        ret i32 3
172*cee313d2SEric Christopher
173*cee313d2SEric ChristopherBB4:
174*cee313d2SEric Christopher	call void @f3()
175*cee313d2SEric Christopher	ret i32 4
176*cee313d2SEric Christopher}
177*cee313d2SEric Christopher
178*cee313d2SEric Christopher
179*cee313d2SEric Christopher;; This tests that the branch in 'merge' can be cloned up into T1.
180*cee313d2SEric Christopher;; rdar://7367025
181*cee313d2SEric Christopherdefine i32 @test7(i1 %cond, i1 %cond2) {
182*cee313d2SEric ChristopherEntry:
183*cee313d2SEric Christopher; CHECK-LABEL: @test7(
184*cee313d2SEric Christopher	%v1 = call i32 @f1()
185*cee313d2SEric Christopher	br i1 %cond, label %Merge, label %F1
186*cee313d2SEric Christopher
187*cee313d2SEric ChristopherF1:
188*cee313d2SEric Christopher	%v2 = call i32 @f2()
189*cee313d2SEric Christopher	br label %Merge
190*cee313d2SEric Christopher
191*cee313d2SEric ChristopherMerge:
192*cee313d2SEric Christopher	%B = phi i32 [%v1, %Entry], [%v2, %F1]
193*cee313d2SEric Christopher        %M = icmp ne i32 %B, %v1
194*cee313d2SEric Christopher        %N = icmp eq i32 %B, 47
195*cee313d2SEric Christopher        %O = and i1 %M, %N
196*cee313d2SEric Christopher	br i1 %O, label %T2, label %F2
197*cee313d2SEric Christopher
198*cee313d2SEric Christopher; CHECK: Merge:
199*cee313d2SEric Christopher; CHECK-NOT: phi
200*cee313d2SEric Christopher; CHECK-NEXT:   %v2 = call i32 @f2()
201*cee313d2SEric Christopher
202*cee313d2SEric ChristopherT2:
203*cee313d2SEric Christopher	call void @f3()
204*cee313d2SEric Christopher	ret i32 %B
205*cee313d2SEric Christopher
206*cee313d2SEric ChristopherF2:
207*cee313d2SEric Christopher	ret i32 %B
208*cee313d2SEric Christopher; CHECK: F2:
209*cee313d2SEric Christopher; CHECK-NEXT: phi i32
210*cee313d2SEric Christopher}
211*cee313d2SEric Christopher
212*cee313d2SEric Christopher
213*cee313d2SEric Christopherdeclare i1 @test8a()
214*cee313d2SEric Christopher
215*cee313d2SEric Christopherdefine i32 @test8b(i1 %cond, i1 %cond2) {
216*cee313d2SEric Christopher; CHECK-LABEL: @test8b(
217*cee313d2SEric ChristopherT0:
218*cee313d2SEric Christopher        %A = call i1 @test8a()
219*cee313d2SEric Christopher	br i1 %A, label %T1, label %F1
220*cee313d2SEric Christopher
221*cee313d2SEric Christopher; CHECK: T0:
222*cee313d2SEric Christopher; CHECK-NEXT: call
223*cee313d2SEric Christopher; CHECK-NEXT: br i1 %A, label %T1, label %Y
224*cee313d2SEric Christopher
225*cee313d2SEric ChristopherT1:
226*cee313d2SEric Christopher        %B = call i1 @test8a()
227*cee313d2SEric Christopher	br i1 %B, label %T2, label %F1
228*cee313d2SEric Christopher
229*cee313d2SEric Christopher; CHECK: T1:
230*cee313d2SEric Christopher; CHECK-NEXT: call
231*cee313d2SEric Christopher; CHECK-NEXT: br i1 %B, label %T2, label %Y
232*cee313d2SEric ChristopherT2:
233*cee313d2SEric Christopher        %C = call i1 @test8a()
234*cee313d2SEric Christopher	br i1 %cond, label %T3, label %F1
235*cee313d2SEric Christopher
236*cee313d2SEric Christopher; CHECK: T2:
237*cee313d2SEric Christopher; CHECK-NEXT: call
238*cee313d2SEric Christopher; CHECK-NEXT: br i1 %cond, label %T3, label %Y
239*cee313d2SEric ChristopherT3:
240*cee313d2SEric Christopher        ret i32 0
241*cee313d2SEric Christopher
242*cee313d2SEric ChristopherF1:
243*cee313d2SEric Christopher        %D = phi i32 [0, %T0], [0, %T1], [1, %T2]
244*cee313d2SEric Christopher        %E = icmp eq i32 %D, 1
245*cee313d2SEric Christopher        %F = and i1 %E, %cond
246*cee313d2SEric Christopher	br i1 %F, label %X, label %Y
247*cee313d2SEric ChristopherX:
248*cee313d2SEric Christopher        call i1 @test8a()
249*cee313d2SEric Christopher        ret i32 1
250*cee313d2SEric ChristopherY:
251*cee313d2SEric Christopher        ret i32 2
252*cee313d2SEric Christopher}
253*cee313d2SEric Christopher
254*cee313d2SEric Christopher
255*cee313d2SEric Christopher;;; Verify that we can handle constraint propagation through "xor x, 1".
256*cee313d2SEric Christopherdefine i32 @test9(i1 %cond, i1 %cond2) {
257*cee313d2SEric ChristopherEntry:
258*cee313d2SEric Christopher; CHECK-LABEL: @test9(
259*cee313d2SEric Christopher	%v1 = call i32 @f1()
260*cee313d2SEric Christopher	br i1 %cond, label %Merge, label %F1
261*cee313d2SEric Christopher
262*cee313d2SEric Christopher; CHECK: Entry:
263*cee313d2SEric Christopher; CHECK-NEXT:  %v1 = call i32 @f1()
264*cee313d2SEric Christopher; CHECK-NEXT:  br i1 %cond, label %F2, label %Merge
265*cee313d2SEric Christopher
266*cee313d2SEric ChristopherF1:
267*cee313d2SEric Christopher	%v2 = call i32 @f2()
268*cee313d2SEric Christopher	br label %Merge
269*cee313d2SEric Christopher
270*cee313d2SEric ChristopherMerge:
271*cee313d2SEric Christopher	%B = phi i32 [%v1, %Entry], [%v2, %F1]
272*cee313d2SEric Christopher        %M = icmp eq i32 %B, %v1
273*cee313d2SEric Christopher        %M1 = xor i1 %M, 1
274*cee313d2SEric Christopher        %N = icmp eq i32 %B, 47
275*cee313d2SEric Christopher        %O = and i1 %M1, %N
276*cee313d2SEric Christopher	br i1 %O, label %T2, label %F2
277*cee313d2SEric Christopher
278*cee313d2SEric Christopher; CHECK: Merge:
279*cee313d2SEric Christopher; CHECK-NOT: phi
280*cee313d2SEric Christopher; CHECK-NEXT:   %v2 = call i32 @f2()
281*cee313d2SEric Christopher
282*cee313d2SEric ChristopherT2:
283*cee313d2SEric Christopher	%Q = zext i1 %M to i32
284*cee313d2SEric Christopher	ret i32 %Q
285*cee313d2SEric Christopher
286*cee313d2SEric ChristopherF2:
287*cee313d2SEric Christopher	ret i32 %B
288*cee313d2SEric Christopher; CHECK: F2:
289*cee313d2SEric Christopher; CHECK-NEXT: phi i32
290*cee313d2SEric Christopher}
291*cee313d2SEric Christopher
292*cee313d2SEric Christopher
293*cee313d2SEric Christopher
294*cee313d2SEric Christopher; CHECK: @test10
295*cee313d2SEric Christopherdeclare i32 @test10f1()
296*cee313d2SEric Christopherdeclare i32 @test10f2()
297*cee313d2SEric Christopherdeclare void @test10f3()
298*cee313d2SEric Christopher
299*cee313d2SEric Christopher;; Non-local condition threading.
300*cee313d2SEric Christopherdefine i32 @test10g(i1 %cond) {
301*cee313d2SEric Christopher; CHECK-LABEL: @test10g(
302*cee313d2SEric Christopher; CHECK-NEXT:   br i1 %cond, label %T2, label %F2
303*cee313d2SEric Christopher        br i1 %cond, label %T1, label %F1
304*cee313d2SEric Christopher
305*cee313d2SEric ChristopherT1:
306*cee313d2SEric Christopher        %v1 = call i32 @test10f1()
307*cee313d2SEric Christopher        br label %Merge
308*cee313d2SEric Christopher
309*cee313d2SEric Christopher; CHECK: %v1 = call i32 @test10f1()
310*cee313d2SEric Christopher; CHECK-NEXT: call void @f3()
311*cee313d2SEric Christopher; CHECK-NEXT: ret i32 %v1
312*cee313d2SEric Christopher
313*cee313d2SEric ChristopherF1:
314*cee313d2SEric Christopher        %v2 = call i32 @test10f2()
315*cee313d2SEric Christopher        br label %Merge
316*cee313d2SEric Christopher
317*cee313d2SEric ChristopherMerge:
318*cee313d2SEric Christopher        %B = phi i32 [%v1, %T1], [%v2, %F1]
319*cee313d2SEric Christopher        br i1 %cond, label %T2, label %F2
320*cee313d2SEric Christopher
321*cee313d2SEric ChristopherT2:
322*cee313d2SEric Christopher        call void @f3()
323*cee313d2SEric Christopher        ret i32 %B
324*cee313d2SEric Christopher
325*cee313d2SEric ChristopherF2:
326*cee313d2SEric Christopher        ret i32 %B
327*cee313d2SEric Christopher}
328*cee313d2SEric Christopher
329*cee313d2SEric Christopher
330*cee313d2SEric Christopher; Impossible conditional constraints should get threaded.  BB3 is dead here.
331*cee313d2SEric Christopherdefine i32 @test11(i32 %A) {
332*cee313d2SEric Christopher; CHECK-LABEL: @test11(
333*cee313d2SEric Christopher; CHECK-NEXT: icmp
334*cee313d2SEric Christopher; CHECK-NEXT: br i1 %tmp455, label %BB4, label %BB2
335*cee313d2SEric Christopher	%tmp455 = icmp eq i32 %A, 42
336*cee313d2SEric Christopher	br i1 %tmp455, label %BB1, label %BB2
337*cee313d2SEric Christopher
338*cee313d2SEric ChristopherBB2:
339*cee313d2SEric Christopher; CHECK: call i32 @f1()
340*cee313d2SEric Christopher; CHECK-NEXT: ret i32 %C
341*cee313d2SEric Christopher	%C = call i32 @f1()
342*cee313d2SEric Christopher	ret i32 %C
343*cee313d2SEric Christopher
344*cee313d2SEric Christopher
345*cee313d2SEric ChristopherBB1:
346*cee313d2SEric Christopher	%tmp459 = icmp eq i32 %A, 43
347*cee313d2SEric Christopher	br i1 %tmp459, label %BB3, label %BB4
348*cee313d2SEric Christopher
349*cee313d2SEric ChristopherBB3:
350*cee313d2SEric Christopher	call i32 @f2()
351*cee313d2SEric Christopher        ret i32 3
352*cee313d2SEric Christopher
353*cee313d2SEric ChristopherBB4:
354*cee313d2SEric Christopher	call void @f3()
355*cee313d2SEric Christopher	ret i32 4
356*cee313d2SEric Christopher}
357*cee313d2SEric Christopher
358*cee313d2SEric Christopher;; Correlated value through boolean expression.  GCC PR18046.
359*cee313d2SEric Christopherdefine void @test12(i32 %A) {
360*cee313d2SEric Christopher; CHECK-LABEL: @test12(
361*cee313d2SEric Christopherentry:
362*cee313d2SEric Christopher  %cond = icmp eq i32 %A, 0
363*cee313d2SEric Christopher  br i1 %cond, label %bb, label %bb1
364*cee313d2SEric Christopher; Should branch to the return block instead of through BB1.
365*cee313d2SEric Christopher; CHECK: entry:
366*cee313d2SEric Christopher; CHECK-NEXT: %cond = icmp eq i32 %A, 0
367*cee313d2SEric Christopher; CHECK-NEXT: br i1 %cond, label %bb1, label %return
368*cee313d2SEric Christopher
369*cee313d2SEric Christopherbb:
370*cee313d2SEric Christopher  %B = call i32 @test10f2()
371*cee313d2SEric Christopher  br label %bb1
372*cee313d2SEric Christopher
373*cee313d2SEric Christopherbb1:
374*cee313d2SEric Christopher  %C = phi i32 [ %A, %entry ], [ %B, %bb ]
375*cee313d2SEric Christopher  %cond4 = icmp eq i32 %C, 0
376*cee313d2SEric Christopher  br i1 %cond4, label %bb2, label %return
377*cee313d2SEric Christopher
378*cee313d2SEric Christopher; CHECK: bb1:
379*cee313d2SEric Christopher; CHECK-NEXT: %B = call i32 @test10f2()
380*cee313d2SEric Christopher; CHECK-NEXT: %cond4 = icmp eq i32 %B, 0
381*cee313d2SEric Christopher; CHECK-NEXT: br i1 %cond4, label %bb2, label %return
382*cee313d2SEric Christopher
383*cee313d2SEric Christopherbb2:
384*cee313d2SEric Christopher  %D = call i32 @test10f2()
385*cee313d2SEric Christopher  ret void
386*cee313d2SEric Christopher
387*cee313d2SEric Christopherreturn:
388*cee313d2SEric Christopher  ret void
389*cee313d2SEric Christopher}
390*cee313d2SEric Christopher
391*cee313d2SEric Christopher
392*cee313d2SEric Christopher;; Duplicate condition to avoid xor of cond.
393*cee313d2SEric Christopher;; rdar://7391699
394*cee313d2SEric Christopherdefine i32 @test13(i1 %cond, i1 %cond2) {
395*cee313d2SEric ChristopherEntry:
396*cee313d2SEric Christopher; CHECK-LABEL: @test13(
397*cee313d2SEric Christopher	%v1 = call i32 @f1()
398*cee313d2SEric Christopher	br i1 %cond, label %Merge, label %F1
399*cee313d2SEric Christopher
400*cee313d2SEric ChristopherF1:
401*cee313d2SEric Christopher	br label %Merge
402*cee313d2SEric Christopher
403*cee313d2SEric ChristopherMerge:
404*cee313d2SEric Christopher	%B = phi i1 [true, %Entry], [%cond2, %F1]
405*cee313d2SEric Christopher        %C = phi i32 [192, %Entry], [%v1, %F1]
406*cee313d2SEric Christopher        %M = icmp eq i32 %C, 192
407*cee313d2SEric Christopher        %N = xor i1 %B, %M
408*cee313d2SEric Christopher	br i1 %N, label %T2, label %F2
409*cee313d2SEric Christopher
410*cee313d2SEric ChristopherT2:
411*cee313d2SEric Christopher	ret i32 123
412*cee313d2SEric Christopher
413*cee313d2SEric ChristopherF2:
414*cee313d2SEric Christopher	ret i32 %v1
415*cee313d2SEric Christopher
416*cee313d2SEric Christopher; CHECK:   br i1 %cond, label %F2, label %Merge
417*cee313d2SEric Christopher
418*cee313d2SEric Christopher; CHECK:      Merge:
419*cee313d2SEric Christopher; CHECK-NEXT:   %M = icmp eq i32 %v1, 192
420*cee313d2SEric Christopher; CHECK-NEXT:   %N = xor i1 %cond2, %M
421*cee313d2SEric Christopher; CHECK-NEXT:   br i1 %N, label %T2, label %F2
422*cee313d2SEric Christopher}
423*cee313d2SEric Christopher
424*cee313d2SEric Christopher; CHECK-LABEL: @test14(
425*cee313d2SEric Christopherdefine i32 @test14(i32 %in) {
426*cee313d2SEric Christopherentry:
427*cee313d2SEric Christopher	%A = icmp eq i32 %in, 0
428*cee313d2SEric Christopher; CHECK: br i1 %A, label %right_ret, label %merge
429*cee313d2SEric Christopher  br i1 %A, label %left, label %right
430*cee313d2SEric Christopher
431*cee313d2SEric Christopher; CHECK-NOT: left:
432*cee313d2SEric Christopherleft:
433*cee313d2SEric Christopher	br label %merge
434*cee313d2SEric Christopher
435*cee313d2SEric Christopher; CHECK-NOT: right:
436*cee313d2SEric Christopherright:
437*cee313d2SEric Christopher  %B = call i32 @f1()
438*cee313d2SEric Christopher	br label %merge
439*cee313d2SEric Christopher
440*cee313d2SEric Christophermerge:
441*cee313d2SEric Christopher; CHECK-NOT: %C = phi i32 [%in, %left], [%B, %right]
442*cee313d2SEric Christopher	%C = phi i32 [%in, %left], [%B, %right]
443*cee313d2SEric Christopher	%D = add i32 %C, 1
444*cee313d2SEric Christopher	%E = icmp eq i32 %D, 2
445*cee313d2SEric Christopher	br i1 %E, label %left_ret, label %right_ret
446*cee313d2SEric Christopher
447*cee313d2SEric Christopher; CHECK: left_ret:
448*cee313d2SEric Christopherleft_ret:
449*cee313d2SEric Christopher	ret i32 0
450*cee313d2SEric Christopher
451*cee313d2SEric Christopherright_ret:
452*cee313d2SEric Christopher	ret i32 1
453*cee313d2SEric Christopher}
454*cee313d2SEric Christopher
455*cee313d2SEric Christopher; PR5652
456*cee313d2SEric Christopher; CHECK-LABEL: @test15(
457*cee313d2SEric Christopherdefine i32 @test15(i32 %len) {
458*cee313d2SEric Christopherentry:
459*cee313d2SEric Christopher; CHECK: icmp ult i32 %len, 13
460*cee313d2SEric Christopher  %tmp = icmp ult i32 %len, 13
461*cee313d2SEric Christopher  br i1 %tmp, label %check, label %exit0
462*cee313d2SEric Christopher
463*cee313d2SEric Christopherexit0:
464*cee313d2SEric Christopher  ret i32 0
465*cee313d2SEric Christopher
466*cee313d2SEric Christophercheck:
467*cee313d2SEric Christopher  %tmp9 = icmp ult i32 %len, 21
468*cee313d2SEric Christopher  br i1 %tmp9, label %exit1, label %exit2
469*cee313d2SEric Christopher
470*cee313d2SEric Christopherexit2:
471*cee313d2SEric Christopher; CHECK-NOT: ret i32 2
472*cee313d2SEric Christopher  ret i32 2
473*cee313d2SEric Christopher
474*cee313d2SEric Christopherexit1:
475*cee313d2SEric Christopher  ret i32 1
476*cee313d2SEric Christopher; CHECK: }
477*cee313d2SEric Christopher}
478*cee313d2SEric Christopher
479*cee313d2SEric Christopher;;; Verify that we can handle constraint propagation through cast.
480*cee313d2SEric Christopherdefine i32 @test16(i1 %cond) {
481*cee313d2SEric ChristopherEntry:
482*cee313d2SEric Christopher; CHECK-LABEL: @test16(
483*cee313d2SEric Christopher	br i1 %cond, label %Merge, label %F1
484*cee313d2SEric Christopher
485*cee313d2SEric Christopher; CHECK: Entry:
486*cee313d2SEric Christopher; CHECK-NEXT:  br i1 %cond, label %F2, label %Merge
487*cee313d2SEric Christopher
488*cee313d2SEric ChristopherF1:
489*cee313d2SEric Christopher	%v1 = call i32 @f1()
490*cee313d2SEric Christopher	br label %Merge
491*cee313d2SEric Christopher
492*cee313d2SEric ChristopherMerge:
493*cee313d2SEric Christopher	%B = phi i32 [0, %Entry], [%v1, %F1]
494*cee313d2SEric Christopher	%M = icmp eq i32 %B, 0
495*cee313d2SEric Christopher	%M1 = zext i1 %M to i32
496*cee313d2SEric Christopher	%N = icmp eq i32 %M1, 0
497*cee313d2SEric Christopher	br i1 %N, label %T2, label %F2
498*cee313d2SEric Christopher
499*cee313d2SEric Christopher; CHECK: Merge:
500*cee313d2SEric Christopher; CHECK-NOT: phi
501*cee313d2SEric Christopher; CHECK-NEXT:   %v1 = call i32 @f1()
502*cee313d2SEric Christopher
503*cee313d2SEric ChristopherT2:
504*cee313d2SEric Christopher	%Q = call i32 @f2()
505*cee313d2SEric Christopher	ret i32 %Q
506*cee313d2SEric Christopher
507*cee313d2SEric ChristopherF2:
508*cee313d2SEric Christopher	ret i32 %B
509*cee313d2SEric Christopher; CHECK: F2:
510*cee313d2SEric Christopher; CHECK-NEXT: phi i32
511*cee313d2SEric Christopher}
512*cee313d2SEric Christopher
513*cee313d2SEric Christopher; In this test we check that block duplication is inhibited by the presence
514*cee313d2SEric Christopher; of a function with the 'noduplicate' attribute.
515*cee313d2SEric Christopher
516*cee313d2SEric Christopherdeclare void @g()
517*cee313d2SEric Christopherdeclare void @j()
518*cee313d2SEric Christopherdeclare void @k()
519*cee313d2SEric Christopher
520*cee313d2SEric Christopher; CHECK-LABEL: define void @h(i32 %p) {
521*cee313d2SEric Christopherdefine void @h(i32 %p) {
522*cee313d2SEric Christopher  %x = icmp ult i32 %p, 5
523*cee313d2SEric Christopher  br i1 %x, label %l1, label %l2
524*cee313d2SEric Christopher
525*cee313d2SEric Christopherl1:
526*cee313d2SEric Christopher  call void @j()
527*cee313d2SEric Christopher  br label %l3
528*cee313d2SEric Christopher
529*cee313d2SEric Christopherl2:
530*cee313d2SEric Christopher  call void @k()
531*cee313d2SEric Christopher  br label %l3
532*cee313d2SEric Christopher
533*cee313d2SEric Christopherl3:
534*cee313d2SEric Christopher; CHECK: call void @g() [[$NOD:#[0-9]+]]
535*cee313d2SEric Christopher; CHECK-NOT: call void @g() [[$NOD]]
536*cee313d2SEric Christopher  call void @g() noduplicate
537*cee313d2SEric Christopher  %y = icmp ult i32 %p, 5
538*cee313d2SEric Christopher  br i1 %y, label %l4, label %l5
539*cee313d2SEric Christopher
540*cee313d2SEric Christopherl4:
541*cee313d2SEric Christopher  call void @j()
542*cee313d2SEric Christopher  ret void
543*cee313d2SEric Christopher
544*cee313d2SEric Christopherl5:
545*cee313d2SEric Christopher  call void @k()
546*cee313d2SEric Christopher  ret void
547*cee313d2SEric Christopher; CHECK: }
548*cee313d2SEric Christopher}
549*cee313d2SEric Christopher
550*cee313d2SEric Christopherdefine i1 @trunc_switch(i1 %arg) {
551*cee313d2SEric Christopher; CHECK-LABEL: @trunc_switch
552*cee313d2SEric Christophertop:
553*cee313d2SEric Christopher; CHECK: br i1 %arg, label %exitA, label %exitB
554*cee313d2SEric Christopher  br i1 %arg, label %common, label %B
555*cee313d2SEric Christopher
556*cee313d2SEric ChristopherB:
557*cee313d2SEric Christopher  br label %common
558*cee313d2SEric Christopher
559*cee313d2SEric Christophercommon:
560*cee313d2SEric Christopher  %phi = phi i8 [ 2, %B ], [ 1, %top ]
561*cee313d2SEric Christopher  %trunc = trunc i8 %phi to i2
562*cee313d2SEric Christopher; CHECK-NOT: switch
563*cee313d2SEric Christopher  switch i2 %trunc, label %unreach [
564*cee313d2SEric Christopher    i2 1, label %exitA
565*cee313d2SEric Christopher    i2 -2, label %exitB
566*cee313d2SEric Christopher  ]
567*cee313d2SEric Christopher
568*cee313d2SEric Christopherunreach:
569*cee313d2SEric Christopher  unreachable
570*cee313d2SEric Christopher
571*cee313d2SEric ChristopherexitA:
572*cee313d2SEric Christopher  ret i1 true
573*cee313d2SEric Christopher
574*cee313d2SEric ChristopherexitB:
575*cee313d2SEric Christopher  ret i1 false
576*cee313d2SEric Christopher}
577*cee313d2SEric Christopher
578*cee313d2SEric Christopher; CHECK-LABEL: define void @h_con(i32 %p) {
579*cee313d2SEric Christopherdefine void @h_con(i32 %p) {
580*cee313d2SEric Christopher  %x = icmp ult i32 %p, 5
581*cee313d2SEric Christopher  br i1 %x, label %l1, label %l2
582*cee313d2SEric Christopher
583*cee313d2SEric Christopherl1:
584*cee313d2SEric Christopher  call void @j()
585*cee313d2SEric Christopher  br label %l3
586*cee313d2SEric Christopher
587*cee313d2SEric Christopherl2:
588*cee313d2SEric Christopher  call void @k()
589*cee313d2SEric Christopher  br label %l3
590*cee313d2SEric Christopher
591*cee313d2SEric Christopherl3:
592*cee313d2SEric Christopher; CHECK: call void @g() [[$CON:#[0-9]+]]
593*cee313d2SEric Christopher; CHECK-NOT: call void @g() [[$CON]]
594*cee313d2SEric Christopher  call void @g() convergent
595*cee313d2SEric Christopher  %y = icmp ult i32 %p, 5
596*cee313d2SEric Christopher  br i1 %y, label %l4, label %l5
597*cee313d2SEric Christopher
598*cee313d2SEric Christopherl4:
599*cee313d2SEric Christopher  call void @j()
600*cee313d2SEric Christopher  ret void
601*cee313d2SEric Christopher
602*cee313d2SEric Christopherl5:
603*cee313d2SEric Christopher  call void @k()
604*cee313d2SEric Christopher  ret void
605*cee313d2SEric Christopher; CHECK: }
606*cee313d2SEric Christopher}
607*cee313d2SEric Christopher
608*cee313d2SEric Christopher
609*cee313d2SEric Christopher; CHECK: attributes [[$NOD]] = { noduplicate }
610*cee313d2SEric Christopher; CHECK: attributes [[$CON]] = { convergent }
611