Trim testcase a bit
[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: if as < %s | opt -ds-aa -load-vn -gcse -instcombine -dce | dis | grep ELIM
5 ; RUN: then exit 1
6 ; RUN: else exit 0
7 ; RUN: fi
8
9 %intpair = type {int*, int*}
10 implementation
11
12 %intpair *%alloc_pair() {
13         %Ap = malloc int
14         %Bp = malloc int
15         %C  = malloc {int*, int*}
16         %C1p = getelementptr {int*, int*}* %C, long 0, ubyte 0
17         store int* %Ap, int** %C1p
18         %C2p = getelementptr {int*, int*}* %C, long 0, ubyte 1
19         store int* %Bp, int** %C2p
20         ret %intpair* %C
21 }
22
23 int* %getp(%intpair* %P) {
24         %pp = getelementptr %intpair* %P, long 0, ubyte 0
25         %V = load int** %pp
26         ret int *%V
27 }
28
29 int* %getq(%intpair* %P) {
30         %pp = getelementptr %intpair* %P, long 0, ubyte 1
31         %V = load int** %pp
32         ret int *%V
33 }
34
35 int %test() {
36         %C = call %intpair* %alloc_pair()
37         %A = call int* %getp(%intpair* %C)
38         %B = call int* %getp(%intpair* %C)
39         %A1 = load int* %A
40
41         store int 123, int* %B  ; Store does alias %A
42
43         %A2 = load int* %A
44         %x = sub int %A1, %A2
45         ret int %x
46 }
47
48 int %test2() {   ; Test context sensitivity
49         %C1 = call %intpair* %alloc_pair()
50         %C2 = call %intpair* %alloc_pair()
51         %P1 = call int* %getp(%intpair* %C1)
52         %P2 = call int* %getp(%intpair* %C2)
53         %X = load int* %P1
54         store int 7, int* %P2
55         %Y = load int* %P1
56         %ELIM_x = sub int %X, %Y
57         ret int %ELIM_x
58 }
59
60 int %test3() {
61         %C = call %intpair* %alloc_pair()
62         %P1 = call int* %getp(%intpair* %C)
63         %P2 = call int* %getq(%intpair* %C)
64         %X = load int* %P1
65         store int 7, int* %P2
66         %Y = load int* %P1
67         %ELIM_x = sub int %X, %Y   ; Check field sensitivity
68         ret int %ELIM_x
69 }