Add new testcases for instcombine
[oota-llvm.git] / test / Transforms / InstCombine / phi.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: if as < %s | opt -instcombine -die | dis | grep phi
5 ; RUN: then exit 1
6 ; RUN: else exit 0
7 ; RUN: fi
8
9 implementation
10
11 int %test1(int %A, bool %b) {
12 BB0:    br bool %b, label %BB1, label %BB2
13 BB1:
14         %B = phi int [%A, %BB0]     ; Combine away one argument PHI nodes
15         ret int %B
16 BB2:
17         ret int %A
18 }
19
20 int %test2(int %A, bool %b) {
21 BB0:    br bool %b, label %BB1, label %BB2
22 BB1:
23         br label %BB2
24 BB2:
25         %B = phi int [%A, %BB0], [%A, %BB1]     ; Combine away PHI nodes with same values
26         ret int %B
27 }
28
29 int %test3(int %A, bool %b) {
30 BB0: br label %Loop
31
32 Loop:
33         %B = phi int [%A, %BB0], [%B, %Loop]    ; PHI has same value always.
34         br bool %b, label %Loop, label %Exit
35 Exit:
36         ret int %B
37 }
38
39 int %test3(bool %b) {
40 BB0:  ret int 7                                 ; Loop is unreachable
41
42 Loop:
43         %B = phi int [%B, %L2], [%B, %Loop]     ; PHI has same value always.
44         br bool %b, label %L2, label %Loop
45 L2:
46         br label %Loop
47 }
48