For PR1319:
[oota-llvm.git] / test / Transforms / InstCombine / phi.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep phi
4
5 implementation
6
7 int %test1(int %A, bool %b) {
8 BB0:    br bool %b, label %BB1, label %BB2
9 BB1:
10         %B = phi int [%A, %BB0]     ; Combine away one argument PHI nodes
11         ret int %B
12 BB2:
13         ret int %A
14 }
15
16 int %test2(int %A, bool %b) {
17 BB0:    br bool %b, label %BB1, label %BB2
18 BB1:
19         br label %BB2
20 BB2:
21         %B = phi int [%A, %BB0], [%A, %BB1]     ; Combine away PHI nodes with same values
22         ret int %B
23 }
24
25 int %test3(int %A, bool %b) {
26 BB0: br label %Loop
27
28 Loop:
29         %B = phi int [%A, %BB0], [%B, %Loop]    ; PHI has same value always.
30         br bool %b, label %Loop, label %Exit
31 Exit:
32         ret int %B
33 }
34
35 int %test4(bool %b) {
36 BB0:  ret int 7                                 ; Loop is unreachable
37
38 Loop:
39         %B = phi int [%B, %L2], [%B, %Loop]     ; PHI has same value always.
40         br bool %b, label %L2, label %Loop
41 L2:
42         br label %Loop
43 }
44
45 int %test5(int %A, bool %b) {
46 BB0: br label %Loop
47
48 Loop:
49         %B = phi int [%A, %BB0], [undef, %Loop]    ; PHI has same value always.
50         br bool %b, label %Loop, label %Exit
51 Exit:
52         ret int %B
53 }
54
55 uint %test6(int %A, bool %b) {
56 BB0:
57         %X = cast int %A to uint
58         br bool %b, label %BB1, label %BB2
59 BB1:
60         %Y = cast int %A to uint
61         br label %BB2
62 BB2:
63         %B = phi uint [%X, %BB0], [%Y, %BB1] ;; Suck casts into phi
64         ret uint %B
65 }
66
67 int %test7(int %A, bool %b) {
68 BB0: br label %Loop
69
70 Loop:
71         %B = phi int [%A, %BB0], [%C, %Loop]    ; PHI is dead.
72         %C = add int %B, 123
73         br bool %b, label %Loop, label %Exit
74 Exit:
75         ret int 0
76 }
77