Use the llvm-upgrade program to upgrade llvm assembly.
[oota-llvm.git] / test / Analysis / DSGraph / gcsetest.ll
1 ; Test that GCSE uses ds-aa to do alias analysis, which is capable of 
2 ; disambiguating some cases.
3
4 ; RUN: llvm-upgrade < %s | llvm-as | opt -no-aa -ds-aa -load-vn -gcse -instcombine -dce | llvm-dis | not grep ELIM
5
6 %intpair = type {int*, int*}
7 implementation
8
9 %intpair *%alloc_pair() {
10         %Ap = malloc int
11         %Bp = malloc int
12         %C  = malloc {int*, int*}
13         %C1p = getelementptr {int*, int*}* %C, long 0, uint 0
14         store int* %Ap, int** %C1p
15         %C2p = getelementptr {int*, int*}* %C, long 0, uint 1
16         store int* %Bp, int** %C2p
17         ret %intpair* %C
18 }
19
20 int* %getp(%intpair* %P) {
21         %pp = getelementptr %intpair* %P, long 0, uint 0
22         %V = load int** %pp
23         ret int *%V
24 }
25
26 int* %getq(%intpair* %P) {
27         %pp = getelementptr %intpair* %P, long 0, uint 1
28         %V = load int** %pp
29         ret int *%V
30 }
31
32 int %test() {
33         %C = call %intpair* %alloc_pair()
34         %A = call int* %getp(%intpair* %C)
35         %B = call int* %getp(%intpair* %C)
36         %A1 = load int* %A
37
38         store int 123, int* %B  ; Store does alias %A
39
40         %A2 = load int* %A
41         %x = sub int %A1, %A2
42         ret int %x
43 }
44
45 int %test2() {   ; Test context sensitivity
46         %C1 = call %intpair* %alloc_pair()
47         %C2 = call %intpair* %alloc_pair()
48         %P1 = call int* %getp(%intpair* %C1)
49         %P2 = call int* %getp(%intpair* %C2)
50         %X = load int* %P1
51         store int 7, int* %P2
52         %Y = load int* %P1
53         %ELIM_x = sub int %X, %Y
54         ret int %ELIM_x
55 }
56
57 int %test3() {
58         %C = call %intpair* %alloc_pair()
59         %P1 = call int* %getp(%intpair* %C)
60         %P2 = call int* %getq(%intpair* %C)
61         %X = load int* %P1
62         store int 7, int* %P2
63         %Y = load int* %P1
64         %ELIM_x = sub int %X, %Y   ; Check field sensitivity
65         ret int %ELIM_x
66 }