blob: 7fc129dd1e5ed2e2414976761acbc0fb5bec8d58 [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
Misha Brukmane78760e2003-09-16 15:29:54 +00004; RUN: llvm-as < %s | opt -basicaa -load-vn -gcse -instcombine -dce | llvm-dis | not grep REMOVE
Chris Lattnere4f318c2002-09-08 18:08:36 +00005
Chris Lattner1ae91432003-06-17 15:16:35 +00006%Global = external global { int }
7
8implementation
9
Chris Lattnere4f318c2002-09-08 18:08:36 +000010
11; Array test: Test that operations on one local array do not invalidate
12; operations on another array. Important for scientific codes.
13;
Chris Lattner66486452002-10-25 22:29:07 +000014int %different_array_test(long %A, long %B) {
Chris Lattnere4f318c2002-09-08 18:08:36 +000015 %Array1 = alloca int, uint 100
16 %Array2 = alloca int, uint 200
17
Chris Lattner66486452002-10-25 22:29:07 +000018 %pointer = getelementptr int* %Array1, long %A
Chris Lattnere4f318c2002-09-08 18:08:36 +000019 %val = load int* %pointer
20
Chris Lattner66486452002-10-25 22:29:07 +000021 %pointer2 = getelementptr int* %Array2, long %B
Chris Lattnere4f318c2002-09-08 18:08:36 +000022 store int 7, int* %pointer2
23
24 %REMOVE = load int* %pointer ; redundant with above load
25 %retval = sub int %REMOVE, %val
26 ret int %retval
27}
28
29; Constant index test: Constant indexes into the same array should not
30; interfere with each other. Again, important for scientific codes.
31;
32int %constant_array_index_test() {
33 %Array = alloca int, uint 100
Chris Lattner66486452002-10-25 22:29:07 +000034 %P1 = getelementptr int* %Array, long 7
35 %P2 = getelementptr int* %Array, long 6
Chris Lattnere4f318c2002-09-08 18:08:36 +000036
37 %A = load int* %P1
38 store int 1, int* %P2 ; Should not invalidate load
39 %BREMOVE = load int* %P1
40 %Val = sub int %A, %BREMOVE
41 ret int %Val
42}
43
Chris Lattner7e38fbe2003-02-09 19:01:00 +000044; Test that if two pointers are spaced out by a constant getelementptr, that
45; they cannot alias.
46int %gep_distance_test(int* %A) {
47 %REMOVEu = load int* %A
48 %B = getelementptr int* %A, long 2 ; Cannot alias A
49 store int 7, int* %B
50 %REMOVEv = load int* %A
51 %r = sub int %REMOVEu, %REMOVEv
52 ret int %r
53}
54
Chris Lattner7b9b1f92003-02-25 21:43:37 +000055; Test that if two pointers are spaced out by a constant offset, that they
56; cannot alias, even if there is a variable offset between them...
57int %gep_distance_test2({int,int}* %A, long %distance) {
58 %A = getelementptr {int,int}* %A, long 0, ubyte 0
59 %REMOVEu = load int* %A
60 %B = getelementptr {int,int}* %A, long %distance, ubyte 1
61 store int 7, int* %B ; B cannot alias A, it's at least 4 bytes away
62 %REMOVEv = load int* %A
63 %r = sub int %REMOVEu, %REMOVEv
64 ret int %r
65}
Chris Lattner2271fdd2003-02-26 21:39:52 +000066
Chris Lattnercd4d41c2003-02-26 22:01:58 +000067; Test that we can do funny pointer things and that distance calc will still
68; work.
69int %gep_distance_test3(int * %A) {
Chris Lattner2271fdd2003-02-26 21:39:52 +000070 %X = load int* %A
71 %B = cast int* %A to sbyte*
72 %C = getelementptr sbyte* %B, long 4
73 %Y = load sbyte* %C
74 ret int 8
75}
Chris Lattner1ae91432003-06-17 15:16:35 +000076
77; Test that we can disambiguate globals reached through constantexpr geps
78int %constexpr_test() {
79 %X = alloca int
80 %Y = load int* %X
81 store int 5, int* getelementptr ({ int }* %Global, long 0, ubyte 0)
82 %REMOVE = load int* %X
83 %retval = sub int %Y, %REMOVE
84 ret int %retval
85}