blob: 803dafb676861029194da8bb5740f4d8940811b7 [file] [log] [blame]
Chris Lattnere4f318c2002-09-08 18:08:36 +00001; 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
Chris Lattner1ae91432003-06-17 15:16:35 +00009%Global = external global { int }
10
11implementation
12
Chris Lattnere4f318c2002-09-08 18:08:36 +000013
14; Array test: Test that operations on one local array do not invalidate
15; operations on another array. Important for scientific codes.
16;
Chris Lattner66486452002-10-25 22:29:07 +000017int %different_array_test(long %A, long %B) {
Chris Lattnere4f318c2002-09-08 18:08:36 +000018 %Array1 = alloca int, uint 100
19 %Array2 = alloca int, uint 200
20
Chris Lattner66486452002-10-25 22:29:07 +000021 %pointer = getelementptr int* %Array1, long %A
Chris Lattnere4f318c2002-09-08 18:08:36 +000022 %val = load int* %pointer
23
Chris Lattner66486452002-10-25 22:29:07 +000024 %pointer2 = getelementptr int* %Array2, long %B
Chris Lattnere4f318c2002-09-08 18:08:36 +000025 store int 7, int* %pointer2
26
27 %REMOVE = load int* %pointer ; redundant with above load
28 %retval = sub int %REMOVE, %val
29 ret int %retval
30}
31
32; Constant index test: Constant indexes into the same array should not
33; interfere with each other. Again, important for scientific codes.
34;
35int %constant_array_index_test() {
36 %Array = alloca int, uint 100
Chris Lattner66486452002-10-25 22:29:07 +000037 %P1 = getelementptr int* %Array, long 7
38 %P2 = getelementptr int* %Array, long 6
Chris Lattnere4f318c2002-09-08 18:08:36 +000039
40 %A = load int* %P1
41 store int 1, int* %P2 ; Should not invalidate load
42 %BREMOVE = load int* %P1
43 %Val = sub int %A, %BREMOVE
44 ret int %Val
45}
46
Chris Lattner7e38fbe2003-02-09 19:01:00 +000047; Test that if two pointers are spaced out by a constant getelementptr, that
48; they cannot alias.
49int %gep_distance_test(int* %A) {
50 %REMOVEu = load int* %A
51 %B = getelementptr int* %A, long 2 ; Cannot alias A
52 store int 7, int* %B
53 %REMOVEv = load int* %A
54 %r = sub int %REMOVEu, %REMOVEv
55 ret int %r
56}
57
Chris Lattner7b9b1f92003-02-25 21:43:37 +000058; Test that if two pointers are spaced out by a constant offset, that they
59; cannot alias, even if there is a variable offset between them...
60int %gep_distance_test2({int,int}* %A, long %distance) {
61 %A = getelementptr {int,int}* %A, long 0, ubyte 0
62 %REMOVEu = load int* %A
63 %B = getelementptr {int,int}* %A, long %distance, ubyte 1
64 store int 7, int* %B ; B cannot alias A, it's at least 4 bytes away
65 %REMOVEv = load int* %A
66 %r = sub int %REMOVEu, %REMOVEv
67 ret int %r
68}
Chris Lattner2271fdd2003-02-26 21:39:52 +000069
Chris Lattnercd4d41c2003-02-26 22:01:58 +000070; Test that we can do funny pointer things and that distance calc will still
71; work.
72int %gep_distance_test3(int * %A) {
Chris Lattner2271fdd2003-02-26 21:39:52 +000073 %X = load int* %A
74 %B = cast int* %A to sbyte*
75 %C = getelementptr sbyte* %B, long 4
76 %Y = load sbyte* %C
77 ret int 8
78}
Chris Lattner1ae91432003-06-17 15:16:35 +000079
80; Test that we can disambiguate globals reached through constantexpr geps
81int %constexpr_test() {
82 %X = alloca int
83 %Y = load int* %X
84 store int 5, int* getelementptr ({ int }* %Global, long 0, ubyte 0)
85 %REMOVE = load int* %X
86 %retval = sub int %Y, %REMOVE
87 ret int %retval
88}