Add a new test for basicaa
[oota-llvm.git] / test / Analysis / BasicAA / featuretest.ll
1 ; This testcase tests for various features the basicaa test should be able to 
2 ; determine, as noted in the comments.
3
4 ; RUN: if as < %s | opt -basicaa -load-vn -gcse -instcombine -dce | dis | grep REMOVE
5 ; RUN: then exit 1
6 ; RUN: else exit 0
7 ; RUN: fi
8
9
10 ; Array test:  Test that operations on one local array do not invalidate 
11 ; operations on another array.  Important for scientific codes.
12 ;
13 int %different_array_test(long %A, long %B) {
14         %Array1 = alloca int, uint 100
15         %Array2 = alloca int, uint 200
16
17         %pointer = getelementptr int* %Array1, long %A
18         %val = load int* %pointer
19
20         %pointer2 = getelementptr int* %Array2, long %B
21         store int 7, int* %pointer2
22
23         %REMOVE = load int* %pointer ; redundant with above load
24         %retval = sub int %REMOVE, %val
25         ret int %retval
26 }
27
28 ; Constant index test: Constant indexes into the same array should not 
29 ; interfere with each other.  Again, important for scientific codes.
30 ;
31 int %constant_array_index_test() {
32         %Array = alloca int, uint 100
33         %P1 = getelementptr int* %Array, long 7
34         %P2 = getelementptr int* %Array, long 6
35         
36         %A = load int* %P1
37         store int 1, int* %P2   ; Should not invalidate load
38         %BREMOVE = load int* %P1
39         %Val = sub int %A, %BREMOVE
40         ret int %Val
41 }
42
43 ; Test that if two pointers are spaced out by a constant getelementptr, that 
44 ; they cannot alias.
45 int %gep_distance_test(int* %A) {
46         %REMOVEu = load int* %A
47         %B = getelementptr int* %A, long 2  ; Cannot alias A
48         store int 7, int* %B
49         %REMOVEv = load int* %A
50         %r = sub int %REMOVEu, %REMOVEv
51         ret int %r
52 }
53
54 ; Test that if two pointers are spaced out by a constant offset, that they
55 ; cannot alias, even if there is a variable offset between them...
56 int %gep_distance_test2({int,int}* %A, long %distance) {
57         %A = getelementptr {int,int}* %A, long 0, ubyte 0
58         %REMOVEu = load int* %A
59         %B = getelementptr {int,int}* %A, long %distance, ubyte 1
60         store int 7, int* %B    ; B cannot alias A, it's at least 4 bytes away
61         %REMOVEv = load int* %A
62         %r = sub int %REMOVEu, %REMOVEv
63         ret int %r
64 }