xref: /aosp_15_r20/external/llvm/test/Analysis/BasicAA/featuretest.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; This testcase tests for various features the basicaa test should be able to
2*9880d681SAndroid Build Coastguard Worker; determine, as noted in the comments.
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -basicaa -gvn -instcombine -dce -S | FileCheck %s
5*9880d681SAndroid Build Coastguard Workertarget 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"
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Worker@Global = external global { i32 }
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Workerdeclare void @external(i32*)
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; Array test:  Test that operations on one local array do not invalidate
12*9880d681SAndroid Build Coastguard Worker; operations on another array.  Important for scientific codes.
13*9880d681SAndroid Build Coastguard Worker;
14*9880d681SAndroid Build Coastguard Workerdefine i32 @different_array_test(i64 %A, i64 %B) {
15*9880d681SAndroid Build Coastguard Worker	%Array1 = alloca i32, i32 100
16*9880d681SAndroid Build Coastguard Worker	%Array2 = alloca i32, i32 200
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker        call void @external(i32* %Array1)
19*9880d681SAndroid Build Coastguard Worker        call void @external(i32* %Array2)
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker	%pointer = getelementptr i32, i32* %Array1, i64 %A
22*9880d681SAndroid Build Coastguard Worker	%val = load i32, i32* %pointer
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker	%pointer2 = getelementptr i32, i32* %Array2, i64 %B
25*9880d681SAndroid Build Coastguard Worker	store i32 7, i32* %pointer2
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker	%REMOVE = load i32, i32* %pointer ; redundant with above load
28*9880d681SAndroid Build Coastguard Worker	%retval = sub i32 %REMOVE, %val
29*9880d681SAndroid Build Coastguard Worker	ret i32 %retval
30*9880d681SAndroid Build Coastguard Worker; CHECK: @different_array_test
31*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
32*9880d681SAndroid Build Coastguard Worker}
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker; Constant index test: Constant indexes into the same array should not
35*9880d681SAndroid Build Coastguard Worker; interfere with each other.  Again, important for scientific codes.
36*9880d681SAndroid Build Coastguard Worker;
37*9880d681SAndroid Build Coastguard Workerdefine i32 @constant_array_index_test() {
38*9880d681SAndroid Build Coastguard Worker	%Array = alloca i32, i32 100
39*9880d681SAndroid Build Coastguard Worker        call void @external(i32* %Array)
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker	%P1 = getelementptr i32, i32* %Array, i64 7
42*9880d681SAndroid Build Coastguard Worker	%P2 = getelementptr i32, i32* %Array, i64 6
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker	%A = load i32, i32* %P1
45*9880d681SAndroid Build Coastguard Worker	store i32 1, i32* %P2   ; Should not invalidate load
46*9880d681SAndroid Build Coastguard Worker	%BREMOVE = load i32, i32* %P1
47*9880d681SAndroid Build Coastguard Worker	%Val = sub i32 %A, %BREMOVE
48*9880d681SAndroid Build Coastguard Worker	ret i32 %Val
49*9880d681SAndroid Build Coastguard Worker; CHECK: @constant_array_index_test
50*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
51*9880d681SAndroid Build Coastguard Worker}
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker; Test that if two pointers are spaced out by a constant getelementptr, that
54*9880d681SAndroid Build Coastguard Worker; they cannot alias.
55*9880d681SAndroid Build Coastguard Workerdefine i32 @gep_distance_test(i32* %A) {
56*9880d681SAndroid Build Coastguard Worker        %REMOVEu = load i32, i32* %A
57*9880d681SAndroid Build Coastguard Worker        %B = getelementptr i32, i32* %A, i64 2  ; Cannot alias A
58*9880d681SAndroid Build Coastguard Worker        store i32 7, i32* %B
59*9880d681SAndroid Build Coastguard Worker        %REMOVEv = load i32, i32* %A
60*9880d681SAndroid Build Coastguard Worker        %r = sub i32 %REMOVEu, %REMOVEv
61*9880d681SAndroid Build Coastguard Worker        ret i32 %r
62*9880d681SAndroid Build Coastguard Worker; CHECK: @gep_distance_test
63*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
64*9880d681SAndroid Build Coastguard Worker}
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker; Test that if two pointers are spaced out by a constant offset, that they
67*9880d681SAndroid Build Coastguard Worker; cannot alias, even if there is a variable offset between them...
68*9880d681SAndroid Build Coastguard Workerdefine i32 @gep_distance_test2({i32,i32}* %A, i64 %distance) {
69*9880d681SAndroid Build Coastguard Worker	%A1 = getelementptr {i32,i32}, {i32,i32}* %A, i64 0, i32 0
70*9880d681SAndroid Build Coastguard Worker	%REMOVEu = load i32, i32* %A1
71*9880d681SAndroid Build Coastguard Worker	%B = getelementptr {i32,i32}, {i32,i32}* %A, i64 %distance, i32 1
72*9880d681SAndroid Build Coastguard Worker	store i32 7, i32* %B    ; B cannot alias A, it's at least 4 bytes away
73*9880d681SAndroid Build Coastguard Worker	%REMOVEv = load i32, i32* %A1
74*9880d681SAndroid Build Coastguard Worker        %r = sub i32 %REMOVEu, %REMOVEv
75*9880d681SAndroid Build Coastguard Worker        ret i32 %r
76*9880d681SAndroid Build Coastguard Worker; CHECK: @gep_distance_test2
77*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
78*9880d681SAndroid Build Coastguard Worker}
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Worker; Test that we can do funny pointer things and that distance calc will still
81*9880d681SAndroid Build Coastguard Worker; work.
82*9880d681SAndroid Build Coastguard Workerdefine i32 @gep_distance_test3(i32 * %A) {
83*9880d681SAndroid Build Coastguard Worker	%X = load i32, i32* %A
84*9880d681SAndroid Build Coastguard Worker	%B = bitcast i32* %A to i8*
85*9880d681SAndroid Build Coastguard Worker	%C = getelementptr i8, i8* %B, i64 4
86*9880d681SAndroid Build Coastguard Worker        store i8 42, i8* %C
87*9880d681SAndroid Build Coastguard Worker	%Y = load i32, i32* %A
88*9880d681SAndroid Build Coastguard Worker        %R = sub i32 %X, %Y
89*9880d681SAndroid Build Coastguard Worker	ret i32 %R
90*9880d681SAndroid Build Coastguard Worker; CHECK: @gep_distance_test3
91*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
92*9880d681SAndroid Build Coastguard Worker}
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Worker; Test that we can disambiguate globals reached through constantexpr geps
95*9880d681SAndroid Build Coastguard Workerdefine i32 @constexpr_test() {
96*9880d681SAndroid Build Coastguard Worker   %X = alloca i32
97*9880d681SAndroid Build Coastguard Worker   call void @external(i32* %X)
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Worker   %Y = load i32, i32* %X
100*9880d681SAndroid Build Coastguard Worker   store i32 5, i32* getelementptr ({ i32 }, { i32 }* @Global, i64 0, i32 0)
101*9880d681SAndroid Build Coastguard Worker   %REMOVE = load i32, i32* %X
102*9880d681SAndroid Build Coastguard Worker   %retval = sub i32 %Y, %REMOVE
103*9880d681SAndroid Build Coastguard Worker   ret i32 %retval
104*9880d681SAndroid Build Coastguard Worker; CHECK: @constexpr_test
105*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
106*9880d681SAndroid Build Coastguard Worker}
107*9880d681SAndroid Build Coastguard Worker
108*9880d681SAndroid Build Coastguard Worker
109*9880d681SAndroid Build Coastguard Worker
110*9880d681SAndroid Build Coastguard Worker; PR7589
111*9880d681SAndroid Build Coastguard Worker; These two index expressions are different, this cannot be CSE'd.
112*9880d681SAndroid Build Coastguard Workerdefine i16 @zext_sext_confusion(i16* %row2col, i5 %j) nounwind{
113*9880d681SAndroid Build Coastguard Workerentry:
114*9880d681SAndroid Build Coastguard Worker  %sum5.cast = zext i5 %j to i64             ; <i64> [#uses=1]
115*9880d681SAndroid Build Coastguard Worker  %P1 = getelementptr i16, i16* %row2col, i64 %sum5.cast
116*9880d681SAndroid Build Coastguard Worker  %row2col.load.1.2 = load i16, i16* %P1, align 1 ; <i16> [#uses=1]
117*9880d681SAndroid Build Coastguard Worker
118*9880d681SAndroid Build Coastguard Worker  %sum13.cast31 = sext i5 %j to i6          ; <i6> [#uses=1]
119*9880d681SAndroid Build Coastguard Worker  %sum13.cast = zext i6 %sum13.cast31 to i64      ; <i64> [#uses=1]
120*9880d681SAndroid Build Coastguard Worker  %P2 = getelementptr i16, i16* %row2col, i64 %sum13.cast
121*9880d681SAndroid Build Coastguard Worker  %row2col.load.1.6 = load i16, i16* %P2, align 1 ; <i16> [#uses=1]
122*9880d681SAndroid Build Coastguard Worker
123*9880d681SAndroid Build Coastguard Worker  %.ret = sub i16 %row2col.load.1.6, %row2col.load.1.2 ; <i16> [#uses=1]
124*9880d681SAndroid Build Coastguard Worker  ret i16 %.ret
125*9880d681SAndroid Build Coastguard Worker; CHECK: @zext_sext_confusion
126*9880d681SAndroid Build Coastguard Worker; CHECK: ret i16 %.ret
127*9880d681SAndroid Build Coastguard Worker}
128