Make opt default to not adding a target data string and update tests that depend...
[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: opt < %s -basicaa -gvn -instcombine -dce -S | not grep REMOVE
5 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
6
7 @Global = external global { i32 }
8
9 ; Array test:  Test that operations on one local array do not invalidate 
10 ; operations on another array.  Important for scientific codes.
11 ;
12 define i32 @different_array_test(i64 %A, i64 %B) {
13         %Array1 = alloca i32, i32 100
14         %Array2 = alloca i32, i32 200
15
16         %pointer = getelementptr i32* %Array1, i64 %A
17         %val = load i32* %pointer
18
19         %pointer2 = getelementptr i32* %Array2, i64 %B
20         store i32 7, i32* %pointer2
21
22         %REMOVE = load i32* %pointer ; redundant with above load
23         %retval = sub i32 %REMOVE, %val
24         ret i32 %retval
25 }
26
27 ; Constant index test: Constant indexes into the same array should not 
28 ; interfere with each other.  Again, important for scientific codes.
29 ;
30 define i32 @constant_array_index_test() {
31         %Array = alloca i32, i32 100
32         %P1 = getelementptr i32* %Array, i64 7
33         %P2 = getelementptr i32* %Array, i64 6
34         
35         %A = load i32* %P1
36         store i32 1, i32* %P2   ; Should not invalidate load
37         %BREMOVE = load i32* %P1
38         %Val = sub i32 %A, %BREMOVE
39         ret i32 %Val
40 }
41
42 ; Test that if two pointers are spaced out by a constant getelementptr, that 
43 ; they cannot alias.
44 define i32 @gep_distance_test(i32* %A) {
45         %REMOVEu = load i32* %A
46         %B = getelementptr i32* %A, i64 2  ; Cannot alias A
47         store i32 7, i32* %B
48         %REMOVEv = load i32* %A
49         %r = sub i32 %REMOVEu, %REMOVEv
50         ret i32 %r
51 }
52
53 ; Test that if two pointers are spaced out by a constant offset, that they
54 ; cannot alias, even if there is a variable offset between them...
55 define i32 @gep_distance_test2({i32,i32}* %A, i64 %distance) {
56         %A1 = getelementptr {i32,i32}* %A, i64 0, i32 0
57         %REMOVEu = load i32* %A1
58         %B = getelementptr {i32,i32}* %A, i64 %distance, i32 1
59         store i32 7, i32* %B    ; B cannot alias A, it's at least 4 bytes away
60         %REMOVEv = load i32* %A1
61         %r = sub i32 %REMOVEu, %REMOVEv
62         ret i32 %r
63 }
64
65 ; Test that we can do funny pointer things and that distance calc will still 
66 ; work.
67 define i32 @gep_distance_test3(i32 * %A) {
68         %X = load i32* %A
69         %B = bitcast i32* %A to i8*
70         %C = getelementptr i8* %B, i64 4
71         %Y = load i8* %C
72         ret i32 8
73 }
74
75 ; Test that we can disambiguate globals reached through constantexpr geps
76 define i32 @constexpr_test() {
77    %X = alloca i32
78    %Y = load i32* %X
79    store i32 5, i32* getelementptr ({ i32 }* @Global, i64 0, i32 0)
80    %REMOVE = load i32* %X
81    %retval = sub i32 %Y, %REMOVE
82    ret i32 %retval
83 }