1 ; This testcase tests for various features the basicaa test should be able to
2 ; determine, as noted in the comments.
4 ; RUN: opt < %s -basicaa -gvn -instcombine -dce -S | FileCheck %s
5 target 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"
7 @Global = external global { i32 }
9 declare void @external(i32*)
11 ; Array test: Test that operations on one local array do not invalidate
12 ; operations on another array. Important for scientific codes.
14 define i32 @different_array_test(i64 %A, i64 %B) {
15 %Array1 = alloca i32, i32 100
16 %Array2 = alloca i32, i32 200
18 call void @external(i32* %Array1)
19 call void @external(i32* %Array2)
21 %pointer = getelementptr i32, i32* %Array1, i64 %A
22 %val = load i32, i32* %pointer
24 %pointer2 = getelementptr i32, i32* %Array2, i64 %B
25 store i32 7, i32* %pointer2
27 %REMOVE = load i32, i32* %pointer ; redundant with above load
28 %retval = sub i32 %REMOVE, %val
30 ; CHECK: @different_array_test
34 ; Constant index test: Constant indexes into the same array should not
35 ; interfere with each other. Again, important for scientific codes.
37 define i32 @constant_array_index_test() {
38 %Array = alloca i32, i32 100
39 call void @external(i32* %Array)
41 %P1 = getelementptr i32, i32* %Array, i64 7
42 %P2 = getelementptr i32, i32* %Array, i64 6
44 %A = load i32, i32* %P1
45 store i32 1, i32* %P2 ; Should not invalidate load
46 %BREMOVE = load i32, i32* %P1
47 %Val = sub i32 %A, %BREMOVE
49 ; CHECK: @constant_array_index_test
53 ; Test that if two pointers are spaced out by a constant getelementptr, that
55 define i32 @gep_distance_test(i32* %A) {
56 %REMOVEu = load i32, i32* %A
57 %B = getelementptr i32, i32* %A, i64 2 ; Cannot alias A
59 %REMOVEv = load i32, i32* %A
60 %r = sub i32 %REMOVEu, %REMOVEv
62 ; CHECK: @gep_distance_test
66 ; Test that if two pointers are spaced out by a constant offset, that they
67 ; cannot alias, even if there is a variable offset between them...
68 define i32 @gep_distance_test2({i32,i32}* %A, i64 %distance) {
69 %A1 = getelementptr {i32,i32}, {i32,i32}* %A, i64 0, i32 0
70 %REMOVEu = load i32, i32* %A1
71 %B = getelementptr {i32,i32}, {i32,i32}* %A, i64 %distance, i32 1
72 store i32 7, i32* %B ; B cannot alias A, it's at least 4 bytes away
73 %REMOVEv = load i32, i32* %A1
74 %r = sub i32 %REMOVEu, %REMOVEv
76 ; CHECK: @gep_distance_test2
80 ; Test that we can do funny pointer things and that distance calc will still
82 define i32 @gep_distance_test3(i32 * %A) {
83 %X = load i32, i32* %A
84 %B = bitcast i32* %A to i8*
85 %C = getelementptr i8, i8* %B, i64 4
87 %Y = load i32, i32* %A
90 ; CHECK: @gep_distance_test3
94 ; Test that we can disambiguate globals reached through constantexpr geps
95 define i32 @constexpr_test() {
97 call void @external(i32* %X)
99 %Y = load i32, i32* %X
100 store i32 5, i32* getelementptr ({ i32 }, { i32 }* @Global, i64 0, i32 0)
101 %REMOVE = load i32, i32* %X
102 %retval = sub i32 %Y, %REMOVE
104 ; CHECK: @constexpr_test
111 ; These two index expressions are different, this cannot be CSE'd.
112 define i16 @zext_sext_confusion(i16* %row2col, i5 %j) nounwind{
114 %sum5.cast = zext i5 %j to i64 ; <i64> [#uses=1]
115 %P1 = getelementptr i16, i16* %row2col, i64 %sum5.cast
116 %row2col.load.1.2 = load i16, i16* %P1, align 1 ; <i16> [#uses=1]
118 %sum13.cast31 = sext i5 %j to i6 ; <i6> [#uses=1]
119 %sum13.cast = zext i6 %sum13.cast31 to i64 ; <i64> [#uses=1]
120 %P2 = getelementptr i16, i16* %row2col, i64 %sum13.cast
121 %row2col.load.1.6 = load i16, i16* %P2, align 1 ; <i16> [#uses=1]
123 %.ret = sub i16 %row2col.load.1.6, %row2col.load.1.2 ; <i16> [#uses=1]
125 ; CHECK: @zext_sext_confusion
126 ; CHECK: ret i16 %.ret