blob: a9eeb5d3d2fcbde4ba476074eeca8e26689b2323 [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
Tanya Lattnerdcd188d2008-02-14 06:56:27 +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
Tanya Lattnerdcd188d2008-02-14 06:56:27 +00006@Global = external global { i32 }
Chris Lattnere4f318c2002-09-08 18:08:36 +00007
8; Array test: Test that operations on one local array do not invalidate
9; operations on another array. Important for scientific codes.
10;
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000011define i32 @different_array_test(i64 %A, i64 %B) {
12 %Array1 = alloca i32, i32 100
13 %Array2 = alloca i32, i32 200
Chris Lattnere4f318c2002-09-08 18:08:36 +000014
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000015 %pointer = getelementptr i32* %Array1, i64 %A
16 %val = load i32* %pointer
Chris Lattnere4f318c2002-09-08 18:08:36 +000017
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000018 %pointer2 = getelementptr i32* %Array2, i64 %B
19 store i32 7, i32* %pointer2
Chris Lattnere4f318c2002-09-08 18:08:36 +000020
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000021 %REMOVE = load i32* %pointer ; redundant with above load
22 %retval = sub i32 %REMOVE, %val
23 ret i32 %retval
Chris Lattnere4f318c2002-09-08 18:08:36 +000024}
25
26; Constant index test: Constant indexes into the same array should not
27; interfere with each other. Again, important for scientific codes.
28;
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000029define i32 @constant_array_index_test() {
30 %Array = alloca i32, i32 100
31 %P1 = getelementptr i32* %Array, i64 7
32 %P2 = getelementptr i32* %Array, i64 6
Chris Lattnere4f318c2002-09-08 18:08:36 +000033
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000034 %A = load i32* %P1
35 store i32 1, i32* %P2 ; Should not invalidate load
36 %BREMOVE = load i32* %P1
37 %Val = sub i32 %A, %BREMOVE
38 ret i32 %Val
Chris Lattnere4f318c2002-09-08 18:08:36 +000039}
40
Chris Lattner7e38fbe2003-02-09 19:01:00 +000041; Test that if two pointers are spaced out by a constant getelementptr, that
42; they cannot alias.
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000043define i32 @gep_distance_test(i32* %A) {
44 %REMOVEu = load i32* %A
45 %B = getelementptr i32* %A, i64 2 ; Cannot alias A
46 store i32 7, i32* %B
47 %REMOVEv = load i32* %A
48 %r = sub i32 %REMOVEu, %REMOVEv
49 ret i32 %r
Chris Lattner7e38fbe2003-02-09 19:01:00 +000050}
51
Chris Lattner7b9b1f92003-02-25 21:43:37 +000052; Test that if two pointers are spaced out by a constant offset, that they
53; cannot alias, even if there is a variable offset between them...
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000054define i32 @gep_distance_test2({i32,i32}* %A, i64 %distance) {
55 %A1 = getelementptr {i32,i32}* %A, i64 0, i32 0
56 %REMOVEu = load i32* %A1
57 %B = getelementptr {i32,i32}* %A, i64 %distance, i32 1
58 store i32 7, i32* %B ; B cannot alias A, it's at least 4 bytes away
59 %REMOVEv = load i32* %A1
60 %r = sub i32 %REMOVEu, %REMOVEv
61 ret i32 %r
Chris Lattner7b9b1f92003-02-25 21:43:37 +000062}
Chris Lattner2271fdd2003-02-26 21:39:52 +000063
Chris Lattnercd4d41c2003-02-26 22:01:58 +000064; Test that we can do funny pointer things and that distance calc will still
65; work.
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000066define i32 @gep_distance_test3(i32 * %A) {
67 %X = load i32* %A
68 %B = bitcast i32* %A to i8*
69 %C = getelementptr i8* %B, i64 4
70 %Y = load i8* %C
71 ret i32 8
Chris Lattner2271fdd2003-02-26 21:39:52 +000072}
Chris Lattner1ae91432003-06-17 15:16:35 +000073
74; Test that we can disambiguate globals reached through constantexpr geps
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000075define i32 @constexpr_test() {
76 %X = alloca i32
77 %Y = load i32* %X
78 store i32 5, i32* getelementptr ({ i32 }* @Global, i64 0, i32 0)
79 %REMOVE = load i32* %X
80 %retval = sub i32 %Y, %REMOVE
81 ret i32 %retval
Chris Lattner1ae91432003-06-17 15:16:35 +000082}