blob: 50dc8864ac9b01427e5de3a397dc381c7fcbf033 [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
Dan Gohmanf2f6ce62009-09-11 18:01:28 +00004; RUN: opt < %s -basicaa -gvn -instcombine -dce -S | not grep REMOVE
Kenneth Uildriksb908f8a2009-11-03 15:29:06 +00005target 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"
Chris Lattnere4f318c2002-09-08 18:08:36 +00006
Tanya Lattnerdcd188d2008-02-14 06:56:27 +00007@Global = external global { i32 }
Chris Lattnere4f318c2002-09-08 18:08:36 +00008
9; Array test: Test that operations on one local array do not invalidate
10; operations on another array. Important for scientific codes.
11;
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000012define i32 @different_array_test(i64 %A, i64 %B) {
13 %Array1 = alloca i32, i32 100
14 %Array2 = alloca i32, i32 200
Chris Lattnere4f318c2002-09-08 18:08:36 +000015
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000016 %pointer = getelementptr i32* %Array1, i64 %A
17 %val = load i32* %pointer
Chris Lattnere4f318c2002-09-08 18:08:36 +000018
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000019 %pointer2 = getelementptr i32* %Array2, i64 %B
20 store i32 7, i32* %pointer2
Chris Lattnere4f318c2002-09-08 18:08:36 +000021
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000022 %REMOVE = load i32* %pointer ; redundant with above load
23 %retval = sub i32 %REMOVE, %val
24 ret i32 %retval
Chris Lattnere4f318c2002-09-08 18:08:36 +000025}
26
27; Constant index test: Constant indexes into the same array should not
28; interfere with each other. Again, important for scientific codes.
29;
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000030define 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
Chris Lattnere4f318c2002-09-08 18:08:36 +000034
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000035 %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
Chris Lattnere4f318c2002-09-08 18:08:36 +000040}
41
Chris Lattner7e38fbe2003-02-09 19:01:00 +000042; Test that if two pointers are spaced out by a constant getelementptr, that
43; they cannot alias.
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000044define 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
Chris Lattner7e38fbe2003-02-09 19:01:00 +000051}
52
Chris Lattner7b9b1f92003-02-25 21:43:37 +000053; 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...
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000055define 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
Chris Lattner7b9b1f92003-02-25 21:43:37 +000063}
Chris Lattner2271fdd2003-02-26 21:39:52 +000064
Chris Lattnercd4d41c2003-02-26 22:01:58 +000065; Test that we can do funny pointer things and that distance calc will still
66; work.
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000067define 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
Chris Lattner2271fdd2003-02-26 21:39:52 +000073}
Chris Lattner1ae91432003-06-17 15:16:35 +000074
75; Test that we can disambiguate globals reached through constantexpr geps
Tanya Lattnerdcd188d2008-02-14 06:56:27 +000076define 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
Chris Lattner1ae91432003-06-17 15:16:35 +000083}