blob: 385144d173b65efb026964c7a73cac6ee7f3a804 [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
9
10; Array test: Test that operations on one local array do not invalidate
11; operations on another array. Important for scientific codes.
12;
Chris Lattner66486452002-10-25 22:29:07 +000013int %different_array_test(long %A, long %B) {
Chris Lattnere4f318c2002-09-08 18:08:36 +000014 %Array1 = alloca int, uint 100
15 %Array2 = alloca int, uint 200
16
Chris Lattner66486452002-10-25 22:29:07 +000017 %pointer = getelementptr int* %Array1, long %A
Chris Lattnere4f318c2002-09-08 18:08:36 +000018 %val = load int* %pointer
19
Chris Lattner66486452002-10-25 22:29:07 +000020 %pointer2 = getelementptr int* %Array2, long %B
Chris Lattnere4f318c2002-09-08 18:08:36 +000021 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;
31int %constant_array_index_test() {
32 %Array = alloca int, uint 100
Chris Lattner66486452002-10-25 22:29:07 +000033 %P1 = getelementptr int* %Array, long 7
34 %P2 = getelementptr int* %Array, long 6
Chris Lattnere4f318c2002-09-08 18:08:36 +000035
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
Chris Lattner7e38fbe2003-02-09 19:01:00 +000043; Test that if two pointers are spaced out by a constant getelementptr, that
44; they cannot alias.
45int %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
Chris Lattner7b9b1f92003-02-25 21:43:37 +000054; 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...
56int %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}
Chris Lattner2271fdd2003-02-26 21:39:52 +000065
66int %foo(int * %A) {
67 %X = load int* %A
68 %B = cast int* %A to sbyte*
69 %C = getelementptr sbyte* %B, long 4
70 %Y = load sbyte* %C
71 ret int 8
72}